SD-DAEMON(3)
π SD-DAEMON(3) β sd-daemon π
okay so bestie, welcome to the sd-daemon page from systemd 261.3 β no cap, this is the glow-up guide for new-style daemons and their log-level era β¨
π NAME π
sd-daemon, SD_EMERG, SD_ALERT, SD_CRIT, SD_ERR, SD_WARNING, SD_NOTICE, SD_INFO, SD_DEBUG β literally the APIs for new-style daemons, periodt π
β¨ SYNOPSIS β¨
#include <systemd/sd-daemon.h>
pkg-config --cflags --libs libsystemd
πΈ DESCRIPTION πΈ
so sd-daemon.h is part of libsystemd(3) and it's giving APIs for new-style daemons, as implemented by the systemd(1) service manager. main character energy fr fr π
for the deets on the actual functions, go check out sd_listen_fds(3), sd_notify(3), sd_booted(3), sd_is_fifo(3), sd_watchdog_enabled(3), and sd_pidfd_get_inode_id(3) β they're all linked below too, iykyk π
and on top of those functions, there's also a whole set of logging prefixes defined as macros. slay:
#define SD_EMERG "<0>" /* system is unusable */
#define SD_ALERT "<1>" /* action must be taken immediately */
#define SD_CRIT "<2>" /* critical conditions */
#define SD_ERR "<3>" /* error conditions */
#define SD_WARNING "<4>" /* warning conditions */
#define SD_NOTICE "<5>" /* normal but significant condition */
#define SD_INFO "<6>" /* informational */
#define SD_DEBUG "<7>" /* debug-level messages */
these prefixes are intended to be used with stderr-based logging (or stdout-based logging, bestie, both count) as implemented by systemd π«Ά if a systemd service definition file is configured with StandardError=journal or StandardError=kmsg (and similar with StandardOutput=), you can use these prefixes to encode a log level in the lines you print. it's giving kernel printk()-style logging vibe check β see klogctl(2) for more info π
the log levels are identical to syslog(3)'s log level system, no cap. to use these prefixes, simply prefix every line with one of these strings. and a line that is not prefixed? it gets logged at the default log level SD_INFO. periodt π
π Example 1. Hello World π
a daemon may log with the log level NOTICE by issuing this call:
fprintf(stderr, SD_NOTICE "Hello World!\n");
iconic, honestly π
π¦ NOTES π¦
the functions described here are available as a shared library, which you can compile against and link to with the libsystemd pkg-config(1) file β ez pz β¨
β οΈ okay so this part matters, bestie: the code described here usesgetenv(3), which is declared to be not multi-thread-safe. that means the code calling the functions described here must not callsetenv(3)from a parallel thread. it's recommended to only do calls tosetenv()from an early phase of the program when no other threads have been started. fr fr, don't skip this one π₯
π SEE ALSO π
systemd(1), sd_listen_fds(3), sd_notify(3), sd_booted(3), sd_is_fifo(3), sd_watchdog_enabled(3), sd_pidfd_get_inode_id(3), daemon(7), systemd.service(5), systemd.socket(5), fprintf(3), pkg-config(1) π
and that's the whole vibe, bestie β this page is brought to you by systemd 261.3, dated the SD-DAEMON(3) era π go forth and log responsibly, ily π«Άβ¨
π¦ where this page comes from
- ubuntu stonking: libsystemd-dev 261.3-0ubuntu3 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms