]> granicus.if.org Git - apache/blob - include/http_log.h
* docs/manual/mod/mod_ssl.xml: Flesh out SSLRenegBufferSize
[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 #ifndef LOG_PRIMASK
39 #define LOG_PRIMASK 7
40 #endif
41
42 #define APLOG_EMERG     LOG_EMERG     /* system is unusable */
43 #define APLOG_ALERT     LOG_ALERT     /* action must be taken immediately */
44 #define APLOG_CRIT      LOG_CRIT      /* critical conditions */
45 #define APLOG_ERR       LOG_ERR       /* error conditions */
46 #define APLOG_WARNING   LOG_WARNING   /* warning conditions */
47 #define APLOG_NOTICE    LOG_NOTICE    /* normal but significant condition */
48 #define APLOG_INFO      LOG_INFO      /* informational */
49 #define APLOG_DEBUG     LOG_DEBUG     /* debug-level messages */
50
51 #define APLOG_LEVELMASK LOG_PRIMASK   /* mask off the level value */
52
53 #else
54
55 #define APLOG_EMERG     0       /* system is unusable */
56 #define APLOG_ALERT     1       /* action must be taken immediately */
57 #define APLOG_CRIT      2       /* critical conditions */
58 #define APLOG_ERR       3       /* error conditions */
59 #define APLOG_WARNING   4       /* warning conditions */
60 #define APLOG_NOTICE    5       /* normal but significant condition */
61 #define APLOG_INFO      6       /* informational */
62 #define APLOG_DEBUG     7       /* debug-level messages */
63
64 #define APLOG_LEVELMASK 7       /* mask off the level value */
65
66 #endif
67
68 /* APLOG_NOERRNO is ignored and should not be used.  It will be
69  * removed in a future release of Apache.
70  */
71 #define APLOG_NOERRNO           (APLOG_LEVELMASK + 1)
72
73 /* Use APLOG_TOCLIENT on ap_log_rerror() to give content
74  * handlers the option of including the error text in the 
75  * ErrorDocument sent back to the client. Setting APLOG_TOCLIENT
76  * will cause the error text to be saved in the request_rec->notes 
77  * table, keyed to the string "error-notes", if and only if:
78  * - the severity level of the message is APLOG_WARNING or greater
79  * - there are no other "error-notes" set in request_rec->notes
80  * Once error-notes is set, it is up to the content handler to
81  * determine whether this text should be sent back to the client.
82  * Note: Client generated text streams sent back to the client MUST 
83  * be escaped to prevent CSS attacks.
84  */
85 #define APLOG_TOCLIENT          ((APLOG_LEVELMASK + 1) * 2)
86
87 /* normal but significant condition on startup, usually printed to stderr */
88 #define APLOG_STARTUP           ((APLOG_LEVELMASK + 1) * 4) 
89
90 #ifndef DEFAULT_LOGLEVEL
91 #define DEFAULT_LOGLEVEL        APLOG_WARNING
92 #endif
93
94 extern int AP_DECLARE_DATA ap_default_loglevel;
95
96 #define APLOG_MARK      __FILE__,__LINE__
97
98 /**
99  * Set up for logging to stderr.
100  * @param p The pool to allocate out of
101  */
102 AP_DECLARE(void) ap_open_stderr_log(apr_pool_t *p);
103
104 /**
105  * Replace logging to stderr with logging to the given file.
106  * @param p The pool to allocate out of
107  * @param file Name of the file to log stderr output
108  */
109 AP_DECLARE(apr_status_t) ap_replace_stderr_log(apr_pool_t *p, 
110                                                const char *file);
111
112 /**
113  * Open the error log and replace stderr with it.
114  * @param pconf Not used
115  * @param plog  The pool to allocate the logs from
116  * @param ptemp Pool used for temporary allocations
117  * @param s_main The main server
118  * @note ap_open_logs isn't expected to be used by modules, it is
119  * an internal core function 
120  */
121 int ap_open_logs(apr_pool_t *pconf, apr_pool_t *plog, 
122                  apr_pool_t *ptemp, server_rec *s_main);
123
124 /**
125  * Perform special processing for piped loggers in MPM child
126  * processes.
127  * @param p Not used
128  * @param s Not used
129  * @note ap_logs_child_init is not for use by modules; it is an
130  * internal core function
131  */
132 void ap_logs_child_init(apr_pool_t *p, server_rec *s);
133
134 /* 
135  * The primary logging functions, ap_log_error, ap_log_rerror, ap_log_cerror,
136  * and ap_log_perror use a printf style format string to build the log message.  
137  * It is VERY IMPORTANT that you not include any raw data from the network, 
138  * such as the request-URI or request header fields, within the format 
139  * string.  Doing so makes the server vulnerable to a denial-of-service 
140  * attack and other messy behavior.  Instead, use a simple format string 
141  * like "%s", followed by the string containing the untrusted data.
142  */
143
144 /**
145  * ap_log_error() - log messages which are not related to a particular
146  * request or connection.  This uses a printf-like format to log messages
147  * to the error_log.
148  * @param file The file in which this function is called
149  * @param line The line number on which this function is called
150  * @param level The level of this error message
151  * @param status The status code from the previous command
152  * @param s The server on which we are logging
153  * @param fmt The format string
154  * @param ... The arguments to use to fill out fmt.
155  * @note Use APLOG_MARK to fill out file and line
156  * @note If a request_rec is available, use that with ap_log_rerror()
157  * in preference to calling this function.  Otherwise, if a conn_rec is
158  * available, use that with ap_log_cerror() in preference to calling
159  * this function.
160  * @warning It is VERY IMPORTANT that you not include any raw data from 
161  * the network, such as the request-URI or request header fields, within 
162  * the format string.  Doing so makes the server vulnerable to a 
163  * denial-of-service attack and other messy behavior.  Instead, use a 
164  * simple format string like "%s", followed by the string containing the 
165  * untrusted data.
166  */
167 AP_DECLARE(void) ap_log_error(const char *file, int line, int level, 
168                              apr_status_t status, const server_rec *s, 
169                              const char *fmt, ...)
170                             __attribute__((format(printf,6,7)));
171
172 /**
173  * ap_log_perror() - log messages which are not related to a particular
174  * request, connection, or virtual server.  This uses a printf-like
175  * format to log messages to the error_log.
176  * @param file The file in which this function is called
177  * @param line The line number on which this function is called
178  * @param level The level of this error message
179  * @param status The status code from the previous command
180  * @param p The pool which we are logging for
181  * @param fmt The format string
182  * @param ... The arguments to use to fill out fmt.
183  * @note Use APLOG_MARK to fill out file and line
184  * @warning It is VERY IMPORTANT that you not include any raw data from 
185  * the network, such as the request-URI or request header fields, within 
186  * the format string.  Doing so makes the server vulnerable to a 
187  * denial-of-service attack and other messy behavior.  Instead, use a 
188  * simple format string like "%s", followed by the string containing the 
189  * untrusted data.
190  */
191 AP_DECLARE(void) ap_log_perror(const char *file, int line, int level, 
192                              apr_status_t status, apr_pool_t *p, 
193                              const char *fmt, ...)
194                             __attribute__((format(printf,6,7)));
195
196 /**
197  * ap_log_rerror() - log messages which are related to a particular
198  * request.  This uses a a printf-like format to log messages to the
199  * error_log.
200  * @param file The file in which this function is called
201  * @param line The line number on which this function is called
202  * @param level The level of this error message
203  * @param status The status code from the previous command
204  * @param r The request which we are logging for
205  * @param fmt The format string
206  * @param ... The arguments to use to fill out fmt.
207  * @note Use APLOG_MARK to fill out file and line
208  * @warning It is VERY IMPORTANT that you not include any raw data from 
209  * the network, such as the request-URI or request header fields, within 
210  * the format string.  Doing so makes the server vulnerable to a 
211  * denial-of-service attack and other messy behavior.  Instead, use a 
212  * simple format string like "%s", followed by the string containing the 
213  * untrusted data.
214  */
215 AP_DECLARE(void) ap_log_rerror(const char *file, int line, int level, 
216                                apr_status_t status, const request_rec *r, 
217                                const char *fmt, ...)
218                             __attribute__((format(printf,6,7)));
219
220 /**
221  * ap_log_cerror() - log messages which are related to a particular
222  * connection.  This uses a a printf-like format to log messages to the
223  * error_log.
224  * @param file The file in which this function is called
225  * @param line The line number on which this function is called
226  * @param level The level of this error message
227  * @param status The status code from the previous command
228  * @param c The connection which we are logging for
229  * @param fmt The format string
230  * @param ... The arguments to use to fill out fmt.
231  * @note Use APLOG_MARK to fill out file and line
232  * @note If a request_rec is available, use that with ap_log_rerror()
233  * in preference to calling this function.
234  * @warning It is VERY IMPORTANT that you not include any raw data from 
235  * the network, such as the request-URI or request header fields, within 
236  * the format string.  Doing so makes the server vulnerable to a 
237  * denial-of-service attack and other messy behavior.  Instead, use a 
238  * simple format string like "%s", followed by the string containing the 
239  * untrusted data.
240  */
241 AP_DECLARE(void) ap_log_cerror(const char *file, int line, int level, 
242                                apr_status_t status, const conn_rec *c, 
243                                const char *fmt, ...)
244                             __attribute__((format(printf,6,7)));
245
246 /**
247  * Convert stderr to the error log
248  * @param s The current server
249  */
250 AP_DECLARE(void) ap_error_log2stderr(server_rec *s);
251
252 /**
253  * Log the current pid of the parent process
254  * @param p The pool to use for logging
255  * @param fname The name of the file to log to
256  */
257 AP_DECLARE(void) ap_log_pid(apr_pool_t *p, const char *fname);
258
259 /**
260  * Retrieve the pid from a pidfile.
261  * @param p The pool to use for logging
262  * @param filename The name of the file containing the pid
263  * @param mypid Pointer to pid_t (valid only if return APR_SUCCESS)
264  */
265 AP_DECLARE(apr_status_t) ap_read_pid(apr_pool_t *p, const char *filename, pid_t *mypid);
266
267 /** @see piped_log */
268 typedef struct piped_log piped_log;
269
270 /**
271  * @brief The piped logging structure.  
272  *
273  * Piped logs are used to move functionality out of the main server.  
274  * For example, log rotation is done with piped logs.
275  */
276 struct piped_log {
277     /** The pool to use for the piped log */
278     apr_pool_t *p;
279     /** The pipe between the server and the logging process */
280     apr_file_t *fds[2];
281     /* XXX - an #ifdef that needs to be eliminated from public view. Shouldn't
282      * be hard */
283 #ifdef AP_HAVE_RELIABLE_PIPED_LOGS
284     /** The name of the program the logging process is running */
285     char *program;
286     /** The pid of the logging process */
287     apr_proc_t *pid;
288 #endif
289 };
290
291 /**
292  * Open the piped log process
293  * @param p The pool to allocate out of
294  * @param program The program to run in the logging process
295  * @return The piped log structure
296  */
297 AP_DECLARE(piped_log *) ap_open_piped_log(apr_pool_t *p, const char *program);
298
299 /**
300  * Close the piped log and kill the logging process
301  * @param pl The piped log structure
302  */
303 AP_DECLARE(void) ap_close_piped_log(piped_log *pl);
304
305 /**
306  * A macro to access the read side of the piped log pipe
307  * @param pl The piped log structure
308  * @return The native file descriptor
309  */
310 #define ap_piped_log_read_fd(pl)        ((pl)->fds[0])
311
312 /**
313  * A macro to access the write side of the piped log pipe
314  * @param pl The piped log structure
315  * @return The native file descriptor
316  */
317 #define ap_piped_log_write_fd(pl)       ((pl)->fds[1])
318
319 /**
320  * hook method to log error messages 
321  * @ingroup hooks
322  * @param file The file in which this function is called
323  * @param line The line number on which this function is called
324  * @param level The level of this error message
325  * @param status The status code from the previous command
326  * @param s The server which we are logging for
327  * @param r The request which we are logging for
328  * @param pool Memory pool to allocate from
329  * @param errstr message to log 
330  */
331 AP_DECLARE_HOOK(void, error_log, (const char *file, int line, int level,
332                        apr_status_t status, const server_rec *s,
333                        const request_rec *r, apr_pool_t *pool,
334                        const char *errstr))
335
336 #ifdef __cplusplus
337 }
338 #endif
339
340 #endif  /* !APACHE_HTTP_LOG_H */
341 /** @} */