Run latex
[egate.git] / include / gw-log.h
1 /*
2  * Copyright (c) 1995, the EUROPAGATE consortium (see below).
3  *
4  * The EUROPAGATE consortium members are:
5  *
6  *    University College Dublin
7  *    Danmarks Teknologiske Videnscenter
8  *    An Chomhairle Leabharlanna
9  *    Consejo Superior de Investigaciones Cientificas
10  *
11  * Permission to use, copy, modify, distribute, and sell this software and
12  * its documentation, in whole or in part, for any purpose, is hereby granted,
13  * provided that:
14  *
15  * 1. This copyright and permission notice appear in all copies of the
16  * software and its documentation. Notices of copyright or attribution
17  * which appear at the beginning of any file must remain unchanged.
18  *
19  * 2. The names of EUROPAGATE or the project partners may not be used to
20  * endorse or promote products derived from this software without specific
21  * prior written permission.
22  *
23  * 3. Users of this software (implementors and gateway operators) agree to
24  * inform the EUROPAGATE consortium of their use of the software. This
25  * information will be used to evaluate the EUROPAGATE project and the
26  * software, and to plan further developments. The consortium may use
27  * the information in later publications.
28  * 
29  * 4. Users of this software agree to make their best efforts, when
30  * documenting their use of the software, to acknowledge the EUROPAGATE
31  * consortium, and the role played by the software in their work.
32  *
33  * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
34  * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
35  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
36  * IN NO EVENT SHALL THE EUROPAGATE CONSORTIUM OR ITS MEMBERS BE LIABLE
37  * FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF
38  * ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
39  * OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND
40  * ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
41  * USE OR PERFORMANCE OF THIS SOFTWARE.
42  *
43  */
44
45 /*
46  * Logging facilities.
47  *
48  * Europagate, 1994-1995.
49  *
50  * $Log: gw-log.h,v $
51  * Revision 1.9  1995/12/01 12:41:00  adam
52  * Bug fix.
53  *
54  * Revision 1.8  1995/12/01  12:24:14  adam
55  * New function: gw_log_mask_str.
56  *
57  * Revision 1.7  1995/05/16  09:39:39  adam
58  * LICENSE.
59  *
60  * Revision 1.6  1995/03/30  07:32:42  adam
61  * New log-level: GW_LOG_NOTICE. New 2709 function: iso2709_mk.
62  *
63  * Revision 1.5  1995/03/28  07:52:35  adam
64  * Bug fix: Bad log masks.
65  *
66  * Revision 1.4  1995/03/27  12:50:40  adam
67  * New level: GW_LOG_ERRNO.
68  *
69  * Revision 1.3  1995/02/23  08:32:11  adam
70  * Changed header.
71  *
72  * Revision 1.1.1.1  1995/02/09  17:27:12  adam
73  * Initial version of email gateway under CVS control.
74  *
75  * Initial:       Dec  7, 94 (Adam Dickmeiss)
76  */
77
78 #ifndef GW_LOG_H
79 #define GW_LOG_H
80 /* The log level is an unsigned integer value with at least 16 bits */
81
82 /* The log levels are defined below */
83 #define GW_LOG_FATAL  0x01
84 #define GW_LOG_WARN   0x02
85 #define GW_LOG_ACCT   0x04
86 #define GW_LOG_STAT   0x08
87 #define GW_LOG_ERRNO  0x10
88 #define GW_LOG_NOTICE 0x20
89
90 /* All debug levels */
91 #define GW_LOG_DEBUG 0xffc0
92 /* Individual debug levels, x sould be in range 0-9 */
93 #define GW_LOG_DEBUGN(x) (0x40<<(x))
94
95 /* All levels on / All levels except debugging */
96 #define GW_LOG_ALL   0xffef
97 #define GW_LOG_DEFAULT 0x2f
98
99 void gw_log_init (const char *app_name);
100 /*
101    Initialises the log-system. Application name is given by 'app_name' - 
102    could be specified as argv[0]. The application name should not
103    contain blanks! 
104
105    All log messages are directed to stderr on return from this function. 
106    Override this behaviour by using the gw_log_file function.
107    
108    The log level is set to GW_LOG_DEFAULT. Override this with the
109    gw_log_level function.
110
111    The session id is set to 0. Use gw_log_session to change this.
112  */
113
114 void gw_log_level (unsigned level);
115 /*
116    Sets the log to 'level' by using the GW_LOG_xxxx masks as described
117    above.
118  */
119
120 void gw_log_session (int session);
121 /*
122    Sets the session id to 'session'.
123  */
124
125 int gw_log_file (unsigned level, const char *fname);
126 /*
127    Specifies that output given by 'level' should be appended to file 'fname'.
128    Thus, all log messages can be written to one file or several files.
129    If 'level' is GW_LOG_ALL all output is appended to the same file.
130    If 'fname' is NULL it means that the output is written to stderr.
131    If 'fname' is "" it means the output is written to stdout.
132
133    This function returns 0 on success; -1 on failure.
134  */ 
135
136 int gw_log (unsigned level, const char *event_type, const char *format, ...);
137 /*
138    Append log message to one or more files. The value of parameter
139    'level' and the value given by the last gw_log_level call are bitwise
140    AND'ed. This value represents the log level for this message. 
141    If this value is non-zero the 'event_type' and 'format' are used to 
142    create the log entries which are appended to the log files specified by 
143    the gw_log_file call(s).
144
145    The 'event_type' should not contain blanks.
146    This function returns 0 on success; -1 on failure.
147  */
148
149 unsigned gw_log_mask_str (const char *str);
150 /*
151    Return the log level corresponding to str.
152     str is a comma separated sequence of tokens. A token is one of:
153      "all", "default", "def", "fatal", "warn", "stat", "notice", "debug",
154      "none" or "debug"<n> where n is 0..9.
155     The level of each token are ORed with initial level being GW_LOG_DEFAULT
156     unless first token is "none" in which case the initial level is 0 (none).
157  */
158
159
160 char *gw_strdup (const char *s);
161 /*
162    Works as strdup(3s), which is not defined by ANSI.
163  */
164
165
166 /* log file format:
167    <appname> <session> <time> <level> <type> <parameter>
168
169    Assuming that a 'token' is separated by one or more blanks we have:
170
171    <appname>   one token
172    <session>   one token
173    <time>      three tokens yymmdd hhmmss sss
174                             | | |  | | |   |_ milliseconds
175                             | | |  | | |_____ seconds
176                             | | |  | |_______ minutes
177                             | | |  |_________ hours
178                             | | |____________ day
179                             | |______________ month
180                             |________________ year
181
182    <level>     one token
183    <type>      one token
184
185    <parameter> zero or more tokens.
186  */
187 #endif