]> granicus.if.org Git - apache/blob - include/http_log.h
Remove unnecessary <pre> tags in <example> blocks.
[apache] / include / http_log.h
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * @file  http_log.h
19  * @brief Apache Logging library
20  *
21  * @defgroup APACHE_CORE_LOG Logging library
22  * @ingroup  APACHE_CORE
23  * @{
24  */
25
26 #ifndef APACHE_HTTP_LOG_H
27 #define APACHE_HTTP_LOG_H
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 #include "apr_thread_proc.h"
34
35 #ifdef HAVE_SYSLOG
36 #include <syslog.h>
37
38 #include "http_config.h"
39
40 #ifndef LOG_PRIMASK
41 #define LOG_PRIMASK 7
42 #endif
43
44 #define APLOG_EMERG     LOG_EMERG       /* system is unusable */
45 #define APLOG_ALERT     LOG_ALERT       /* action must be taken immediately */
46 #define APLOG_CRIT      LOG_CRIT        /* critical conditions */
47 #define APLOG_ERR       LOG_ERR         /* error conditions */
48 #define APLOG_WARNING   LOG_WARNING     /* warning conditions */
49 #define APLOG_NOTICE    LOG_NOTICE      /* normal but significant condition */
50 #define APLOG_INFO      LOG_INFO        /* informational */
51 #define APLOG_DEBUG     LOG_DEBUG       /* debug-level messages */
52 #define APLOG_TRACE1   (LOG_DEBUG + 1)  /* trace-level 1 messages */
53 #define APLOG_TRACE2   (LOG_DEBUG + 2)  /* trace-level 2 messages */
54 #define APLOG_TRACE3   (LOG_DEBUG + 3)  /* trace-level 3 messages */
55 #define APLOG_TRACE4   (LOG_DEBUG + 4)  /* trace-level 4 messages */
56 #define APLOG_TRACE5   (LOG_DEBUG + 5)  /* trace-level 5 messages */
57 #define APLOG_TRACE6   (LOG_DEBUG + 6)  /* trace-level 6 messages */
58 #define APLOG_TRACE7   (LOG_DEBUG + 7)  /* trace-level 7 messages */
59 #define APLOG_TRACE8   (LOG_DEBUG + 8)  /* trace-level 8 messages */
60
61 #define APLOG_LEVELMASK 15     /* mask off the level value */
62
63 #else
64
65 #define APLOG_EMERG      0     /* system is unusable */
66 #define APLOG_ALERT      1     /* action must be taken immediately */
67 #define APLOG_CRIT       2     /* critical conditions */
68 #define APLOG_ERR        3     /* error conditions */
69 #define APLOG_WARNING    4     /* warning conditions */
70 #define APLOG_NOTICE     5     /* normal but significant condition */
71 #define APLOG_INFO       6     /* informational */
72 #define APLOG_DEBUG      7     /* debug-level messages */
73 #define APLOG_TRACE1     8     /* trace-level 1 messages */
74 #define APLOG_TRACE2     9     /* trace-level 2 messages */
75 #define APLOG_TRACE3    10     /* trace-level 3 messages */
76 #define APLOG_TRACE4    11     /* trace-level 4 messages */
77 #define APLOG_TRACE5    12     /* trace-level 5 messages */
78 #define APLOG_TRACE6    13     /* trace-level 6 messages */
79 #define APLOG_TRACE7    14     /* trace-level 7 messages */
80 #define APLOG_TRACE8    15     /* trace-level 8 messages */
81
82 #define APLOG_LEVELMASK 15     /* mask off the level value */
83
84 #endif
85
86 /* APLOG_NOERRNO is ignored and should not be used.  It will be
87  * removed in a future release of Apache.
88  */
89 #define APLOG_NOERRNO           (APLOG_LEVELMASK + 1)
90
91 /** Use APLOG_TOCLIENT on ap_log_rerror() to give content
92  * handlers the option of including the error text in the 
93  * ErrorDocument sent back to the client. Setting APLOG_TOCLIENT
94  * will cause the error text to be saved in the request_rec->notes 
95  * table, keyed to the string "error-notes", if and only if:
96  * - the severity level of the message is APLOG_WARNING or greater
97  * - there are no other "error-notes" set in request_rec->notes
98  * Once error-notes is set, it is up to the content handler to
99  * determine whether this text should be sent back to the client.
100  * Note: Client generated text streams sent back to the client MUST 
101  * be escaped to prevent CSS attacks.
102  */
103 #define APLOG_TOCLIENT          ((APLOG_LEVELMASK + 1) * 2)
104
105 /* normal but significant condition on startup, usually printed to stderr */
106 #define APLOG_STARTUP           ((APLOG_LEVELMASK + 1) * 4) 
107
108 #ifndef DEFAULT_LOGLEVEL
109 #define DEFAULT_LOGLEVEL        APLOG_WARNING
110 #endif
111
112 /**
113  * APLOG_NO_MODULE may be passed as module_index to ap_log_error() and related
114  * functions if the module causing the log message is not known. Normally this
115  * should not be used directly. Use ::APLOG_MARK or ::APLOG_MODULE_INDEX
116  * instead.
117  *
118  * @see APLOG_MARK
119  * @see APLOG_MODULE_INDEX
120  * @see ap_log_error
121  */
122 #define APLOG_NO_MODULE         -1
123
124 /**
125  * Constant to store module_index for the current file.
126  * Objects with static storage duration are set to NULL if not
127  * initialized explicitly. This means that if aplog_module_index
128  * is not initalized using the ::APLOG_USE_MODULE or the
129  * ::AP_DECLARE_MODULE macro, we can safely fall back to
130  * use ::APLOG_NO_MODULE. This variable will usually be optimized away.
131  */
132 static int * const aplog_module_index;
133
134 /**
135  * APLOG_MODULE_INDEX contains the module_index of the current module if
136  * it has been set via the ::APLOG_USE_MODULE or ::AP_DECLARE_MODULE macro.
137  * Otherwise it contains ::APLOG_NO_MODULE (for example in unmodified httpd
138  * 2.2 modules).
139  *
140  * If ::APLOG_MARK is used in ap_log_error() and related functions,
141  * ::APLOG_MODULE_INDEX will be passed as module_index. In cases where
142  * ::APLOG_MARK cannot be used, ::APLOG_MODULE_INDEX should normally be passed
143  * as module_index.
144  *
145  * @see APLOG_MARK
146  * @see ap_log_error
147  */
148 #define APLOG_MODULE_INDEX  \
149     (aplog_module_index ? *aplog_module_index : APLOG_NO_MODULE)
150
151 /**
152  * APLOG_MAX_LOGLEVEL can be defined to remove logging above some
153  * specified level at compile time.
154  *
155  * This requires a C99 compiler.
156  */
157 #ifdef DOXYGEN
158 #define APLOG_MAX_LOGLEVEL
159 #endif
160 #ifndef APLOG_MAX_LOGLEVEL
161 #define APLOG_MODULE_IS_LEVEL(s,module_index,level)              \
162           ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) ||       \
163             (s == NULL) ||                                       \
164             (ap_get_server_module_loglevel(s, module_index)      \
165              >= ((level)&APLOG_LEVELMASK) ) )
166 #define APLOG_C_MODULE_IS_LEVEL(c,module_index,level)            \
167           ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) ||       \
168             (ap_get_conn_module_loglevel(c, module_index)        \
169              >= ((level)&APLOG_LEVELMASK) ) )
170 #define APLOG_CS_MODULE_IS_LEVEL(c,s,module_index,level)            \
171           ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) ||          \
172             (ap_get_conn_server_module_loglevel(c, s, module_index) \
173              >= ((level)&APLOG_LEVELMASK) ) )
174 #define APLOG_R_MODULE_IS_LEVEL(r,module_index,level)            \
175           ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) ||       \
176             (ap_get_request_module_loglevel(r, module_index)     \
177              >= ((level)&APLOG_LEVELMASK) ) )
178 #else
179 #define APLOG_MODULE_IS_LEVEL(s,module_index,level)              \
180         ( (((level)&APLOG_LEVELMASK) <= APLOG_MAX_LOGLEVEL) &&   \
181           ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) ||       \
182             (s == NULL) ||                                       \
183             (ap_get_server_module_loglevel(s, module_index)      \
184              >= ((level)&APLOG_LEVELMASK) ) ) )
185 #define APLOG_CS_MODULE_IS_LEVEL(c,s,module_index,level)            \
186         ( (((level)&APLOG_LEVELMASK) <= APLOG_MAX_LOGLEVEL) &&      \
187           ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) ||          \
188             (ap_get_conn_server_module_loglevel(c, s, module_index) \
189              >= ((level)&APLOG_LEVELMASK) ) ) )
190 #define APLOG_C_MODULE_IS_LEVEL(c,module_index,level)            \
191         ( (((level)&APLOG_LEVELMASK) <= APLOG_MAX_LOGLEVEL) &&   \
192           ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) ||       \
193             (ap_get_conn_module_loglevel(c, module_index)        \
194              >= ((level)&APLOG_LEVELMASK) ) ) )
195 #define APLOG_R_MODULE_IS_LEVEL(r,module_index,level)            \
196         ( (((level)&APLOG_LEVELMASK) <= APLOG_MAX_LOGLEVEL) &&   \
197           ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) ||       \
198             (ap_get_request_module_loglevel(r, module_index)     \
199              >= ((level)&APLOG_LEVELMASK) ) ) )
200 #endif
201
202 #define APLOG_IS_LEVEL(s,level)     \
203     APLOG_MODULE_IS_LEVEL(s,APLOG_MODULE_INDEX,level)
204 #define APLOG_C_IS_LEVEL(c,level)   \
205     APLOG_C_MODULE_IS_LEVEL(c,APLOG_MODULE_INDEX,level)
206 #define APLOG_CS_IS_LEVEL(c,s,level) \
207     APLOG_CS_MODULE_IS_LEVEL(c,s,APLOG_MODULE_INDEX,level)
208 #define APLOG_R_IS_LEVEL(r,level)   \
209     APLOG_R_MODULE_IS_LEVEL(r,APLOG_MODULE_INDEX,level)
210
211
212 #define APLOGinfo(s)                APLOG_IS_LEVEL(s,APLOG_INFO)
213 #define APLOGdebug(s)               APLOG_IS_LEVEL(s,APLOG_DEBUG)
214 #define APLOGtrace1(s)              APLOG_IS_LEVEL(s,APLOG_TRACE1)
215 #define APLOGtrace2(s)              APLOG_IS_LEVEL(s,APLOG_TRACE2)
216 #define APLOGtrace3(s)              APLOG_IS_LEVEL(s,APLOG_TRACE3)
217 #define APLOGtrace4(s)              APLOG_IS_LEVEL(s,APLOG_TRACE4)
218 #define APLOGtrace5(s)              APLOG_IS_LEVEL(s,APLOG_TRACE5)
219 #define APLOGtrace6(s)              APLOG_IS_LEVEL(s,APLOG_TRACE6)
220 #define APLOGtrace7(s)              APLOG_IS_LEVEL(s,APLOG_TRACE7)
221 #define APLOGtrace8(s)              APLOG_IS_LEVEL(s,APLOG_TRACE8)
222
223 #define APLOGrinfo(r)               APLOG_R_IS_LEVEL(r,APLOG_INFO)
224 #define APLOGrdebug(r)              APLOG_R_IS_LEVEL(r,APLOG_DEBUG)
225 #define APLOGrtrace1(r)             APLOG_R_IS_LEVEL(r,APLOG_TRACE1)
226 #define APLOGrtrace2(r)             APLOG_R_IS_LEVEL(r,APLOG_TRACE2)
227 #define APLOGrtrace3(r)             APLOG_R_IS_LEVEL(r,APLOG_TRACE3)
228 #define APLOGrtrace4(r)             APLOG_R_IS_LEVEL(r,APLOG_TRACE4)
229 #define APLOGrtrace5(r)             APLOG_R_IS_LEVEL(r,APLOG_TRACE5)
230 #define APLOGrtrace6(r)             APLOG_R_IS_LEVEL(r,APLOG_TRACE6)
231 #define APLOGrtrace7(r)             APLOG_R_IS_LEVEL(r,APLOG_TRACE7)
232 #define APLOGrtrace8(r)             APLOG_R_IS_LEVEL(r,APLOG_TRACE8)
233
234 #define APLOGcinfo(c)               APLOG_C_IS_LEVEL(c,APLOG_INFO)
235 #define APLOGcdebug(c)              APLOG_C_IS_LEVEL(c,APLOG_DEBUG)
236 #define APLOGctrace1(c)             APLOG_C_IS_LEVEL(c,APLOG_TRACE1)
237 #define APLOGctrace2(c)             APLOG_C_IS_LEVEL(c,APLOG_TRACE2)
238 #define APLOGctrace3(c)             APLOG_C_IS_LEVEL(c,APLOG_TRACE3)
239 #define APLOGctrace4(c)             APLOG_C_IS_LEVEL(c,APLOG_TRACE4)
240 #define APLOGctrace5(c)             APLOG_C_IS_LEVEL(c,APLOG_TRACE5)
241 #define APLOGctrace6(c)             APLOG_C_IS_LEVEL(c,APLOG_TRACE6)
242 #define APLOGctrace7(c)             APLOG_C_IS_LEVEL(c,APLOG_TRACE7)
243 #define APLOGctrace8(c)             APLOG_C_IS_LEVEL(c,APLOG_TRACE8)
244
245 extern int AP_DECLARE_DATA ap_default_loglevel;
246
247 /**
248  * APLOG_MARK is a convenience macro for use as the first three parameters in
249  * ap_log_error() and related functions, i.e. file, line, and module_index.
250  *
251  * The module_index parameter was introduced in version 2.3.6. Before that
252  * version, APLOG_MARK only replaced the file and line parameters.
253  * This means that APLOG_MARK can be used with ap_log_*error in all versions
254  * of Apache httpd.
255  *
256  * @see APLOG_MODULE_INDEX
257  * @see ap_log_error
258  * @see ap_log_cerror
259  * @see ap_log_rerror
260  * @see ap_log_cserror
261  */
262 #define APLOG_MARK     __FILE__,__LINE__,APLOG_MODULE_INDEX
263
264 /**
265  * Set up for logging to stderr.
266  * @param p The pool to allocate out of
267  */
268 AP_DECLARE(void) ap_open_stderr_log(apr_pool_t *p);
269
270 /**
271  * Replace logging to stderr with logging to the given file.
272  * @param p The pool to allocate out of
273  * @param file Name of the file to log stderr output
274  */
275 AP_DECLARE(apr_status_t) ap_replace_stderr_log(apr_pool_t *p, 
276                                                const char *file);
277
278 /**
279  * Open the error log and replace stderr with it.
280  * @param pconf Not used
281  * @param plog  The pool to allocate the logs from
282  * @param ptemp Pool used for temporary allocations
283  * @param s_main The main server
284  * @note ap_open_logs isn't expected to be used by modules, it is
285  * an internal core function 
286  */
287 int ap_open_logs(apr_pool_t *pconf, apr_pool_t *plog, 
288                  apr_pool_t *ptemp, server_rec *s_main);
289
290 /**
291  * Perform special processing for piped loggers in MPM child
292  * processes.
293  * @param p Not used
294  * @param s Not used
295  * @note ap_logs_child_init is not for use by modules; it is an
296  * internal core function
297  */
298 void ap_logs_child_init(apr_pool_t *p, server_rec *s);
299
300 /* 
301  * The primary logging functions, ap_log_error, ap_log_rerror, ap_log_cerror,
302  * and ap_log_perror use a printf style format string to build the log message.  
303  * It is VERY IMPORTANT that you not include any raw data from the network, 
304  * such as the request-URI or request header fields, within the format 
305  * string.  Doing so makes the server vulnerable to a denial-of-service 
306  * attack and other messy behavior.  Instead, use a simple format string 
307  * like "%s", followed by the string containing the untrusted data.
308  */
309
310 /**
311  * ap_log_error() - log messages which are not related to a particular
312  * request or connection.  This uses a printf-like format to log messages
313  * to the error_log.
314  * @param file The file in which this function is called
315  * @param line The line number on which this function is called
316  * @param module_index The module_index of the module generating this message
317  * @param level The level of this error message
318  * @param status The status code from the previous command
319  * @param s The server on which we are logging
320  * @param fmt The format string
321  * @param ... The arguments to use to fill out fmt.
322  * @note ap_log_error is implemented as a macro
323  * @note Use APLOG_MARK to fill out file and line
324  * @note If a request_rec is available, use that with ap_log_rerror()
325  * in preference to calling this function.  Otherwise, if a conn_rec is
326  * available, use that with ap_log_cerror() in preference to calling
327  * this function.
328  * @warning It is VERY IMPORTANT that you not include any raw data from 
329  * the network, such as the request-URI or request header fields, within 
330  * the format string.  Doing so makes the server vulnerable to a 
331  * denial-of-service attack and other messy behavior.  Instead, use a 
332  * simple format string like "%s", followed by the string containing the 
333  * untrusted data.
334  */
335 #ifdef DOXYGEN
336 AP_DECLARE(void) ap_log_error(const char *file, int line, int module_index,
337                               int level, apr_status_t status,
338                               const server_rec *s, const char *fmt, ...);
339 #else
340 #if __STDC_VERSION__ >= 199901L
341 /* need additional step to expand APLOG_MARK first */
342 #define ap_log_error(...) ap_log_error__(__VA_ARGS__)
343 /* need server_rec *sr = ... for the case if s is verbatim NULL */
344 #define ap_log_error__(file, line, mi, level, status, s, ...)           \
345     do { const server_rec *sr = s; if (APLOG_MODULE_IS_LEVEL(sr, mi, level))      \
346              ap_log_error_(file, line, mi, level, status, sr, __VA_ARGS__); \
347     } while(0)
348 #else
349 #define ap_log_error ap_log_error_
350 #endif
351 AP_DECLARE(void) ap_log_error_(const char *file, int line, int module_index,
352                                int level, apr_status_t status,
353                                const server_rec *s, const char *fmt, ...)
354                               __attribute__((format(printf,7,8)));
355 #endif
356
357 /**
358  * ap_log_perror() - log messages which are not related to a particular
359  * request, connection, or virtual server.  This uses a printf-like
360  * format to log messages to the error_log.
361  * @param file The file in which this function is called
362  * @param line The line number on which this function is called
363  * @param module_index ignored dummy value for use by APLOG_MARK
364  * @param level The level of this error message
365  * @param status The status code from the previous command
366  * @param p The pool which we are logging for
367  * @param fmt The format string
368  * @param ... The arguments to use to fill out fmt.
369  * @note ap_log_perror is implemented as a macro
370  * @note Use APLOG_MARK to fill out file, line, and module_index
371  * @warning It is VERY IMPORTANT that you not include any raw data from 
372  * the network, such as the request-URI or request header fields, within 
373  * the format string.  Doing so makes the server vulnerable to a 
374  * denial-of-service attack and other messy behavior.  Instead, use a 
375  * simple format string like "%s", followed by the string containing the 
376  * untrusted data.
377  */
378 #ifdef DOXYGEN
379 AP_DECLARE(void) ap_log_perror(const char *file, int line, int module_index,
380                                int level, apr_status_t status, apr_pool_t *p,
381                                const char *fmt, ...);
382 #else
383 #if __STDC_VERSION__ >= 199901L && defined(APLOG_MAX_LOGLEVEL)
384 /* need additional step to expand APLOG_MARK first */
385 #define ap_log_perror(...) ap_log_perror__(__VA_ARGS__)
386 #define ap_log_perror__(file, line, mi, level, status, p, ...)            \
387     do { if ((level) <= APLOG_MAX_LOGLEVEL )                              \
388              ap_log_perror_(file, line, mi, level, status, p,             \
389                             __VA_ARGS__); } while(0)
390 #else
391 #define ap_log_perror ap_log_perror_
392 #endif
393 AP_DECLARE(void) ap_log_perror_(const char *file, int line, int module_index,
394                                 int level, apr_status_t status, apr_pool_t *p,
395                                 const char *fmt, ...)
396                                __attribute__((format(printf,7,8)));
397 #endif
398
399 /**
400  * ap_log_rerror() - log messages which are related to a particular
401  * request.  This uses a printf-like format to log messages to the
402  * error_log.
403  * @param file The file in which this function is called
404  * @param line The line number on which this function is called
405  * @param module_index The module_index of the module generating this message
406  * @param level The level of this error message
407  * @param status The status code from the previous command
408  * @param r The request which we are logging for
409  * @param fmt The format string
410  * @param ... The arguments to use to fill out fmt.
411  * @note ap_log_rerror is implemented as a macro
412  * @note Use APLOG_MARK to fill out file, line, and module_index
413  * @warning It is VERY IMPORTANT that you not include any raw data from 
414  * the network, such as the request-URI or request header fields, within 
415  * the format string.  Doing so makes the server vulnerable to a 
416  * denial-of-service attack and other messy behavior.  Instead, use a 
417  * simple format string like "%s", followed by the string containing the 
418  * untrusted data.
419  */
420 #ifdef DOXYGEN
421 AP_DECLARE(void) ap_log_rerror(const char *file, int line, int module_index,
422                                int level, apr_status_t status,
423                                const request_rec *r, const char *fmt, ...);
424 #else
425 #if __STDC_VERSION__ >= 199901L
426 /* need additional step to expand APLOG_MARK first */
427 #define ap_log_rerror(...) ap_log_rerror__(__VA_ARGS__)
428 #define ap_log_rerror__(file, line, mi, level, status, r, ...)              \
429     do { if (APLOG_R_MODULE_IS_LEVEL(r, mi, level))                         \
430              ap_log_rerror_(file, line, mi, level, status, r, __VA_ARGS__); \
431     } while(0)
432 #else
433 #define ap_log_rerror ap_log_rerror_
434 #endif
435 AP_DECLARE(void) ap_log_rerror_(const char *file, int line, int module_index,
436                                 int level, apr_status_t status,
437                                 const request_rec *r, const char *fmt, ...)
438                                 __attribute__((format(printf,7,8)));
439 #endif
440
441 /**
442  * ap_log_cerror() - log messages which are related to a particular
443  * connection.  This uses a printf-like format to log messages to the
444  * error_log.
445  * @param file The file in which this function is called
446  * @param line The line number on which this function is called
447  * @param level The level of this error message
448  * @param module_index The module_index of the module generating this message
449  * @param status The status code from the previous command
450  * @param c The connection which we are logging for
451  * @param fmt The format string
452  * @param ... The arguments to use to fill out fmt.
453  * @note ap_log_cerror is implemented as a macro
454  * @note Use APLOG_MARK to fill out file, line, and module_index
455  * @note If a request_rec is available, use that with ap_log_rerror()
456  * in preference to calling this function.
457  * @warning It is VERY IMPORTANT that you not include any raw data from 
458  * the network, such as the request-URI or request header fields, within 
459  * the format string.  Doing so makes the server vulnerable to a 
460  * denial-of-service attack and other messy behavior.  Instead, use a 
461  * simple format string like "%s", followed by the string containing the 
462  * untrusted data.
463  */
464 #ifdef DOXYGEN
465 AP_DECLARE(void) ap_log_cerror(const char *file, int line, int module_index,
466                                int level, apr_status_t status,
467                                const conn_rec *c, const char *fmt, ...);
468 #else
469 #if __STDC_VERSION__ >= 199901L
470 /* need additional step to expand APLOG_MARK first */
471 #define ap_log_cerror(...) ap_log_cerror__(__VA_ARGS__)
472 #define ap_log_cerror__(file, line, mi, level, status, c, ...)              \
473     do { if (APLOG_C_MODULE_IS_LEVEL(c, mi, level))                         \
474              ap_log_cerror_(file, line, mi, level, status, c, __VA_ARGS__); \
475     } while(0)
476 #else
477 #define ap_log_cerror ap_log_cerror_
478 #endif
479 AP_DECLARE(void) ap_log_cerror_(const char *file, int line, int module_index,
480                                 int level, apr_status_t status,
481                                 const conn_rec *c, const char *fmt, ...)
482                                 __attribute__((format(printf,7,8)));
483 #endif
484
485 /**
486  * ap_log_cserror() - log messages which are related to a particular
487  * connection and to a vhost other than c->base_server.  This uses a
488  * printf-like format to log messages to the error_log.
489  * @param file The file in which this function is called
490  * @param line The line number on which this function is called
491  * @param level The level of this error message
492  * @param module_index The module_index of the module generating this message
493  * @param status The status code from the previous command
494  * @param c The connection which we are logging for
495  * @param s The server which we are logging for
496  * @param fmt The format string
497  * @param ... The arguments to use to fill out fmt.
498  * @note ap_log_cserror is implemented as a macro
499  * @note Use APLOG_MARK to fill out file, line, and module_index
500  * @note If a request_rec is available, use that with ap_log_rerror()
501  * in preference to calling this function. This function is mainly useful for
502  * modules like mod_ssl to use before the request_rec is created.
503  * @warning It is VERY IMPORTANT that you not include any raw data from 
504  * the network, such as the request-URI or request header fields, within 
505  * the format string.  Doing so makes the server vulnerable to a 
506  * denial-of-service attack and other messy behavior.  Instead, use a 
507  * simple format string like "%s", followed by the string containing the 
508  * untrusted data.
509  */
510 #ifdef DOXYGEN
511 AP_DECLARE(void) ap_log_cserror(const char *file, int line, int module_index,
512                                 int level, apr_status_t status,
513                                 const conn_rec *c, const server_rec *s,
514                                 const char *fmt, ...);
515 #else
516 #if __STDC_VERSION__ >= 199901L
517 /* need additional step to expand APLOG_MARK first */
518 #define ap_log_cserror(...) ap_log_cserror__(__VA_ARGS__)
519 #define ap_log_cserror__(file, line, mi, level, status, c, s, ...)  \
520     do { if (APLOG_CS_MODULE_IS_LEVEL(c, s, mi, level))             \
521              ap_log_cserror_(file, line, mi, level, status, c, s,   \
522                              __VA_ARGS__);                          \
523     } while(0)
524 #else
525 #define ap_log_cserror ap_log_cserror_
526 #endif
527 AP_DECLARE(void) ap_log_cserror_(const char *file, int line, int module_index,
528                                  int level, apr_status_t status,
529                                  const conn_rec *c, const server_rec *s,
530                                  const char *fmt, ...)
531                              __attribute__((format(printf,8,9)));
532 #endif
533
534 /**
535  * Convert stderr to the error log
536  * @param s The current server
537  */
538 AP_DECLARE(void) ap_error_log2stderr(server_rec *s);
539
540 /**
541  * Log the command line used to start the server.
542  * @param p The pool to use for logging
543  * @param s The server_rec whose process's command line we want to log.
544  * The command line is logged to that server's error log.
545  */
546 AP_DECLARE(void) ap_log_command_line(apr_pool_t *p, server_rec *s);
547
548 /**
549  * Log the current pid of the parent process
550  * @param p The pool to use for logging
551  * @param fname The name of the file to log to
552  */
553 AP_DECLARE(void) ap_log_pid(apr_pool_t *p, const char *fname);
554
555 /**
556  * Retrieve the pid from a pidfile.
557  * @param p The pool to use for logging
558  * @param filename The name of the file containing the pid
559  * @param mypid Pointer to pid_t (valid only if return APR_SUCCESS)
560  */
561 AP_DECLARE(apr_status_t) ap_read_pid(apr_pool_t *p, const char *filename, pid_t *mypid);
562
563 /** @see piped_log */
564 typedef struct piped_log piped_log;
565
566 /**
567  * Open the piped log process
568  * @param p The pool to allocate out of
569  * @param program The program to run in the logging process
570  * @return The piped log structure
571  * @note The log program is invoked as @p APR_PROGRAM_ENV, 
572  *      @see ap_open_piped_log_ex to modify this behavior
573  */
574 AP_DECLARE(piped_log *) ap_open_piped_log(apr_pool_t *p, const char *program);
575
576 /**
577  * Open the piped log process specifying the execution choice for program
578  * @param p The pool to allocate out of
579  * @param program The program to run in the logging process
580  * @param cmdtype How to invoke program, e.g. APR_PROGRAM, APR_SHELLCMD_ENV, etc
581  * @return The piped log structure
582  */
583 AP_DECLARE(piped_log *) ap_open_piped_log_ex(apr_pool_t *p,
584                                              const char *program,
585                                              apr_cmdtype_e cmdtype);
586
587 /**
588  * Close the piped log and kill the logging process
589  * @param pl The piped log structure
590  */
591 AP_DECLARE(void) ap_close_piped_log(piped_log *pl);
592
593 /**
594  * A function to return the read side of the piped log pipe
595  * @param pl The piped log structure
596  * @return The native file descriptor
597  */
598 AP_DECLARE(apr_file_t *) ap_piped_log_read_fd(piped_log *pl);
599
600 /**
601  * A function to return the write side of the piped log pipe
602  * @param pl The piped log structure
603  * @return The native file descriptor
604  */
605 AP_DECLARE(apr_file_t *) ap_piped_log_write_fd(piped_log *pl);
606
607 /**
608  * hook method to log error messages 
609  * @ingroup hooks
610  * @param file The file in which this function is called
611  * @param line The line number on which this function is called
612  * @param module_index The module_index of the module generating this message
613  * @param level The level of this error message
614  * @param status The status code from the previous command
615  * @param s The server which we are logging for
616  * @param r The request which we are logging for
617  * @param pool Memory pool to allocate from
618  * @param errstr message to log 
619  */
620 AP_DECLARE_HOOK(void, error_log, (const char *file, int line,
621                        int module_index, int level,
622                        apr_status_t status, const server_rec *s,
623                        const request_rec *r, apr_pool_t *pool,
624                        const char *errstr))
625
626 /**
627  * hook method to generate unique id for connection or request
628  * @ingroup hooks
629  * @param c the conn_rec of the connections
630  * @param r the request_req (may be NULL)
631  * @param id the place where to store the unique id
632  * @return OK or DECLINE
633  */
634 AP_DECLARE_HOOK(int, generate_log_id,
635                 (const conn_rec *c, const request_rec *r, const char **id))
636
637
638 #ifdef __cplusplus
639 }
640 #endif
641
642 #endif  /* !APACHE_HTTP_LOG_H */
643 /** @} */