cscvs to tla changeset 77
[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  * $Id: log.h,v 1.2 2003/06/04 20:57:10 noodles Exp $
9  */
10
11 #ifndef __LOG_H__
12 #define __LOG_H__
13
14 /*
15  *      loglevels - levels of severity for a log entry
16  *
17  *      These provide various different levels of severity for a log entry. In
18  *      acesending order they are:
19  *
20  *      LOGTHING_TRACE
21  *      LOGTHING_DEBUG
22  *      LOGTHING_INFO
23  *      LOGTHING_NOTICE
24  *      LOGTHING_ERROR
25  *      LOGTHING_SERIOUS
26  *      LOGTHING_CRITICAL
27  *
28  *      By default the log threshold is set to LOGTHING_NOTICE, meaning
29  *      anything with a lower priority won't be output.
30  */
31 typedef enum {
32         LOGTHING_TRACE = 0,
33         LOGTHING_DEBUG = 1,
34         LOGTHING_INFO = 2,
35         LOGTHING_NOTICE = 3,
36         LOGTHING_ERROR = 4,
37         LOGTHING_SERIOUS = 5,
38         LOGTHING_CRITICAL = 6
39 } loglevels;
40
41 /*
42  *      initlogthing - initialize the logging module
43  *      @appname: The application name to use in the log.
44  *      @filename: The filename to log to. NULL means stderr.
45  *
46  *      This function sets up the logging module ready to log. The appname is
47  *      written as part of every log entry and the filename is the file we
48  *      should log to. If the appname is NULL then none is written. If the
49  *      filename is NULL all output is sent to stderr.
50  */
51 int initlogthing(const char *appname, const char *filename);
52
53 /*
54  *      cleanuplogthing - clean up the logging module
55  *
56  *      This function cleans up the logging module after use.
57  */
58 void cleanuplogthing(void);
59
60 /*
61  *      setlogthreshold - set the threshold for log output
62  *      @loglevel: The minimum log level we should output
63  *
64  *      Sets the threshold for log output; anything logged with a log level
65  *      lower than this will be silently dropped. Returns the old log threshold
66  *      value.
67  */
68 loglevels setlogthreshold(loglevels loglevel);
69
70 /*
71  *      logthing - output a log entry
72  *      @loglevel: The level of the log.
73  *      @format: A format string, followed by any parameters required.
74  *
75  *      This function outputs a log entry. A leading time/date stamp and a
76  *      trailing newline are automatically added. The loglevel is compared to
77  *      the current log threshold and if equal or above the log entry is
78  *      output. The format parameter is of the same nature as that used in
79  *      printf.
80  */
81 int logthing(loglevels loglevel, const char *format, ...);
82
83 #endif /* __LOG_H__ */