Only seed database for Debian install if we're using default config
[onak.git] / log.h
1 /*
2  * log.h - Simple logging framework.
3  *
4  * Jonathan McDowell <noodles@earth.li>
5  *
6  * Copyright 2003 Project Purple
7  */
8
9 #ifndef __LOG_H__
10 #define __LOG_H__
11
12 #include <assert.h>
13
14 #define log_assert(expr) \
15         if (!(expr)) { \
16                 logthing(LOGTHING_CRITICAL, \
17                         "Assertion %s failed in %s, line %d", \
18                         #expr, \
19                         __FILE__, \
20                         __LINE__); \
21         } \
22         assert(expr)
23
24 /*
25  *      loglevels - levels of severity for a log entry
26  *
27  *      These provide various different levels of severity for a log entry. In
28  *      acesending order they are:
29  *
30  *      LOGTHING_TRACE
31  *      LOGTHING_DEBUG
32  *      LOGTHING_INFO
33  *      LOGTHING_NOTICE
34  *      LOGTHING_ERROR
35  *      LOGTHING_SERIOUS
36  *      LOGTHING_CRITICAL
37  *
38  *      By default the log threshold is set to LOGTHING_NOTICE, meaning
39  *      anything with a lower priority won't be output.
40  */
41 typedef enum {
42         LOGTHING_TRACE = 0,
43         LOGTHING_DEBUG = 1,
44         LOGTHING_INFO = 2,
45         LOGTHING_NOTICE = 3,
46         LOGTHING_ERROR = 4,
47         LOGTHING_SERIOUS = 5,
48         LOGTHING_CRITICAL = 6
49 } loglevels;
50
51 /*
52  *      initlogthing - initialize the logging module
53  *      @appname: The application name to use in the log.
54  *      @filename: The filename to log to. NULL means stderr.
55  *
56  *      This function sets up the logging module ready to log. The appname is
57  *      written as part of every log entry and the filename is the file we
58  *      should log to. If the appname is NULL then none is written. If the
59  *      filename is NULL all output is sent to stderr.
60  */
61 int initlogthing(const char *appname, const char *filename);
62
63 /*
64  *      cleanuplogthing - clean up the logging module
65  *
66  *      This function cleans up the logging module after use.
67  */
68 void cleanuplogthing(void);
69
70 /*
71  *      setlogthreshold - set the threshold for log output
72  *      @loglevel: The minimum log level we should output
73  *
74  *      Sets the threshold for log output; anything logged with a log level
75  *      lower than this will be silently dropped. Returns the old log threshold
76  *      value.
77  */
78 loglevels setlogthreshold(loglevels loglevel);
79
80 /*
81  *      logthing - output a log entry
82  *      @loglevel: The level of the log.
83  *      @format: A format string, followed by any parameters required.
84  *
85  *      This function outputs a log entry. A leading time/date stamp and a
86  *      trailing newline are automatically added. The loglevel is compared to
87  *      the current log threshold and if equal or above the log entry is
88  *      output. The format parameter is of the same nature as that used in
89  *      printf.
90  */
91 int logthing(loglevels loglevel, const char *format, ...);
92
93 #endif /* __LOG_H__ */