2 * log.h - Simple logging framework.
4 * Copyright 2003 Jonathan McDowell <noodles@earth.li>
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program. If not, see <https://www.gnu.org/licenses/>.
24 #define log_assert(expr) \
26 logthing(LOGTHING_CRITICAL, \
27 "Assertion %s failed in %s, line %d", \
35 * loglevels - levels of severity for a log entry
37 * These provide various different levels of severity for a log entry. In
38 * acesending order they are:
48 * By default the log threshold is set to LOGTHING_NOTICE, meaning
49 * anything with a lower priority won't be output.
62 * initlogthing - initialize the logging module
63 * @appname: The application name to use in the log.
64 * @filename: The filename to log to. NULL means stderr.
66 * This function sets up the logging module ready to log. The appname is
67 * written as part of every log entry and the filename is the file we
68 * should log to. If the appname is NULL then none is written. If the
69 * filename is NULL all output is sent to stderr.
71 int initlogthing(const char *appname, const char *filename);
74 * cleanuplogthing - clean up the logging module
76 * This function cleans up the logging module after use.
78 void cleanuplogthing(void);
81 * setlogthreshold - set the threshold for log output
82 * @loglevel: The minimum log level we should output
84 * Sets the threshold for log output; anything logged with a log level
85 * lower than this will be silently dropped. Returns the old log threshold
88 loglevels setlogthreshold(loglevels loglevel);
91 * getlogthreshold - get the threshold for log output
93 * Returns the threshold for log output; anything logged with a log level
94 * lower than this will be silently dropped.
96 loglevels getlogthreshold(void);
99 * logthing - output a log entry
100 * @loglevel: The level of the log.
101 * @format: A format string, followed by any parameters required.
103 * This function outputs a log entry. A leading time/date stamp and a
104 * trailing newline are automatically added. The loglevel is compared to
105 * the current log threshold and if equal or above the log entry is
106 * output. The format parameter is of the same nature as that used in
109 int logthing(loglevels loglevel, const char *format, ...);
111 #endif /* __LOG_H__ */