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);
127
* Perform special processing for piped loggers in MPM child
131
* @note ap_logs_child_init is not for use by modules; it is an
132
* internal core function
134
void ap_logs_child_init(apr_pool_t *p, server_rec *s);
136
#endif /* CORE_PRIVATE */
139
* The primary logging functions, ap_log_error, ap_log_rerror, ap_log_cerror,
140
* and ap_log_perror use a printf style format string to build the log message.
141
* It is VERY IMPORTANT that you not include any raw data from the network,
142
* such as the request-URI or request header fields, within the format
143
* string. Doing so makes the server vulnerable to a denial-of-service
144
* attack and other messy behavior. Instead, use a simple format string
145
* like "%s", followed by the string containing the untrusted data.
149
* ap_log_error() - log messages which are not related to a particular
150
* request or connection. This uses a printf-like format to log messages
152
* @param file The file in which this function is called
153
* @param line The line number on which this function is called
154
* @param level The level of this error message
155
* @param status The status code from the previous command
156
* @param s The server on which we are logging
157
* @param fmt The format string
158
* @param ... The arguments to use to fill out fmt.
159
* @note Use APLOG_MARK to fill out file and line
160
* @note If a request_rec is available, use that with ap_log_rerror()
161
* in preference to calling this function. Otherwise, if a conn_rec is
162
* available, use that with ap_log_cerror() in preference to calling
164
* @warning It is VERY IMPORTANT that you not include any raw data from
165
* the network, such as the request-URI or request header fields, within
166
* the format string. Doing so makes the server vulnerable to a
167
* denial-of-service attack and other messy behavior. Instead, use a
168
* simple format string like "%s", followed by the string containing the
171
AP_DECLARE(void) ap_log_error(const char *file, int line, int level,
172
apr_status_t status, const server_rec *s,
173
const char *fmt, ...)
174
__attribute__((format(printf,6,7)));
177
* ap_log_perror() - log messages which are not related to a particular
178
* request, connection, or virtual server. This uses a printf-like
179
* format to log messages to the error_log.
180
* @param file The file in which this function is called
181
* @param line The line number on which this function is called
182
* @param level The level of this error message
183
* @param status The status code from the previous command
184
* @param p The pool which we are logging for
185
* @param fmt The format string
186
* @param ... The arguments to use to fill out fmt.
187
* @note Use APLOG_MARK to fill out file and line
188
* @warning It is VERY IMPORTANT that you not include any raw data from
189
* the network, such as the request-URI or request header fields, within
190
* the format string. Doing so makes the server vulnerable to a
191
* denial-of-service attack and other messy behavior. Instead, use a
192
* simple format string like "%s", followed by the string containing the
195
AP_DECLARE(void) ap_log_perror(const char *file, int line, int level,
196
apr_status_t status, apr_pool_t *p,
197
const char *fmt, ...)
198
__attribute__((format(printf,6,7)));
201
* ap_log_rerror() - log messages which are related to a particular
202
* request. This uses a a printf-like format to log messages to the
204
* @param file The file in which this function is called
205
* @param line The line number on which this function is called
206
* @param level The level of this error message
207
* @param status The status code from the previous command
208
* @param r The request which we are logging for
209
* @param fmt The format string
210
* @param ... The arguments to use to fill out fmt.
211
* @note Use APLOG_MARK to fill out file and line
212
* @warning It is VERY IMPORTANT that you not include any raw data from
213
* the network, such as the request-URI or request header fields, within
214
* the format string. Doing so makes the server vulnerable to a
215
* denial-of-service attack and other messy behavior. Instead, use a
216
* simple format string like "%s", followed by the string containing the
219
AP_DECLARE(void) ap_log_rerror(const char *file, int line, int level,
220
apr_status_t status, const request_rec *r,
221
const char *fmt, ...)
222
__attribute__((format(printf,6,7)));
225
* ap_log_cerror() - log messages which are related to a particular
226
* connection. This uses a a printf-like format to log messages to the
228
* @param file The file in which this function is called
229
* @param line The line number on which this function is called
230
* @param level The level of this error message
231
* @param status The status code from the previous command
232
* @param c The connection which we are logging for
233
* @param fmt The format string
234
* @param ... The arguments to use to fill out fmt.
235
* @note Use APLOG_MARK to fill out file and line
236
* @note If a request_rec is available, use that with ap_log_rerror()
237
* in preference to calling this function.
238
* @warning It is VERY IMPORTANT that you not include any raw data from
239
* the network, such as the request-URI or request header fields, within
240
* the format string. Doing so makes the server vulnerable to a
241
* denial-of-service attack and other messy behavior. Instead, use a
242
* simple format string like "%s", followed by the string containing the
245
AP_DECLARE(void) ap_log_cerror(const char *file, int line, int level,
246
apr_status_t status, const conn_rec *c,
247
const char *fmt, ...)
248
__attribute__((format(printf,6,7)));
251
* Convert stderr to the error log
252
* @param s The current server
254
AP_DECLARE(void) ap_error_log2stderr(server_rec *s);
257
* Log the current pid of the parent process
258
* @param p The pool to use for logging
259
* @param fname The name of the file to log to
261
AP_DECLARE(void) ap_log_pid(apr_pool_t *p, const char *fname);
264
* Retrieve the pid from a pidfile.
265
* @param p The pool to use for logging
266
* @param filename The name of the file containing the pid
267
* @param mypid Pointer to pid_t (valid only if return APR_SUCCESS)
269
AP_DECLARE(apr_status_t) ap_read_pid(apr_pool_t *p, const char *filename, pid_t *mypid);
271
/** @see piped_log */
272
typedef struct piped_log piped_log;
275
* @brief The piped logging structure.
277
* Piped logs are used to move functionality out of the main server.
278
* For example, log rotation is done with piped logs.
281
/** The pool to use for the piped log */
283
/** The pipe between the server and the logging process */
285
/* XXX - an #ifdef that needs to be eliminated from public view. Shouldn't
287
#ifdef AP_HAVE_RELIABLE_PIPED_LOGS
288
/** The name of the program the logging process is running */
290
/** The pid of the logging process */
296
* Open the piped log process
297
* @param p The pool to allocate out of
298
* @param program The program to run in the logging process
299
* @return The piped log structure
301
AP_DECLARE(piped_log *) ap_open_piped_log(apr_pool_t *p, const char *program);
304
* Close the piped log and kill the logging process
305
* @param pl The piped log structure
307
AP_DECLARE(void) ap_close_piped_log(piped_log *pl);
310
* A macro to access the read side of the piped log pipe
311
* @param pl The piped log structure
312
* @return The native file descriptor
314
#define ap_piped_log_read_fd(pl) ((pl)->fds[0])
317
* A macro to access the write side of the piped log pipe
318
* @param pl The piped log structure
319
* @return The native file descriptor
321
#define ap_piped_log_write_fd(pl) ((pl)->fds[1])
324
* hook method to log error messages
326
* @param file The file in which this function is called
327
* @param line The line number on which this function is called
328
* @param level The level of this error message
329
* @param status The status code from the previous command
330
* @param s The server which we are logging for
331
* @param r The request which we are logging for
332
* @param pool Memory pool to allocate from
333
* @param errstr message to log
335
AP_DECLARE_HOOK(void, error_log, (const char *file, int line, int level,
336
apr_status_t status, const server_rec *s,
337
const request_rec *r, apr_pool_t *pool,
344
#endif /* !APACHE_HTTP_LOG_H */