LOG(3pub)
π LOG(3pub) π
okay bestie, gather round, because we're about to make your C program log things like the icon it is β¨ this is a page from the C Programmer's Manual, and it's literally the whole lore on log β simple log file output. no cap, it's giving "small but mighty" π
β¨ NAME β¨
log β simple log file output π«Ά
πΈ SYNOPSIS πΈ
#include <publib.h>
int log_open(const char *filename, int min_level);
int log_add(FILE *f, int min_level);
void log_set_level(int log_handle, int min_level);
void log_set_localtime(int log_handle, int use_localtime);
int log_close(void);
void log_off(void);
void log_on(void);
void log_chat(const char *fmt, ...);
void log_note(const char *fmt, ...);
void log_warn(const char *fmt, ...);
void log_error(const char *fmt, ...);
void log_fatal(const char *fmt, ...);
void log_printf(int level, const char *fmt, ...);
likeβ¦ look at that lineup. main character energy fr fr π
π¦ DESCRIPTION π¦
so these routines are a whole simple log file facility. you can have several log files open at the same time β up to 256, bestie, but heads up, limits on the number of concurrently open files may set a lower limit. so like, vibe check your ulimits, iykyk π
Every single log message gets a level of severity attached to it. that level can be any integer you want. but the levels log_level_chat, log_level_note, log_level_warn, log_level_error, and log_level_fatal are already predefined, and they're super easy to use β you just call the matching print function (log_chat, etc.) π for any other log level, you have to call log_printf. periodt.
Each open log file is associated with a minimum level. messages below that minimum level justβ¦ don't get output to that log file. silenced. not invited to the party π
The log printing functions attempt to force the messages to be written to the disk (or wherever they're going), using fflush(3). and honestly? that's iconic of them, because it will hopefully avoid problems due to delayed messages that buffering may cause. no stale tea here, we want it fresh π₯
Log files get opened with log_open. and if you've got an already open file β like stderr, for example β you can add it to the list of open log files with log_add. β¨
ngl this matters: the file should be opened in append mode,"a"tofopen(3). don't skip that part bestie, it's not a suggestion π
Both of these functions set the minimum level as well. they return a log file handle, which is what you use to identify that log file to all the other functions. the minimum level can be adjusted later with log_set_level. and log_close closes all the log files β every last one, closing time at the function π
By default, times in log files are reported in UTC. but each log file can be set to use local time with log_set_localtime. your timezone, your rules π
Logging may temporarily be turned off for all log files at the same time with log_off. and it can be turned back on with log_on. it's giving "do not disturb" mode, and honestly, valid π
β RETURN VALUE β
log_openandlog_addreturn a log file handle π«Άlog_closereturns-1if the closing of any log file failed, and0if all went well β
π SEE ALSO π
π AUTHOR π
Lars Wirzenius (lars.wirzenius@helsinki.fi) β the legend themselves π
and that's the whole page, bestie!! this lil masterpiece lives in the Publib collection, filed under the C Programmer's Manual, and it's been serving log file realness since forever. go forth and log_fatal responsibly, mwah πππ¦
π¦ where this page comes from
- debian bookworm: publib-dev 0.40-3+b1 Β· BSD-2-Clause
- debian trixie: publib-dev 0.40-4 Β· BSD-2-Clause
- ubuntu jammy: publib-dev 0.40-3build1 Β· BSD-2-Clause
- ubuntu noble: publib-dev 0.40-3build1 Β· BSD-2-Clause
- ubuntu questing: publib-dev 0.40-4
- ubuntu resolute: publib-dev 0.40-4build1 Β· BSD-2-Clause
- ubuntu stonking: publib-dev 0.40-4build1 Β· BSD-2-Clause
- Copyright (c) 1994-2006 Lars Wirzenius. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms