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