]> granicus.if.org Git - apache/blob - include/http_log.h
keep -DAP_HOOK_PROBES_ENABLED (--enable-hook-probes) and
[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 #ifdef __cplusplus
125 /**
126  * C++ modules must invoke ::APLOG_USE_MODULE or ::AP_DECLARE_MODULE in
127  * every file which uses ap_log_* before the first use of ::APLOG_MARK
128  * or ::APLOG_MODULE_INDEX.
129  * (C modules *should* do that as well, to enable module-specific log
130  * levels. C modules need not obey the ordering, though).
131  */
132 #else /* __cplusplus */
133 /**
134  * Constant to store module_index for the current file.
135  * Objects with static storage duration are set to NULL if not
136  * initialized explicitly. This means that if aplog_module_index
137  * is not initalized using the ::APLOG_USE_MODULE or the
138  * ::AP_DECLARE_MODULE macro, we can safely fall back to
139  * use ::APLOG_NO_MODULE. This variable will usually be optimized away.
140  */
141 static int * const aplog_module_index;
142 #endif /* __cplusplus */
143
144 /**
145  * APLOG_MODULE_INDEX contains the module_index of the current module if
146  * it has been set via the ::APLOG_USE_MODULE or ::AP_DECLARE_MODULE macro.
147  * Otherwise it contains ::APLOG_NO_MODULE (for example in unmodified httpd
148  * 2.2 modules).
149  *
150  * If ::APLOG_MARK is used in ap_log_error() and related functions,
151  * ::APLOG_MODULE_INDEX will be passed as module_index. In cases where
152  * ::APLOG_MARK cannot be used, ::APLOG_MODULE_INDEX should normally be passed
153  * as module_index.
154  *
155  * @see APLOG_MARK
156  * @see ap_log_error
157  */
158 #ifdef __cplusplus
159 #define APLOG_MODULE_INDEX (*aplog_module_index)
160 #else /* __cplusplus */
161 #define APLOG_MODULE_INDEX  \
162     (aplog_module_index ? *aplog_module_index : APLOG_NO_MODULE)
163 #endif /* __cplusplus */
164
165 /**
166  * APLOG_MAX_LOGLEVEL can be defined to remove logging above some
167  * specified level at compile time.
168  *
169  * This requires a C99 compiler.
170  */
171 #ifdef DOXYGEN
172 #define APLOG_MAX_LOGLEVEL
173 #endif
174 #ifndef APLOG_MAX_LOGLEVEL
175 #define APLOG_MODULE_IS_LEVEL(s,module_index,level)              \
176           ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) ||       \
177             (s == NULL) ||                                       \
178             (ap_get_server_module_loglevel(s, module_index)      \
179              >= ((level)&APLOG_LEVELMASK) ) )
180 #define APLOG_C_MODULE_IS_LEVEL(c,module_index,level)            \
181           ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) ||       \
182             (ap_get_conn_module_loglevel(c, module_index)        \
183              >= ((level)&APLOG_LEVELMASK) ) )
184 #define APLOG_CS_MODULE_IS_LEVEL(c,s,module_index,level)            \
185           ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) ||          \
186             (ap_get_conn_server_module_loglevel(c, s, module_index) \
187              >= ((level)&APLOG_LEVELMASK) ) )
188 #define APLOG_R_MODULE_IS_LEVEL(r,module_index,level)            \
189           ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) ||       \
190             (ap_get_request_module_loglevel(r, module_index)     \
191              >= ((level)&APLOG_LEVELMASK) ) )
192 #else
193 #define APLOG_MODULE_IS_LEVEL(s,module_index,level)              \
194         ( (((level)&APLOG_LEVELMASK) <= APLOG_MAX_LOGLEVEL) &&   \
195           ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) ||       \
196             (s == NULL) ||                                       \
197             (ap_get_server_module_loglevel(s, module_index)      \
198              >= ((level)&APLOG_LEVELMASK) ) ) )
199 #define APLOG_CS_MODULE_IS_LEVEL(c,s,module_index,level)            \
200         ( (((level)&APLOG_LEVELMASK) <= APLOG_MAX_LOGLEVEL) &&      \
201           ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) ||          \
202             (ap_get_conn_server_module_loglevel(c, s, module_index) \
203              >= ((level)&APLOG_LEVELMASK) ) ) )
204 #define APLOG_C_MODULE_IS_LEVEL(c,module_index,level)            \
205         ( (((level)&APLOG_LEVELMASK) <= APLOG_MAX_LOGLEVEL) &&   \
206           ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) ||       \
207             (ap_get_conn_module_loglevel(c, module_index)        \
208              >= ((level)&APLOG_LEVELMASK) ) ) )
209 #define APLOG_R_MODULE_IS_LEVEL(r,module_index,level)            \
210         ( (((level)&APLOG_LEVELMASK) <= APLOG_MAX_LOGLEVEL) &&   \
211           ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) ||       \
212             (ap_get_request_module_loglevel(r, module_index)     \
213              >= ((level)&APLOG_LEVELMASK) ) ) )
214 #endif
215
216 #define APLOG_IS_LEVEL(s,level)     \
217     APLOG_MODULE_IS_LEVEL(s,APLOG_MODULE_INDEX,level)
218 #define APLOG_C_IS_LEVEL(c,level)   \
219     APLOG_C_MODULE_IS_LEVEL(c,APLOG_MODULE_INDEX,level)
220 #define APLOG_CS_IS_LEVEL(c,s,level) \
221     APLOG_CS_MODULE_IS_LEVEL(c,s,APLOG_MODULE_INDEX,level)
222 #define APLOG_R_IS_LEVEL(r,level)   \
223     APLOG_R_MODULE_IS_LEVEL(r,APLOG_MODULE_INDEX,level)
224
225
226 #define APLOGinfo(s)                APLOG_IS_LEVEL(s,APLOG_INFO)
227 #define APLOGdebug(s)               APLOG_IS_LEVEL(s,APLOG_DEBUG)
228 #define APLOGtrace1(s)              APLOG_IS_LEVEL(s,APLOG_TRACE1)
229 #define APLOGtrace2(s)              APLOG_IS_LEVEL(s,APLOG_TRACE2)
230 #define APLOGtrace3(s)              APLOG_IS_LEVEL(s,APLOG_TRACE3)
231 #define APLOGtrace4(s)              APLOG_IS_LEVEL(s,APLOG_TRACE4)
232 #define APLOGtrace5(s)              APLOG_IS_LEVEL(s,APLOG_TRACE5)
233 #define APLOGtrace6(s)              APLOG_IS_LEVEL(s,APLOG_TRACE6)
234 #define APLOGtrace7(s)              APLOG_IS_LEVEL(s,APLOG_TRACE7)
235 #define APLOGtrace8(s)              APLOG_IS_LEVEL(s,APLOG_TRACE8)
236
237 #define APLOGrinfo(r)               APLOG_R_IS_LEVEL(r,APLOG_INFO)
238 #define APLOGrdebug(r)              APLOG_R_IS_LEVEL(r,APLOG_DEBUG)
239 #define APLOGrtrace1(r)             APLOG_R_IS_LEVEL(r,APLOG_TRACE1)
240 #define APLOGrtrace2(r)             APLOG_R_IS_LEVEL(r,APLOG_TRACE2)
241 #define APLOGrtrace3(r)             APLOG_R_IS_LEVEL(r,APLOG_TRACE3)
242 #define APLOGrtrace4(r)             APLOG_R_IS_LEVEL(r,APLOG_TRACE4)
243 #define APLOGrtrace5(r)             APLOG_R_IS_LEVEL(r,APLOG_TRACE5)
244 #define APLOGrtrace6(r)             APLOG_R_IS_LEVEL(r,APLOG_TRACE6)
245 #define APLOGrtrace7(r)             APLOG_R_IS_LEVEL(r,APLOG_TRACE7)
246 #define APLOGrtrace8(r)             APLOG_R_IS_LEVEL(r,APLOG_TRACE8)
247
248 #define APLOGcinfo(c)               APLOG_C_IS_LEVEL(c,APLOG_INFO)
249 #define APLOGcdebug(c)              APLOG_C_IS_LEVEL(c,APLOG_DEBUG)
250 #define APLOGctrace1(c)             APLOG_C_IS_LEVEL(c,APLOG_TRACE1)
251 #define APLOGctrace2(c)             APLOG_C_IS_LEVEL(c,APLOG_TRACE2)
252 #define APLOGctrace3(c)             APLOG_C_IS_LEVEL(c,APLOG_TRACE3)
253 #define APLOGctrace4(c)             APLOG_C_IS_LEVEL(c,APLOG_TRACE4)
254 #define APLOGctrace5(c)             APLOG_C_IS_LEVEL(c,APLOG_TRACE5)
255 #define APLOGctrace6(c)             APLOG_C_IS_LEVEL(c,APLOG_TRACE6)
256 #define APLOGctrace7(c)             APLOG_C_IS_LEVEL(c,APLOG_TRACE7)
257 #define APLOGctrace8(c)             APLOG_C_IS_LEVEL(c,APLOG_TRACE8)
258
259 extern int AP_DECLARE_DATA ap_default_loglevel;
260
261 /**
262  * APLOG_MARK is a convenience macro for use as the first three parameters in
263  * ap_log_error() and related functions, i.e. file, line, and module_index.
264  *
265  * The module_index parameter was introduced in version 2.3.6. Before that
266  * version, APLOG_MARK only replaced the file and line parameters.
267  * This means that APLOG_MARK can be used with ap_log_*error in all versions
268  * of Apache httpd.
269  *
270  * @see APLOG_MODULE_INDEX
271  * @see ap_log_error
272  * @see ap_log_cerror
273  * @see ap_log_rerror
274  * @see ap_log_cserror
275  */
276 #define APLOG_MARK     __FILE__,__LINE__,APLOG_MODULE_INDEX
277
278 /**
279  * Set up for logging to stderr.
280  * @param p The pool to allocate out of
281  */
282 AP_DECLARE(void) ap_open_stderr_log(apr_pool_t *p);
283
284 /**
285  * Replace logging to stderr with logging to the given file.
286  * @param p The pool to allocate out of
287  * @param file Name of the file to log stderr output
288  */
289 AP_DECLARE(apr_status_t) ap_replace_stderr_log(apr_pool_t *p, 
290                                                const char *file);
291
292 /**
293  * Open the error log and replace stderr with it.
294  * @param pconf Not used
295  * @param plog  The pool to allocate the logs from
296  * @param ptemp Pool used for temporary allocations
297  * @param s_main The main server
298  * @note ap_open_logs isn't expected to be used by modules, it is
299  * an internal core function 
300  */
301 int ap_open_logs(apr_pool_t *pconf, apr_pool_t *plog, 
302                  apr_pool_t *ptemp, server_rec *s_main);
303
304 /**
305  * Perform special processing for piped loggers in MPM child
306  * processes.
307  * @param p Not used
308  * @param s Not used
309  * @note ap_logs_child_init is not for use by modules; it is an
310  * internal core function
311  */
312 void ap_logs_child_init(apr_pool_t *p, server_rec *s);
313
314 /* 
315  * The primary logging functions, ap_log_error, ap_log_rerror, ap_log_cerror,
316  * and ap_log_perror use a printf style format string to build the log message.  
317  * It is VERY IMPORTANT that you not include any raw data from the network, 
318  * such as the request-URI or request header fields, within the format 
319  * string.  Doing so makes the server vulnerable to a denial-of-service 
320  * attack and other messy behavior.  Instead, use a simple format string 
321  * like "%s", followed by the string containing the untrusted data.
322  */
323
324 /**
325  * ap_log_error() - log messages which are not related to a particular
326  * request or connection.  This uses a printf-like format to log messages
327  * to the error_log.
328  * @param file The file in which this function is called
329  * @param line The line number on which this function is called
330  * @param module_index The module_index of the module generating this message
331  * @param level The level of this error message
332  * @param status The status code from the previous command
333  * @param s The server on which we are logging
334  * @param fmt The format string
335  * @param ... The arguments to use to fill out fmt.
336  * @note ap_log_error is implemented as a macro
337  * @note Use APLOG_MARK to fill out file and line
338  * @note If a request_rec is available, use that with ap_log_rerror()
339  * in preference to calling this function.  Otherwise, if a conn_rec is
340  * available, use that with ap_log_cerror() in preference to calling
341  * this function.
342  * @warning It is VERY IMPORTANT that you not include any raw data from 
343  * the network, such as the request-URI or request header fields, within 
344  * the format string.  Doing so makes the server vulnerable to a 
345  * denial-of-service attack and other messy behavior.  Instead, use a 
346  * simple format string like "%s", followed by the string containing the 
347  * untrusted data.
348  */
349 #ifdef DOXYGEN
350 AP_DECLARE(void) ap_log_error(const char *file, int line, int module_index,
351                               int level, apr_status_t status,
352                               const server_rec *s, const char *fmt, ...);
353 #else
354 #if __STDC_VERSION__ >= 199901L
355 /* need additional step to expand APLOG_MARK first */
356 #define ap_log_error(...) ap_log_error__(__VA_ARGS__)
357 /* need server_rec *sr = ... for the case if s is verbatim NULL */
358 #define ap_log_error__(file, line, mi, level, status, s, ...)           \
359     do { const server_rec *sr = s; if (APLOG_MODULE_IS_LEVEL(sr, mi, level))      \
360              ap_log_error_(file, line, mi, level, status, sr, __VA_ARGS__); \
361     } while(0)
362 #else
363 #define ap_log_error ap_log_error_
364 #endif
365 AP_DECLARE(void) ap_log_error_(const char *file, int line, int module_index,
366                                int level, apr_status_t status,
367                                const server_rec *s, const char *fmt, ...)
368                               __attribute__((format(printf,7,8)));
369 #endif
370
371 /**
372  * ap_log_perror() - log messages which are not related to a particular
373  * request, connection, or virtual server.  This uses a printf-like
374  * format to log messages to the error_log.
375  * @param file The file in which this function is called
376  * @param line The line number on which this function is called
377  * @param module_index ignored dummy value for use by APLOG_MARK
378  * @param level The level of this error message
379  * @param status The status code from the previous command
380  * @param p The pool which we are logging for
381  * @param fmt The format string
382  * @param ... The arguments to use to fill out fmt.
383  * @note ap_log_perror is implemented as a macro
384  * @note Use APLOG_MARK to fill out file, line, and module_index
385  * @warning It is VERY IMPORTANT that you not include any raw data from 
386  * the network, such as the request-URI or request header fields, within 
387  * the format string.  Doing so makes the server vulnerable to a 
388  * denial-of-service attack and other messy behavior.  Instead, use a 
389  * simple format string like "%s", followed by the string containing the 
390  * untrusted data.
391  */
392 #ifdef DOXYGEN
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 #else
397 #if __STDC_VERSION__ >= 199901L && defined(APLOG_MAX_LOGLEVEL)
398 /* need additional step to expand APLOG_MARK first */
399 #define ap_log_perror(...) ap_log_perror__(__VA_ARGS__)
400 #define ap_log_perror__(file, line, mi, level, status, p, ...)            \
401     do { if ((level) <= APLOG_MAX_LOGLEVEL )                              \
402              ap_log_perror_(file, line, mi, level, status, p,             \
403                             __VA_ARGS__); } while(0)
404 #else
405 #define ap_log_perror ap_log_perror_
406 #endif
407 AP_DECLARE(void) ap_log_perror_(const char *file, int line, int module_index,
408                                 int level, apr_status_t status, apr_pool_t *p,
409                                 const char *fmt, ...)
410                                __attribute__((format(printf,7,8)));
411 #endif
412
413 /**
414  * ap_log_rerror() - log messages which are related to a particular
415  * request.  This uses a printf-like format to log messages to the
416  * error_log.
417  * @param file The file in which this function is called
418  * @param line The line number on which this function is called
419  * @param module_index The module_index of the module generating this message
420  * @param level The level of this error message
421  * @param status The status code from the previous command
422  * @param r The request which we are logging for
423  * @param fmt The format string
424  * @param ... The arguments to use to fill out fmt.
425  * @note ap_log_rerror is implemented as a macro
426  * @note Use APLOG_MARK to fill out file, line, and module_index
427  * @warning It is VERY IMPORTANT that you not include any raw data from 
428  * the network, such as the request-URI or request header fields, within 
429  * the format string.  Doing so makes the server vulnerable to a 
430  * denial-of-service attack and other messy behavior.  Instead, use a 
431  * simple format string like "%s", followed by the string containing the 
432  * untrusted data.
433  */
434 #ifdef DOXYGEN
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 #else
439 #if __STDC_VERSION__ >= 199901L
440 /* need additional step to expand APLOG_MARK first */
441 #define ap_log_rerror(...) ap_log_rerror__(__VA_ARGS__)
442 #define ap_log_rerror__(file, line, mi, level, status, r, ...)              \
443     do { if (APLOG_R_MODULE_IS_LEVEL(r, mi, level))                         \
444              ap_log_rerror_(file, line, mi, level, status, r, __VA_ARGS__); \
445     } while(0)
446 #else
447 #define ap_log_rerror ap_log_rerror_
448 #endif
449 AP_DECLARE(void) ap_log_rerror_(const char *file, int line, int module_index,
450                                 int level, apr_status_t status,
451                                 const request_rec *r, const char *fmt, ...)
452                                 __attribute__((format(printf,7,8)));
453 #endif
454
455 /**
456  * ap_log_cerror() - log messages which are related to a particular
457  * connection.  This uses a printf-like format to log messages to the
458  * error_log.
459  * @param file The file in which this function is called
460  * @param line The line number on which this function is called
461  * @param level The level of this error message
462  * @param module_index The module_index of the module generating this message
463  * @param status The status code from the previous command
464  * @param c The connection which we are logging for
465  * @param fmt The format string
466  * @param ... The arguments to use to fill out fmt.
467  * @note ap_log_cerror is implemented as a macro
468  * @note Use APLOG_MARK to fill out file, line, and module_index
469  * @note If a request_rec is available, use that with ap_log_rerror()
470  * in preference to calling this function.
471  * @warning It is VERY IMPORTANT that you not include any raw data from 
472  * the network, such as the request-URI or request header fields, within 
473  * the format string.  Doing so makes the server vulnerable to a 
474  * denial-of-service attack and other messy behavior.  Instead, use a 
475  * simple format string like "%s", followed by the string containing the 
476  * untrusted data.
477  */
478 #ifdef DOXYGEN
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 #else
483 #if __STDC_VERSION__ >= 199901L
484 /* need additional step to expand APLOG_MARK first */
485 #define ap_log_cerror(...) ap_log_cerror__(__VA_ARGS__)
486 #define ap_log_cerror__(file, line, mi, level, status, c, ...)              \
487     do { if (APLOG_C_MODULE_IS_LEVEL(c, mi, level))                         \
488              ap_log_cerror_(file, line, mi, level, status, c, __VA_ARGS__); \
489     } while(0)
490 #else
491 #define ap_log_cerror ap_log_cerror_
492 #endif
493 AP_DECLARE(void) ap_log_cerror_(const char *file, int line, int module_index,
494                                 int level, apr_status_t status,
495                                 const conn_rec *c, const char *fmt, ...)
496                                 __attribute__((format(printf,7,8)));
497 #endif
498
499 /**
500  * ap_log_cserror() - log messages which are related to a particular
501  * connection and to a vhost other than c->base_server.  This uses a
502  * printf-like format to log messages to the error_log.
503  * @param file The file in which this function is called
504  * @param line The line number on which this function is called
505  * @param level The level of this error message
506  * @param module_index The module_index of the module generating this message
507  * @param status The status code from the previous command
508  * @param c The connection which we are logging for
509  * @param s The server which we are logging for
510  * @param fmt The format string
511  * @param ... The arguments to use to fill out fmt.
512  * @note ap_log_cserror is implemented as a macro
513  * @note Use APLOG_MARK to fill out file, line, and module_index
514  * @note If a request_rec is available, use that with ap_log_rerror()
515  * in preference to calling this function. This function is mainly useful for
516  * modules like mod_ssl to use before the request_rec is created.
517  * @warning It is VERY IMPORTANT that you not include any raw data from 
518  * the network, such as the request-URI or request header fields, within 
519  * the format string.  Doing so makes the server vulnerable to a 
520  * denial-of-service attack and other messy behavior.  Instead, use a 
521  * simple format string like "%s", followed by the string containing the 
522  * untrusted data.
523  */
524 #ifdef DOXYGEN
525 AP_DECLARE(void) ap_log_cserror(const char *file, int line, int module_index,
526                                 int level, apr_status_t status,
527                                 const conn_rec *c, const server_rec *s,
528                                 const char *fmt, ...);
529 #else
530 #if __STDC_VERSION__ >= 199901L
531 /* need additional step to expand APLOG_MARK first */
532 #define ap_log_cserror(...) ap_log_cserror__(__VA_ARGS__)
533 #define ap_log_cserror__(file, line, mi, level, status, c, s, ...)  \
534     do { if (APLOG_CS_MODULE_IS_LEVEL(c, s, mi, level))             \
535              ap_log_cserror_(file, line, mi, level, status, c, s,   \
536                              __VA_ARGS__);                          \
537     } while(0)
538 #else
539 #define ap_log_cserror ap_log_cserror_
540 #endif
541 AP_DECLARE(void) ap_log_cserror_(const char *file, int line, int module_index,
542                                  int level, apr_status_t status,
543                                  const conn_rec *c, const server_rec *s,
544                                  const char *fmt, ...)
545                              __attribute__((format(printf,8,9)));
546 #endif
547
548 /**
549  * Convert stderr to the error log
550  * @param s The current server
551  */
552 AP_DECLARE(void) ap_error_log2stderr(server_rec *s);
553
554 /**
555  * Log the command line used to start the server.
556  * @param p The pool to use for logging
557  * @param s The server_rec whose process's command line we want to log.
558  * The command line is logged to that server's error log.
559  */
560 AP_DECLARE(void) ap_log_command_line(apr_pool_t *p, server_rec *s);
561
562 /**
563  * Log the current pid of the parent process
564  * @param p The pool to use for processing
565  * @param fname The name of the file to log to
566  */
567 AP_DECLARE(void) ap_log_pid(apr_pool_t *p, const char *fname);
568
569 /**
570  * Remove the pidfile.
571  * @param p The pool to use for processing
572  * @param fname The name of the pid file to remove
573  */
574 AP_DECLARE(void) ap_remove_pid(apr_pool_t *p, const char *fname);
575
576 /**
577  * Retrieve the pid from a pidfile.
578  * @param p The pool to use for processing
579  * @param filename The name of the file containing the pid
580  * @param mypid Pointer to pid_t (valid only if return APR_SUCCESS)
581  */
582 AP_DECLARE(apr_status_t) ap_read_pid(apr_pool_t *p, const char *filename, pid_t *mypid);
583
584 /** @see piped_log */
585 typedef struct piped_log piped_log;
586
587 /**
588  * Open the piped log process
589  * @param p The pool to allocate out of
590  * @param program The program to run in the logging process
591  * @return The piped log structure
592  * @note The log program is invoked as @p APR_PROGRAM_ENV, 
593  *      @see ap_open_piped_log_ex to modify this behavior
594  */
595 AP_DECLARE(piped_log *) ap_open_piped_log(apr_pool_t *p, const char *program);
596
597 /**
598  * Open the piped log process specifying the execution choice for program
599  * @param p The pool to allocate out of
600  * @param program The program to run in the logging process
601  * @param cmdtype How to invoke program, e.g. APR_PROGRAM, APR_SHELLCMD_ENV, etc
602  * @return The piped log structure
603  */
604 AP_DECLARE(piped_log *) ap_open_piped_log_ex(apr_pool_t *p,
605                                              const char *program,
606                                              apr_cmdtype_e cmdtype);
607
608 /**
609  * Close the piped log and kill the logging process
610  * @param pl The piped log structure
611  */
612 AP_DECLARE(void) ap_close_piped_log(piped_log *pl);
613
614 /**
615  * A function to return the read side of the piped log pipe
616  * @param pl The piped log structure
617  * @return The native file descriptor
618  */
619 AP_DECLARE(apr_file_t *) ap_piped_log_read_fd(piped_log *pl);
620
621 /**
622  * A function to return the write side of the piped log pipe
623  * @param pl The piped log structure
624  * @return The native file descriptor
625  */
626 AP_DECLARE(apr_file_t *) ap_piped_log_write_fd(piped_log *pl);
627
628 /**
629  * hook method to log error messages 
630  * @ingroup hooks
631  * @param file The file in which this function is called
632  * @param line The line number on which this function is called
633  * @param module_index The module_index of the module generating this message
634  * @param level The level of this error message
635  * @param status The status code from the previous command
636  * @param s The server which we are logging for
637  * @param r The request which we are logging for
638  * @param pool Memory pool to allocate from
639  * @param errstr message to log 
640  */
641 AP_DECLARE_HOOK(void, error_log, (const char *file, int line,
642                        int module_index, int level,
643                        apr_status_t status, const server_rec *s,
644                        const request_rec *r, apr_pool_t *pool,
645                        const char *errstr))
646
647 /**
648  * hook method to generate unique id for connection or request
649  * @ingroup hooks
650  * @param c the conn_rec of the connections
651  * @param r the request_req (may be NULL)
652  * @param id the place where to store the unique id
653  * @return OK or DECLINE
654  */
655 AP_DECLARE_HOOK(int, generate_log_id,
656                 (const conn_rec *c, const request_rec *r, const char **id))
657
658
659 #ifdef __cplusplus
660 }
661 #endif
662
663 #endif  /* !APACHE_HTTP_LOG_H */
664 /** @} */