]> granicus.if.org Git - apache/blob - include/http_log.h
add "-l" option to indicate interval is based on localtime not gmt
[apache] / include / http_log.h
1 /* Copyright 1999-2004 The Apache Software Foundation
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #ifndef APACHE_HTTP_LOG_H
17 #define APACHE_HTTP_LOG_H
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 #include "apr_thread_proc.h"
24
25 /**
26  * @package Apache logging library
27  */
28
29 #ifdef HAVE_SYSLOG
30 #include <syslog.h>
31
32 #ifndef LOG_PRIMASK
33 #define LOG_PRIMASK 7
34 #endif
35
36 #define APLOG_EMERG     LOG_EMERG     /* system is unusable */
37 #define APLOG_ALERT     LOG_ALERT     /* action must be taken immediately */
38 #define APLOG_CRIT      LOG_CRIT      /* critical conditions */
39 #define APLOG_ERR       LOG_ERR       /* error conditions */
40 #define APLOG_WARNING   LOG_WARNING   /* warning conditions */
41 #define APLOG_NOTICE    LOG_NOTICE    /* normal but significant condition */
42 #define APLOG_INFO      LOG_INFO      /* informational */
43 #define APLOG_DEBUG     LOG_DEBUG     /* debug-level messages */
44
45 #define APLOG_LEVELMASK LOG_PRIMASK   /* mask off the level value */
46
47 #else
48
49 #define APLOG_EMERG     0       /* system is unusable */
50 #define APLOG_ALERT     1       /* action must be taken immediately */
51 #define APLOG_CRIT      2       /* critical conditions */
52 #define APLOG_ERR       3       /* error conditions */
53 #define APLOG_WARNING   4       /* warning conditions */
54 #define APLOG_NOTICE    5       /* normal but significant condition */
55 #define APLOG_INFO      6       /* informational */
56 #define APLOG_DEBUG     7       /* debug-level messages */
57
58 #define APLOG_LEVELMASK 7       /* mask off the level value */
59
60 #endif
61
62 /* APLOG_NOERRNO is ignored and should not be used.  It will be
63  * removed in a future release of Apache.
64  */
65 #define APLOG_NOERRNO           (APLOG_LEVELMASK + 1)
66
67 /* Use APLOG_TOCLIENT on ap_log_rerror() to give content
68  * handlers the option of including the error text in the 
69  * ErrorDocument sent back to the client. Setting APLOG_TOCLIENT
70  * will cause the error text to be saved in the request_rec->notes 
71  * table, keyed to the string "error-notes", if and only if:
72  * - the severity level of the message is APLOG_WARNING or greater
73  * - there are no other "error-notes" set in request_rec->notes
74  * Once error-notes is set, it is up to the content handler to
75  * determine whether this text should be sent back to the client.
76  * Note: Client generated text streams sent back to the client MUST 
77  * be escaped to prevent CSS attacks.
78  */
79 #define APLOG_TOCLIENT          ((APLOG_LEVELMASK + 1) * 2)
80
81 /* normal but significant condition on startup, usually printed to stderr */
82 #define APLOG_STARTUP           ((APLOG_LEVELMASK + 1) * 4) 
83
84 #ifndef DEFAULT_LOGLEVEL
85 #define DEFAULT_LOGLEVEL        APLOG_WARNING
86 #endif
87
88 extern int AP_DECLARE_DATA ap_default_loglevel;
89
90 #define APLOG_MARK      __FILE__,__LINE__
91
92 /**
93  * Set up for logging to stderr.
94  * @param p The pool to allocate out of
95  */
96 AP_DECLARE(void) ap_open_stderr_log(apr_pool_t *p);
97
98 /**
99  * Replace logging to stderr with logging to the given file.
100  * @param p The pool to allocate out of
101  * @param file Name of the file to log stderr output
102  */
103 AP_DECLARE(apr_status_t) ap_replace_stderr_log(apr_pool_t *p, 
104                                                const char *file);
105
106 /**
107  * Open the error log and replace stderr with it.
108  * @param pconf Not used
109  * @param plog  The pool to allocate the logs from
110  * @param ptemp Pool used for temporary allocations
111  * @param s_main The main server
112  * @tip ap_open_logs isn't expected to be used by modules, it is
113  * an internal core function 
114  */
115 int ap_open_logs(apr_pool_t *pconf, apr_pool_t *plog, 
116                  apr_pool_t *ptemp, server_rec *s_main);
117
118 /* 
119  * The three primary logging functions, ap_log_error, ap_log_rerror, and 
120  * ap_log_perror use a printf style format string to build the log message.  
121  * It is VERY IMPORTANT that you not include any raw data from the network, 
122  * such as the request-URI or request header fields, within the format 
123  * string.  Doing so makes the server vulnerable to a denial-of-service 
124  * attack and other messy behavior.  Instead, use a simple format string 
125  * like "%s", followed by the string containing the untrusted data.
126  */
127
128 /**
129  * One of the primary logging routines in Apache.  This uses a printf-like
130  * format to log messages to the error_log.
131  * @param file The file in which this function is called
132  * @param line The line number on which this function is called
133  * @param level The level of this error message
134  * @param status The status code from the previous command
135  * @param s The server on which we are logging
136  * @param fmt The format string
137  * @param ... The arguments to use to fill out fmt.
138  * @tip Use APLOG_MARK to fill out file and line
139  * @warning It is VERY IMPORTANT that you not include any raw data from 
140  * the network, such as the request-URI or request header fields, within 
141  * the format string.  Doing so makes the server vulnerable to a 
142  * denial-of-service attack and other messy behavior.  Instead, use a 
143  * simple format string like "%s", followed by the string containing the 
144  * untrusted data.
145  * @deffunc void ap_log_error(const char *file, int line, int level, apr_status_t status, const server_rec *s, const char *fmt, ...) 
146  */
147 AP_DECLARE(void) ap_log_error(const char *file, int line, int level, 
148                              apr_status_t status, const server_rec *s, 
149                              const char *fmt, ...)
150                             __attribute__((format(printf,6,7)));
151
152 /**
153  * The second of the primary logging routines in Apache.  This uses 
154  * a printf-like format to log messages to the error_log.
155  * @param file The file in which this function is called
156  * @param line The line number on which this function is called
157  * @param level The level of this error message
158  * @param status The status code from the previous command
159  * @param p The pool which we are logging for
160  * @param fmt The format string
161  * @param ... The arguments to use to fill out fmt.
162  * @tip Use APLOG_MARK to fill out file and line
163  * @warning It is VERY IMPORTANT that you not include any raw data from 
164  * the network, such as the request-URI or request header fields, within 
165  * the format string.  Doing so makes the server vulnerable to a 
166  * denial-of-service attack and other messy behavior.  Instead, use a 
167  * simple format string like "%s", followed by the string containing the 
168  * untrusted data.
169  * @deffunc void ap_log_perror(const char *file, int line, int level, apr_status_t status, apr_pool_t *p, const char *fmt, ...) 
170  */
171 AP_DECLARE(void) ap_log_perror(const char *file, int line, int level, 
172                              apr_status_t status, apr_pool_t *p, 
173                              const char *fmt, ...)
174                             __attribute__((format(printf,6,7)));
175
176 /**
177  * The last of the primary logging routines in Apache.  This uses 
178  * a printf-like format to log messages to the error_log.
179  * @param file The file in which this function is called
180  * @param line The line number on which this function is called
181  * @param level The level of this error message
182  * @param status The status code from the previous command
183  * @param s The request which we are logging for
184  * @param fmt The format string
185  * @param ... The arguments to use to fill out fmt.
186  * @tip Use APLOG_MARK to fill out file and line
187  * @warning It is VERY IMPORTANT that you not include any raw data from 
188  * the network, such as the request-URI or request header fields, within 
189  * the format string.  Doing so makes the server vulnerable to a 
190  * denial-of-service attack and other messy behavior.  Instead, use a 
191  * simple format string like "%s", followed by the string containing the 
192  * untrusted data.
193  * @deffunc void ap_log_rerror(const char *file, int line, int level, apr_status_t status, request_rec *r, const char *fmt, ...) 
194  */
195 AP_DECLARE(void) ap_log_rerror(const char *file, int line, int level, 
196                                apr_status_t status, const request_rec *r, 
197                                const char *fmt, ...)
198                             __attribute__((format(printf,6,7)));
199
200 /**
201  * Convert stderr to the error log
202  * @param s The current server
203  * @deffunc void ap_error_log2stderr(server_rec *s)
204  */
205 AP_DECLARE(void) ap_error_log2stderr(server_rec *s);
206
207 /**
208  * Log the current pid of the parent process
209  * @param p The pool to use for logging
210  * @param fname The name of the file to log to
211  */
212 AP_DECLARE(void) ap_log_pid(apr_pool_t *p, const char *fname);
213
214 /**
215  * Retrieve the pid from a pidfile.
216  * @param p The pool to use for logging
217  * @param filename The name of the file containing the pid
218  * @param mypid Pointer to pid_t (valid only if return APR_SUCCESS)
219  */
220 AP_DECLARE(apr_status_t) ap_read_pid(apr_pool_t *p, const char *filename, pid_t *mypid);
221
222 typedef struct piped_log piped_log;
223
224 /**
225  * The piped logging structure.  Piped logs are used to move functionality
226  * out of the main server.  For example, log rotation is done with piped logs.
227  */
228 struct piped_log {
229     /** The pool to use for the piped log */
230     apr_pool_t *p;
231     /** The pipe between the server and the logging process */
232     apr_file_t *fds[2];
233     /* XXX - an #ifdef that needs to be eliminated from public view. Shouldn't
234      * be hard */
235 #ifdef AP_HAVE_RELIABLE_PIPED_LOGS
236     /** The name of the program the logging process is running */
237     char *program;
238     /** The pid of the logging process */
239     apr_proc_t *pid;
240 #endif
241 };
242
243 /**
244  * Open the piped log process
245  * @param p The pool to allocate out of
246  * @param program The program to run in the logging process
247  * @return The piped log structure
248  * @deffunc piped_log *ap_open_piped_log(apr_pool_t *p, const char *program)
249  */
250 AP_DECLARE(piped_log *) ap_open_piped_log(apr_pool_t *p, const char *program);
251
252 /**
253  * Close the piped log and kill the logging process
254  * @param pl The piped log structure
255  * @deffunc void ap_close_piped_log(piped_log *pl)
256  */
257 AP_DECLARE(void) ap_close_piped_log(piped_log *pl);
258
259 /**
260  * A macro to access the read side of the piped log pipe
261  * @param pl The piped log structure
262  * @return The native file descriptor
263  * @deffunc ap_piped_log_read_fd(pl)
264  */
265 #define ap_piped_log_read_fd(pl)        ((pl)->fds[0])
266
267 /**
268  * A macro to access the write side of the piped log pipe
269  * @param pl The piped log structure
270  * @return The native file descriptor
271  * @deffunc ap_piped_log_read_fd(pl)
272  */
273 #define ap_piped_log_write_fd(pl)       ((pl)->fds[1])
274
275 AP_DECLARE_HOOK(void, error_log, (const char *file, int line, int level,
276                        apr_status_t status, const server_rec *s,
277                        const request_rec *r, apr_pool_t *pool,
278                        const char *errstr))
279
280 #ifdef __cplusplus
281 }
282 #endif
283
284 #endif  /* !APACHE_HTTP_LOG_H */