|LOG(3pub)||C Programmer's Manual||LOG(3pub)|
NAME¶log - simple log file output
#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, ...);
DESCRIPTION¶These routines implement a simple log file facility. There can be several log files open at the same time (up to 256, but limits on the number of concurrently open files may set a lower limit). Each log message is associated with a level of severity, which can be any integer, but the levels log_level_chat, log_level_note, log_level_warn, log_level_error, and log_level_fatal are predefined, and can easily be used by calling the respective print functions (log_chat, etc.); for other log levels, log_printf must be called. Each open log file is associated by a minimum level. Messages below the minimum level are not output to that log file.
The log printing functions attempt to force the messages to be written to the disk (or wherever they're going), using fflush(3). This will hopefully avoid problems due to delayed messages that buffering may cause.
Log files are opened with log_open. An already open file (such as stderr) can be added to the list of open log files with log_add. (Note that the file should be opened in append mode, "a" to fopen(3)). Both of these functions set the minimum level as well. They return a log file handle, which is used to identify the log file to the other functions. The minimum level can later be adjusted with log_set_level. log_close closes all log files.
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.
Logging may temporarily be turned off for all log files at the same time with log_off. It can be turned back on with log_on.
RETURN VALUE¶log_open and log_add return a log file handle. log_close returns -1 if the closing of any log file failed, 0 if all went well.
SEE ALSO¶publib(3), syslog(2)
AUTHOR¶Lars Wirzenius (firstname.lastname@example.org)
|C Programmer's Manual||Publib|