Skip to main content

Syslog and platform sinks

When the platform already owns log collection — syslog, the systemd journal, the Windows Event Log — writing your own file and reinventing rotation, retention, and shipping is the wrong answer.

syslog_sink

spdlog/sinks/syslog_sink.h wraps POSIX syslog(3). Construction takes an ident string and a facility (LOG_USER, LOG_DAEMON, etc.); spdlog levels map onto syslog priorities:

spdlog levelsyslog priority
trace, debugLOG_DEBUG
infoLOG_INFO
warnLOG_WARNING
errLOG_ERR
criticalLOG_CRIT

systemd journal

systemd_sink writes directly to the systemd journal via sd_journal_send, rather than through syslog. The practical difference: the journal is structured (you can attach extra fields, and journalctl can query them), and you don't format your own timestamp — the journal stamps entries itself, so a timestamp pattern flag in your logger's pattern is redundant here.

Windows event log and debugger

win_eventlog_sink writes to the Windows Event Log, the closest Windows equivalent to syslog — useful for services managed by the Service Control Manager. msvc_sink writes via OutputDebugString instead, which shows up in the Visual Studio output window and any attached debugger; it's a development-time tool, not a production destination.

Android

android_sink maps onto __android_log_write, so output shows up in adb logcat under the tag you provide, using the platform's own level constants under the hood.

Portability

SinkPlatformHeader
syslog_sinkPOSIX (Linux, macOS, BSD)spdlog/sinks/syslog_sink.h
systemd_sinkLinux with systemdspdlog/sinks/systemd_sink.h
win_eventlog_sinkWindowsspdlog/sinks/win_eventlog_sink.h
msvc_sinkWindows (MSVC/debugger)spdlog/sinks/msvc_sink.h
android_sinkAndroidspdlog/sinks/android_sink.h
These headers are platform-specific — including them unconditionally breaks cross-platform builds

#include "spdlog/sinks/syslog_sink.h" on Windows, or win_eventlog_sink.h on Linux, won't compile. Guard these includes and the code that uses them behind the same platform macros you use elsewhere (#ifdef _WIN32, #ifdef __linux__), or isolate them behind a small platform-logging module that the rest of the codebase doesn't need to know about.

See also