PMEM_LOG_SET_FUNCTION(3)

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

πŸ’– pmem_log_set_function(3) πŸ’–

okay bestie, gather round, because we're talking about the PMDK Programmer's Manual and specifically about pmem_log_set_function() β€” the girl whose whole job is deciding who gets to hear the library's little gossip (aka its logging messages). πŸŽ€


✨ NAME ✨

pmem_log_set_function() β€” set the logging function πŸ’…


🌸 SYNOPSIS 🌸

#include <libpmem.h>

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

int pmem_log_set_function(pmem_log_function *log_function);

πŸ¦‹ DESCRIPTION πŸ¦‹

so pmem_log_set_function() is literally the vibe check for your logs β€” it lets you choose the function that's gonna receive all the generated logging messages. no cap. 🫢

your log_function can be one of two things:

  • PMEM_LOG_USE_DEFAULT_FUNCTION, which just uses the default logging function (it's built right into the library, it's giving pre-installed ✨), or
  • a pointer to a user-defined function of your own making, because you're the main character here πŸ‘‘

now, the parameters of a user-defined log function go like this:

  • level β€” the log level of the message (peep pmem_log_set_threshold(3) for the available log levels πŸ‘€)
  • file_name β€” name of the source file where the message is coming from. it could be set to NULL, and if that happens, neither line_no nor function_name are provided. so like, don't come for them, they're just not 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). she's enabled during library initialization, and you can bring her back any time by passing PMEM_LOG_USE_DEFAULT_FUNCTION as the log_function argument. iconic behavior honestly.

here's the thing though β€” the default logging function sinks all the logging messages into syslog(3) unconditionally. every single one. no filter, no shame. πŸ’€

additionally, it sinks a logging message into stderr(3) if:

  • its logging level is not less severe than the value indicated by the PMEM_LOG_THRESHOLD_AUX threshold, and
  • it is not of level PMEM_LOG_LEVEL_HARK.

also note that the PMEM_LOG_THRESHOLD threshold's value applies to the default logging function. please see the notes below, bestie, they matter πŸ’œ


⭐ RETURN VALUE ⭐

pmem_log_set_function() returns 0 on success, or it returns a non-zero value and sets errno on failure. and on failure? the logging function remains unchanged. she stays exactly as she was, no drama. 🧚


πŸ’€ ERRORS πŸ’€

pmem_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 please, we're not doing chaos today πŸ™ˆ

πŸ‘‘ NOTE πŸ‘‘

the logging messages of level less severe than indicated by the PMEM_LOG_THRESHOLD threshold's value won't make it to the logging function, no matter whether the logging function is the default one or a user-provided one. sorry babes, them's the rules. 🌸

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

also, the library will call your user-defined function before returning from pmem_log_set_function(), just to deliver basic info about the library:

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

so yeah, she introduces herself immediately. polite queen. πŸ’…


πŸŽ€ SEE ALSO πŸŽ€


and that's the whole page bestie!! this came to you straight from the PMDK crew, dated 2025-07-24 β€” love that for us, mwah πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from