Bug fix: Bad log masks.
[egate.git] / include / gw-log.h
1 /*
2  * gw-log.h: Logging facilities.
3  *
4  * Europagate, 1994-1995.
5  *
6  * $Log: gw-log.h,v $
7  * Revision 1.5  1995/03/28 07:52:35  adam
8  * Bug fix: Bad log masks.
9  *
10  * Revision 1.4  1995/03/27  12:50:40  adam
11  * New level: GW_LOG_ERRNO.
12  *
13  * Revision 1.3  1995/02/23  08:32:11  adam
14  * Changed header.
15  *
16  * Revision 1.1.1.1  1995/02/09  17:27:12  adam
17  * Initial version of email gateway under CVS control.
18  *
19  * Initial:       Dec  7, 94 (Adam Dickmeiss)
20  */
21
22 #ifndef GW_LOG_H
23 #define GW_LOG_H
24 /* The log level is an unsigned integer value with at least 16 bits */
25
26 /* The log levels are defined below */
27 #define GW_LOG_FATAL 0x01
28 #define GW_LOG_WARN  0x02
29 #define GW_LOG_ACCT  0x04
30 #define GW_LOG_STAT  0x08
31 #define GW_LOG_ERRNO 0x10
32
33 /* All debug levels */
34 #define GW_LOG_DEBUG 0xffe0
35 /* Individual debug levels, x sould be in range 0-10 */
36 #define GW_LOG_DEBUGN(x) (0x20<<(x))
37
38 /* All levels on / All levels except debugging */
39 #define GW_LOG_ALL   0xffef
40 #define GW_LOG_DEFAULT 0x0f
41
42 void gw_log_init (const char *app_name);
43 /*
44    Initialises the log-system. Application name is given by 'app_name' - 
45    could be specified as argv[0]. The application name should not
46    contain blanks! 
47
48    All log messages are directed to stderr on return from this function. 
49    Override this behaviour by using the gw_log_file function.
50    
51    The log level is set to GW_LOG_DEFAULT. Override this with the
52    gw_log_level function.
53
54    The session id is set to 0. Use gw_log_session to change this.
55  */
56
57 void gw_log_level (unsigned level);
58 /*
59    Sets the log to 'level' by using the GW_LOG_xxxx masks as described
60    above.
61  */
62
63 void gw_log_session (int session);
64 /*
65    Sets the session id to 'session'.
66  */
67
68 int gw_log_file (unsigned level, const char *fname);
69 /*
70    Specifies that output given by 'level' should be appended to file 'fname'.
71    Thus, all log messages can be written to one file or several files.
72    If 'level' is GW_LOG_ALL all output is appended to the same file.
73    If 'fname' is NULL it means that the output is written to stderr.
74    If 'fname' is "" it means the output is written to stdout.
75
76    This function returns 0 on success; -1 on failure.
77  */ 
78
79 int gw_log (unsigned level, const char *event_type, const char *format, ...);
80 /*
81    Append log message to one or more files. The value of parameter
82    'level' and the value given by the last gw_log_level call are bitwise
83    AND'ed. This value represents the log level for this message. 
84    If this value is non-zero the 'event_type' and 'format' are used to 
85    create the log entries which are appended to the log files specified by 
86    the gw_log_file call(s).
87
88    The 'event_type' should not contain blanks.
89    This function returns 0 on success; -1 on failure.
90  */
91
92 char *gw_strdup (const char *s);
93 /*
94    Works as strdup(3s), which is not defined by ANSI.
95  */
96
97
98 /* log file format:
99    <appname> <session> <date> <level> <type> <parameter>
100
101    Assuming that a 'token' is separated by one or more blanks we have:
102
103    <appname>   one token
104    <session>   one token
105    <date>      one token yymmddhhmmss
106    <level>     one token
107    <type>      one token
108
109    <parameter> zero or more tokens.
110  */
111 #endif