LOG_OPEN(3debug)
π LOG_OPEN β bestie, it's the debug logging manual (3debug) π
okay so this is the LOG_OPEN(3debug) page from the Library calls section and honestly? it's giving "your code is misbehaving and you need receipts" energy. logging is literally the main character of debugging, periodt. let's get into it π¦
β¨ NAME β¨
log_open, log_close, log_reset, log_flush, log_printf, log_vprintf, log_putc, log_puts β the log routines for debugging, aka your little army of message-printers π
π LIBRARIES π
Debug Library (-ldebug) β yeah you gotta link that, no cap.
πΈ SYNOPSIS πΈ
#include <debug/log.h>
int log_open(const char *logfile, int level, int flags);
void log_close(void);
int log_reset(void);
int log_flush(void);
int log_printf(int level, const char *fmt, ...);
int log_vprintf(int level, const char *fmt, va_list ap);
int log_putc(int level, int c);
int log_puts(int level, const char *str);
look at that include line. she's gorgeous. copy her exactly bestie, character for character π
π« DESCRIPTION π«
log_open() is the one that initializes the whole logging system. you hand her logfile β that's the filename of the file where messages get logged β or you can pass NULL if you'd rather messages get printed straight to the console instead. and the values for level and flags? those live in the next section, keep scrolling bestie β¬οΈ
and listen, from version 0.4.1 onwards the debug library also supports logging to syslog instead of a file. the way you do it is: instead of specifying a file, you just specify a string in the form ident.facility β where ident is a string that gets prepended to each syslog message and is usually the program name, and the facility should be the facility messages should be logged to. iconic behavior honestly π
log_close() flushes all the pending messages, and closes the file descriptor of the log file (if any). clean exit, we love to see it π
log_reset() reinitializes the logging system. if any files are currently opened for writing, it will be closed and reopened. this is useful if you need to rotate log files β so if you're doing the logrotate thing, this is your girl β¨
log_flush() flushes all pending messages (if any). that's it. that's the whole job π«Ά
log_printf() and log_vprintf() are replacements for printf(3) and vprintf(3) respectively. same vibe, but they log.
log_putc() will log a single character. this is the equivalent of putchar(3).
log_puts() will log a string. it's the equivalent of puts(3), except that is does not append a trailing newline. (yes, that typo is in the original, and yes, I'm keeping it, because fidelity is the vibe π)
π PARAMETERS π
this section lists the parameters used to set the values of level and flags. buckle up.
π₯ level
this determines the importance of the message. the levels are, in order of decreasing verbosity:
LOG_NOISYβ verbose debug messages (the chattiest girl at the party π)LOG_DEBUGβ debug messagesLOG_VERBOSEβ informational messagesLOG_NORMALβ normal, but significant, conditionsLOG_WARNINGβ warning conditionsLOG_ERRORβ error conditionsLOG_QUIETβ no messages are printed π€
the level argument to log_printf(), log_vprintf(), log_putc(), and log_puts() specify the level at which the message should be printed. and it does not make sense to specify LOG_QUIET to these functions. like, why would you. that's not the move bestie π
the level argument to log_open() sets the verbosity of the program. any messages printed with a level higher (more verbose) than that specified to the log_open() function, will be discarded. so set it wisely or your cute little debug prints will just vanish into the void πΈ
π flags
the flags argument to log_open() is an OR of any of these:
LOG_HAVE_COLORSβ if this flag is specified and messages are printed to the console (i.e. no log file is specified), messages will be printed in different colors, depending on their log level. aesthetic AND functional, we stan π¨LOG_PRINT_FUNCTIONβ if this flag is specified, the function in which the print function was called would be printed in addition to the filename and line number. so you get the full receipt of where this mess came from πLOG_DEBUG_PREFIX_ONLYβ if this flag is specified, only messages with a level higher or equal to (i.e. more or as verbose)LOG_DEBUGwill be printed in color and with file, line number, and (if necessary), the function.LOG_DETECT_DUPLICATESβ if this flag is specified, messages would be buffered and duplicate lines would not be printed. instead, the first message would be printed, followed by a line describing the number of times the message repeated. this is a great way to prevent flooding, but unfortunately it has the side effect of always being one statement behind. yeah. she's a little delayed. it's her thing πLOG_DETECT_FLOODINGβ if specified, the rate at which messages are printed would be limited in order to avoid flooding. this feature have not been implemented yet, and is currently ignored. so like. she's aspirational. she's a dream. she does nothing π«
β RETURN VALUE β
all functions except log_close() return 0 if successful, -1 if some error occurred. check errno to see which error occurred π
π¨ iflog_reset()orlog_open()fails, behaviour is undefined and it should be assumed that no logging is possible. no logging!! the horror!! proceed with caution bestie π
the log_close() function returns no value. she gives nothing and that's valid π
π NOTES π
if this routines are combined with the memory routines, care should be taken to call open and close functions in the right order. the correct order is as follows:
mem_open (NULL);
log_open (NULL,LOG_NORMAL,LOG_HAVE_COLORS | LOG_PRINT_FUNCTION);
atexit (mem_close);
atexit (log_close);
of course, atexit(3) should only be used if the program will not forked. (again, the original says "will not forked" and I am not touching it, we preserve the artifacts here ποΈ)
and now the spicy part: none of the libdebug routines are thread-safe. and the author says, and I quote: "I'm not planning to change this either!" π for more information, please see http://threading.2038bug.com/. he said what he said, periodt.
π SEE ALSO π
mem_open(3), errno(3), atexit(3), printf(3), vprintf(3), putchar(3), puts(3)
logrotate(8), syslog(3), logger(1)
π AUTHOR π
Written by Abraham vd Merwe <abz@blio.com> β thank you king, your logging library ate π
okay and that's the whole page!! this one's from the Unix manual, dated August 2004 β yes she's an elder but she still slays, and honestly that's the most iconic thing about her πβ¨ bye bestie, go log something π
π¦ where this page comes from
- debian bookworm: libdebug0-dev 0.5.3-7 Β· BSD-3-Clause
- debian trixie: libdebug0-dev 0.5.3-8+b1 Β· BSD-3-Clause
- ubuntu jammy: libdebug0-dev 0.5.3-6 Β· BSD-3-Clause
- ubuntu noble: libdebug0-dev 0.5.3-7 Β· BSD-3-Clause
- ubuntu questing: libdebug0-dev 0.5.3-8
- Copyright (c) 2002-2004 Abraham vd Merwe <abz@blio.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms