PMEM_LOG_SET_FUNCTION(3)
π 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 (peeppmem_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 toNULL, and if that happens, neitherline_nonorfunction_nameare provided. so like, don't come for them, they're just not there πline_noβ the source file line where the message is coming fromfunction_nameβ the function name where the message is coming frommessageβ 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_AUXthreshold, 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
- fedora 43: libpmem-devel 2.1.0-4.fc43 Β· BSD-3-Clause
- π the page's license: BSD-3-Clause
- Copyright 2024, Intel Corporation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms