rpma_log_set_function(3)

πŸ“¦
version 1.3.0 Β· 3 versions
, in ubuntu noble

πŸ’– rpma_log_set_function β€” bestie edition πŸ’–

okay so this is a page from the RPMA Programmer's Manual, and today's main character is rpma_log_set_function(3). sit down, grab a boba, we're talking about where your logs go 🫢


✨ NAME ✨

rpma_log_set_function β€” set the logging function πŸ’…


🌸 SYNOPSIS 🌸

#include <librpma.h>

typedef void rpma_log_function(
        enum rpma_log_level level,
        const char *file_name,
        const int line_no,
        const char *function_name,
        const char *message_format,
        ...);

int rpma_log_set_function(rpma_log_function *log_function);

like, that's the whole vibe. one function, one pointer, endless possibilities ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

so rpma_log_set_function() is literally your chance to pick which function gets handed every single logging message the library generates. no cap. all of them. it's giving "you are the chosen one" energy πŸ‘‘

and log_function can be one of two things:

  • RPMA_LOG_USE_DEFAULT_FUNCTION β€” which just uses the default logging function (built into the library, she's pre-installed bestie πŸ’–)
  • or a pointer to a user-defined function that you wrote yourself. main character move fr fr

so what do the parameters of a user-defined log function even look like? let me put you on:

  • level β€” the log level of the message πŸ“Š
  • file_name β€” name of the source file where the message coming from. lowkey important: it could be set to NULL, and in that case neither line_no nor function_name are provided. so like, be ready for that πŸ’€
  • line_no β€” the source file line where the message coming from πŸ“
  • function_name β€” the function name where the message coming from 🎯
  • message_format β€” a printf(3)-like format string of the message πŸ–¨οΈ
  • "..." β€” additional arguments of the message format string 🎁

πŸŽ€ THE DEFAULT LOGGING FUNCTION πŸŽ€

the initial value of the logging function is RPMA_LOG_USE_DEFAULT_FUNCTION. and what does that one do, you ask? she writes messages to syslog(3) (the primary destination) and to stderr(3) (the secondary destination). two destinations, one icon 🌈


⭐ RETURN VALUE ⭐

rpma_log_set_function() returns 0 on success or an error code on failure. simple as that bestie ✨


πŸ’€ ERRORS πŸ’€

  • RPMA_E_AGAIN β€” a temporary error occurred, the retry may fix the problem. so like, don't panic, just run it back πŸ”

πŸ‘‘ NOTE πŸ‘‘

the logging messages on the levels above the RPMA_LOG_THRESHOLD level won't trigger the logging function. so if you're wondering why your logs are ghosting you… that's why πŸ™ˆ
also, the user defined function must be thread-safe. this is not a drill, this is not optional, this is the rule πŸ“’

πŸ’œ SEE ALSO πŸ’œ

rpma_log_get_threshold(3), rpma_log_set_threshold(3), librpma(7) and https://pmem.io/rpma/ β€” go read them, they're the friend group 🫢


and that's the tea, bestie πŸ“ this little gem comes to you from RPMA and it's dated 01 April 2024. now go forth and set your logging function like the icon you are πŸ’…βœ¨πŸ‘‘

πŸ“¦ where this page comes from