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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @brief Apache Logging library
21 * @defgroup APACHE_CORE_LOG Logging library
22 * @ingroup APACHE_CORE
26 #ifndef APACHE_HTTP_LOG_H
27 #define APACHE_HTTP_LOG_H
33 #include "apr_thread_proc.h"
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 */
51 #define APLOG_LEVELMASK LOG_PRIMASK /* mask off the level value */
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 */
64 #define APLOG_LEVELMASK 7 /* mask off the level value */
68 /* APLOG_NOERRNO is ignored and should not be used. It will be
69 * removed in a future release of Apache.
71 #define APLOG_NOERRNO (APLOG_LEVELMASK + 1)
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.
85 #define APLOG_TOCLIENT ((APLOG_LEVELMASK + 1) * 2)
87 /* normal but significant condition on startup, usually printed to stderr */
88 #define APLOG_STARTUP ((APLOG_LEVELMASK + 1) * 4)
90 #ifndef DEFAULT_LOGLEVEL
91 #define DEFAULT_LOGLEVEL APLOG_WARNING
94 extern int AP_DECLARE_DATA ap_default_loglevel;
96 #define APLOG_MARK __FILE__,__LINE__
99 * Set up for logging to stderr.
100 * @param p The pool to allocate out of
102 AP_DECLARE(void) ap_open_stderr_log(apr_pool_t *p);
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
109 AP_DECLARE(apr_status_t) ap_replace_stderr_log(apr_pool_t *p,
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
121 int ap_open_logs(apr_pool_t *pconf, apr_pool_t *plog,
122 apr_pool_t *ptemp, server_rec *s_main);
125 * Perform special processing for piped loggers in MPM child
129 * @note ap_logs_child_init is not for use by modules; it is an
130 * internal core function
132 void ap_logs_child_init(apr_pool_t *p, server_rec *s);
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.
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
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
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
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)));
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
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)));
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
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
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)));
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
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
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)));
247 * Convert stderr to the error log
248 * @param s The current server
250 AP_DECLARE(void) ap_error_log2stderr(server_rec *s);
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
257 AP_DECLARE(void) ap_log_pid(apr_pool_t *p, const char *fname);
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)
265 AP_DECLARE(apr_status_t) ap_read_pid(apr_pool_t *p, const char *filename, pid_t *mypid);
267 /** @see piped_log */
268 typedef struct piped_log piped_log;
271 * @brief The piped logging structure.
273 * Piped logs are used to move functionality out of the main server.
274 * For example, log rotation is done with piped logs.
277 /** The pool to use for the piped log */
279 /** The pipe between the server and the logging process */
281 /* XXX - an #ifdef that needs to be eliminated from public view. Shouldn't
283 #ifdef AP_HAVE_RELIABLE_PIPED_LOGS
284 /** The name of the program the logging process is running */
286 /** The pid of the logging process */
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
297 AP_DECLARE(piped_log *) ap_open_piped_log(apr_pool_t *p, const char *program);
300 * Close the piped log and kill the logging process
301 * @param pl The piped log structure
303 AP_DECLARE(void) ap_close_piped_log(piped_log *pl);
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
310 #define ap_piped_log_read_fd(pl) ((pl)->fds[0])
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
317 #define ap_piped_log_write_fd(pl) ((pl)->fds[1])
320 * hook method to log error messages
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
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,
340 #endif /* !APACHE_HTTP_LOG_H */