PMEMOBJ_LOG_USE_DEFAULT_FUNCTION(3)

πŸ“¦
version 2.1.0 Β· 2 versions
, in fedora 43

πŸ’– pmemobj_log_set_function() β€” set the logging function πŸ’–

okay bestie, welcome to the PMDK Programmer's Manual ✨ this one's all about picking who gets to hear the library's gossip (aka the logging messages). no cap, it's a short one, so let's go 🫢


✨ SYNOPSIS ✨

#include <libpmemobj.h>

typedef void pmemobj_log_function(
    enum pmemobj_log_level level,
    const char *file_name,
    unsigned line_no,
    const char *function_name,
    const char *message);

int pmemobj_log_set_function(pmemobj_log_function *log_function);

🌸 DESCRIPTION 🌸

pmemobj_log_set_function() is literally your way of choosing which function receives every single logging message the library generates. iconic, right?

So log_function can be one of two things:

  • PMEMOBJ_LOG_USE_DEFAULT_FUNCTION β€” the default logging function, built right into the library, no effort required πŸ’…
  • a pointer to a user-defined function β€” for when you want main character energy and handle the logs yourself πŸ‘‘

The parameters your user-defined log function gets handed are as follows, bestie:

  • level β€” the log level of the message (peep pmemobj_log_set_threshold(3) for the available log levels) πŸ‘€
  • file_name β€” the name of the source file where the message is coming from. it could be set to NULL, and in that case neither line_no nor function_name are provided. so don't come for them, they just aren't there πŸ™ˆ
  • line_no β€” the source file line where the message is coming from
  • function_name β€” the function name where the message is coming from
  • message β€” the message string, the actual tea β˜•

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

The library ships with a default logging function that writes messages to syslog(3) and to stderr(3). it's enabled during library initialization (she's already awake when you get there πŸ’…) and you can bring her back anytime using PMEMOBJ_LOG_USE_DEFAULT_FUNCTION as the log_function argument.

Here's the deets on her behaviour, fr fr:

  • she sinks all the logging messages into syslog(3) unconditionally β€” no questions asked
  • additionally, she sinks a logging message into stderr(3) if its logging level is not less severe than the value indicated by the PMEMOBJ_LOG_THRESHOLD_AUX threshold, and it is not of level PMEMOBJ_LOG_LEVEL_HARK
⚠️ heads up: the PMEMOBJ_LOG_THRESHOLD threshold's value applies to the default logging function. pls read the notes below, they matter πŸ‘‡

⭐ RETURN VALUE ⭐

pmemobj_log_set_function() returns 0 on success ✨ or returns a non-zero value and sets errno on failure 😭. and on failure, the logging function remains unchanged β€” no half-done glow-ups here.


πŸ’€ ERRORS πŸ’€

pmemobj_log_set_function() can set the following errno values on fail:

  • EAGAIN β€” multiple threads attempted to change the logging function concurrently. a retry may fix the problem. this error is not expected when the function is called from just one thread at a time. so like, one at a time, bestie, we are not doing chaos today 🫢

πŸ¦‹ NOTE πŸ¦‹

The logging messages of level less severe than indicated by the PMEMOBJ_LOG_THRESHOLD threshold's value won't make it to the logging function β€” and no, it does not matter whether the logging function is the default logging function or user-provided. them's the rules πŸ’…

The user-defined function must be thread-safe. periodt πŸ”₯

The library will call your user-defined function before returning from pmemobj_log_set_function() to deliver basic information about the library:

  • β€œsrc version: 2.y.z”
  • β€œcompiled with support for shutdown state”
  • β€œcompiled with libndctl 63+”

like, she's introducing herself before you two even properly start talking. obsessed 🌸


🌈 SEE ALSO 🌈

pmemobj_log_get_threshold(3), pmemobj_log_set_threshold(3).


and that's the whole page, bestie!! πŸŽ‰ this was served fresh from the PMDK programmer's manual, dated 2025-07-24 β€” so go forth, set your logging function, and slay πŸ’–βœ¨πŸŽ€πŸ¦‹πŸ‘‘

πŸ“¦ where this page comes from