NNG_LOG_SET_LOGGER(3)

πŸ“¦
version 1.12.0 Β· 4 versions
, in ubuntu stonking

πŸ’– NNG_LOG_SET_LOGGER(3) πŸ’–

okay bestie, welcome to the NNG Reference Manual β€” this is the page for nng_log_set_logger, and it's literally the one that decides who gets to hear the tea when your library wants to say something. let's get into it 🫢


✨ NAME ✨

nng_log_set_logger β€” set logging handler πŸŽ€


🌸 SYNOPSIS 🌸

#include <nng/nng.h>

typedef void (*nng_logger)(nng_log_level level, nng_log_facility facility,
    const char *msgid, const char *msg);

void nng_null_logger(nng_log_level, nng_log_facility, const char *, const char *);
void nng_stderr_logger(nng_log_level, nng_log_facility, const char *, const char *);
void nng_system_logger(nng_log_level, nng_log_facility, const char *, const char *);

void nng_log_set_logger(nng_logger logger);

no cap, that typedef is the whole personality of this function. everything's a void *… okay not literally, but the vibe is you pass a function pointer, I'll call it. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so nng_log_set_logger does exactly one thing and it does it slay: it sets the base logging function to logger. that logger can totally be a function you wrote yourself, if you wanna process log messages your own way. main character behavior, honestly. πŸ‘‘

But β€” and this is the important part β€” only one logger may be registered at a time. one. singular. there is no polycule of loggers here. πŸ’€

🚨 bestie listen up: if your logger is gonna hold onto msgid or msg past the moment it returns, it must make copies of them first. those strings may not be valid once your logger function returns. like, they could be gone-gone. copy them or cry about it. 😭

🌈 The built-in loggers 🌈

okay so NNG ships with three ready-made logger implementations so you don't have to write your own from scratch. obsessed with the convenience, honestly.

  • nng_null_logger β€” the "I'm on Do Not Disturb" logger. it's an implementation of nng_logger that simply discards the content. nothing gets logged, nothing gets said, the vibes stay immaculate and silent. this is the default logger, which means logging is disabled by default. you literally have to opt in to hearing anything. iconic hermit energy. πŸ™ˆ
  • nng_stderr_logger β€” the chatty one. it's an implementation that logs messages to the standard error stream. and the way it will attempt to colorize messages by the severity if standard error is a terminal device?? actual aesthetic. 🌈✨

but if you're not in the mood for the rainbow, you can suppress it by setting either the NO_COLOR or the NNG_LOG_NO_COLOR environment variables. either one works, pick your fighter. πŸŽ€

  • nng_system_logger β€” the one that plays nicely with your OS. it attempts to use an appropriate system facility to log messages. on POSIX systems, that means it uses syslog to process the messages. for other systems, nng_stderr_log may be used as a fallback. so like, if it can't find the system's vibe, it'll just use the stderr vibe. versatile king. πŸ‘‘

πŸ‘€ SEE ALSO πŸ‘€

the friend group, the squad, the trio:


πŸ’œ that's the whole page, bestie πŸ’œ

and that's a wrap fr fr. this page came from the NNG Reference Manual and it's dated 2026-06-30, so you know it's fresh. periodt. πŸ’…βœ¨πŸŒΈπŸ¦‹πŸŽ€πŸ«Ά

NNG_LOG_SET_LOGGER(3) β€” go set that logger, you got this. πŸ”₯πŸ‘‘

πŸ“¦ where this page comes from