PMEMOBJ_LOG_USE_DEFAULT_FUNCTION(3)
π 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 (peeppmemobj_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 toNULL, and in that case neitherline_nonorfunction_nameare provided. so don't come for them, they just aren't 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). 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 thePMEMOBJ_LOG_THRESHOLD_AUXthreshold, and it is not of levelPMEMOBJ_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
- fedora 43: libpmemobj-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