]> the.earth.li Git - onak.git/blob - log.h
Fix handling of other signature requirement
[onak.git] / log.h
1 /*
2  * log.h - Simple logging framework.
3  *
4  * Copyright 2003 Jonathan McDowell <noodles@earth.li>
5  *
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.
9  *
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
13  * more details.
14  *
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/>.
17  */
18
19 #ifndef __LOG_H__
20 #define __LOG_H__
21
22 #include <assert.h>
23
24 #define log_assert(expr) \
25         if (!(expr)) { \
26                 logthing(LOGTHING_CRITICAL, \
27                         "Assertion %s failed in %s, line %d", \
28                         #expr, \
29                         __FILE__, \
30                         __LINE__); \
31         } \
32         assert(expr)
33
34 /*
35  *      loglevels - levels of severity for a log entry
36  *
37  *      These provide various different levels of severity for a log entry. In
38  *      acesending order they are:
39  *
40  *      LOGTHING_TRACE
41  *      LOGTHING_DEBUG
42  *      LOGTHING_INFO
43  *      LOGTHING_NOTICE
44  *      LOGTHING_ERROR
45  *      LOGTHING_SERIOUS
46  *      LOGTHING_CRITICAL
47  *
48  *      By default the log threshold is set to LOGTHING_NOTICE, meaning
49  *      anything with a lower priority won't be output.
50  */
51 typedef enum {
52         LOGTHING_TRACE = 0,
53         LOGTHING_DEBUG = 1,
54         LOGTHING_INFO = 2,
55         LOGTHING_NOTICE = 3,
56         LOGTHING_ERROR = 4,
57         LOGTHING_SERIOUS = 5,
58         LOGTHING_CRITICAL = 6
59 } loglevels;
60
61 /*
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.
65  *
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.
70  */
71 int initlogthing(const char *appname, const char *filename);
72
73 /*
74  *      cleanuplogthing - clean up the logging module
75  *
76  *      This function cleans up the logging module after use.
77  */
78 void cleanuplogthing(void);
79
80 /*
81  *      setlogthreshold - set the threshold for log output
82  *      @loglevel: The minimum log level we should output
83  *
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
86  *      value.
87  */
88 loglevels setlogthreshold(loglevels loglevel);
89
90 /*
91  *      getlogthreshold - get the threshold for log output
92  *
93  *      Returns the threshold for log output; anything logged with a log level
94  *      lower than this will be silently dropped.
95  */
96 loglevels getlogthreshold(void);
97
98 /*
99  *      logthing - output a log entry
100  *      @loglevel: The level of the log.
101  *      @format: A format string, followed by any parameters required.
102  *
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
107  *      printf.
108  */
109 int logthing(loglevels loglevel, const char *format, ...);
110
111 #endif /* __LOG_H__ */