00001 /* Copyright 1999-2005 The Apache Software Foundation or its licensors, as 00002 * applicable. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef APACHE_HTTP_LOG_H 00018 #define APACHE_HTTP_LOG_H 00019 00020 #ifdef __cplusplus 00021 extern "C" { 00022 #endif 00023 00024 #include "apr_thread_proc.h" 00025 00026 /** 00027 * @package Apache logging library 00028 */ 00029 00030 #ifdef HAVE_SYSLOG 00031 #include <syslog.h> 00032 00033 #ifndef LOG_PRIMASK 00034 #define LOG_PRIMASK 7 00035 #endif 00036 00037 #define APLOG_EMERG LOG_EMERG /* system is unusable */ 00038 #define APLOG_ALERT LOG_ALERT /* action must be taken immediately */ 00039 #define APLOG_CRIT LOG_CRIT /* critical conditions */ 00040 #define APLOG_ERR LOG_ERR /* error conditions */ 00041 #define APLOG_WARNING LOG_WARNING /* warning conditions */ 00042 #define APLOG_NOTICE LOG_NOTICE /* normal but significant condition */ 00043 #define APLOG_INFO LOG_INFO /* informational */ 00044 #define APLOG_DEBUG LOG_DEBUG /* debug-level messages */ 00045 00046 #define APLOG_LEVELMASK LOG_PRIMASK /* mask off the level value */ 00047 00048 #else 00049 00050 #define APLOG_EMERG 0 /* system is unusable */ 00051 #define APLOG_ALERT 1 /* action must be taken immediately */ 00052 #define APLOG_CRIT 2 /* critical conditions */ 00053 #define APLOG_ERR 3 /* error conditions */ 00054 #define APLOG_WARNING 4 /* warning conditions */ 00055 #define APLOG_NOTICE 5 /* normal but significant condition */ 00056 #define APLOG_INFO 6 /* informational */ 00057 #define APLOG_DEBUG 7 /* debug-level messages */ 00058 00059 #define APLOG_LEVELMASK 7 /* mask off the level value */ 00060 00061 #endif 00062 00063 /* APLOG_NOERRNO is ignored and should not be used. It will be 00064 * removed in a future release of Apache. 00065 */ 00066 #define APLOG_NOERRNO (APLOG_LEVELMASK + 1) 00067 00068 /* Use APLOG_TOCLIENT on ap_log_rerror() to give content 00069 * handlers the option of including the error text in the 00070 * ErrorDocument sent back to the client. Setting APLOG_TOCLIENT 00071 * will cause the error text to be saved in the request_rec->notes 00072 * table, keyed to the string "error-notes", if and only if: 00073 * - the severity level of the message is APLOG_WARNING or greater 00074 * - there are no other "error-notes" set in request_rec->notes 00075 * Once error-notes is set, it is up to the content handler to 00076 * determine whether this text should be sent back to the client. 00077 * Note: Client generated text streams sent back to the client MUST 00078 * be escaped to prevent CSS attacks. 00079 */ 00080 #define APLOG_TOCLIENT ((APLOG_LEVELMASK + 1) * 2) 00081 00082 /* normal but significant condition on startup, usually printed to stderr */ 00083 #define APLOG_STARTUP ((APLOG_LEVELMASK + 1) * 4) 00084 00085 #ifndef DEFAULT_LOGLEVEL 00086 #define DEFAULT_LOGLEVEL APLOG_WARNING 00087 #endif 00088 00089 extern int AP_DECLARE_DATA ap_default_loglevel; 00090 00091 #define APLOG_MARK __FILE__,__LINE__ 00092 00093 /** 00094 * Set up for logging to stderr. 00095 * @param p The pool to allocate out of 00096 */ 00097 AP_DECLARE(void) ap_open_stderr_log(apr_pool_t *p); 00098 00099 /** 00100 * Replace logging to stderr with logging to the given file. 00101 * @param p The pool to allocate out of 00102 * @param file Name of the file to log stderr output 00103 */ 00104 AP_DECLARE(apr_status_t) ap_replace_stderr_log(apr_pool_t *p, 00105 const char *file); 00106 00107 /** 00108 * Open the error log and replace stderr with it. 00109 * @param pconf Not used 00110 * @param plog The pool to allocate the logs from 00111 * @param ptemp Pool used for temporary allocations 00112 * @param s_main The main server 00113 * @tip ap_open_logs isn't expected to be used by modules, it is 00114 * an internal core function 00115 */ 00116 int ap_open_logs(apr_pool_t *pconf, apr_pool_t *plog, 00117 apr_pool_t *ptemp, server_rec *s_main); 00118 00119 /* 00120 * The three primary logging functions, ap_log_error, ap_log_rerror, and 00121 * ap_log_perror use a printf style format string to build the log message. 00122 * It is VERY IMPORTANT that you not include any raw data from the network, 00123 * such as the request-URI or request header fields, within the format 00124 * string. Doing so makes the server vulnerable to a denial-of-service 00125 * attack and other messy behavior. Instead, use a simple format string 00126 * like "%s", followed by the string containing the untrusted data. 00127 */ 00128 00129 /** 00130 * One of the primary logging routines in Apache. This uses a printf-like 00131 * format to log messages to the error_log. 00132 * @param file The file in which this function is called 00133 * @param line The line number on which this function is called 00134 * @param level The level of this error message 00135 * @param status The status code from the previous command 00136 * @param s The server on which we are logging 00137 * @param fmt The format string 00138 * @param ... The arguments to use to fill out fmt. 00139 * @tip Use APLOG_MARK to fill out file and line 00140 * @warning It is VERY IMPORTANT that you not include any raw data from 00141 * the network, such as the request-URI or request header fields, within 00142 * the format string. Doing so makes the server vulnerable to a 00143 * denial-of-service attack and other messy behavior. Instead, use a 00144 * simple format string like "%s", followed by the string containing the 00145 * untrusted data. 00146 * @deffunc void ap_log_error(const char *file, int line, int level, apr_status_t status, const server_rec *s, const char *fmt, ...) 00147 */ 00148 AP_DECLARE(void) ap_log_error(const char *file, int line, int level, 00149 apr_status_t status, const server_rec *s, 00150 const char *fmt, ...) 00151 __attribute__((format(printf,6,7))); 00152 00153 /** 00154 * The second of the primary logging routines in Apache. This uses 00155 * a printf-like format to log messages to the error_log. 00156 * @param file The file in which this function is called 00157 * @param line The line number on which this function is called 00158 * @param level The level of this error message 00159 * @param status The status code from the previous command 00160 * @param p The pool which we are logging for 00161 * @param fmt The format string 00162 * @param ... The arguments to use to fill out fmt. 00163 * @tip Use APLOG_MARK to fill out file and line 00164 * @warning It is VERY IMPORTANT that you not include any raw data from 00165 * the network, such as the request-URI or request header fields, within 00166 * the format string. Doing so makes the server vulnerable to a 00167 * denial-of-service attack and other messy behavior. Instead, use a 00168 * simple format string like "%s", followed by the string containing the 00169 * untrusted data. 00170 * @deffunc void ap_log_perror(const char *file, int line, int level, apr_status_t status, apr_pool_t *p, const char *fmt, ...) 00171 */ 00172 AP_DECLARE(void) ap_log_perror(const char *file, int line, int level, 00173 apr_status_t status, apr_pool_t *p, 00174 const char *fmt, ...) 00175 __attribute__((format(printf,6,7))); 00176 00177 /** 00178 * The last of the primary logging routines in Apache. This uses 00179 * a printf-like format to log messages to the error_log. 00180 * @param file The file in which this function is called 00181 * @param line The line number on which this function is called 00182 * @param level The level of this error message 00183 * @param status The status code from the previous command 00184 * @param s The request which we are logging for 00185 * @param fmt The format string 00186 * @param ... The arguments to use to fill out fmt. 00187 * @tip Use APLOG_MARK to fill out file and line 00188 * @warning It is VERY IMPORTANT that you not include any raw data from 00189 * the network, such as the request-URI or request header fields, within 00190 * the format string. Doing so makes the server vulnerable to a 00191 * denial-of-service attack and other messy behavior. Instead, use a 00192 * simple format string like "%s", followed by the string containing the 00193 * untrusted data. 00194 * @deffunc void ap_log_rerror(const char *file, int line, int level, apr_status_t status, request_rec *r, const char *fmt, ...) 00195 */ 00196 AP_DECLARE(void) ap_log_rerror(const char *file, int line, int level, 00197 apr_status_t status, const request_rec *r, 00198 const char *fmt, ...) 00199 __attribute__((format(printf,6,7))); 00200 00201 /** 00202 * Convert stderr to the error log 00203 * @param s The current server 00204 * @deffunc void ap_error_log2stderr(server_rec *s) 00205 */ 00206 AP_DECLARE(void) ap_error_log2stderr(server_rec *s); 00207 00208 /** 00209 * Log the current pid of the parent process 00210 * @param p The pool to use for logging 00211 * @param fname The name of the file to log to 00212 */ 00213 AP_DECLARE(void) ap_log_pid(apr_pool_t *p, const char *fname); 00214 00215 /** 00216 * Retrieve the pid from a pidfile. 00217 * @param p The pool to use for logging 00218 * @param filename The name of the file containing the pid 00219 * @param mypid Pointer to pid_t (valid only if return APR_SUCCESS) 00220 */ 00221 AP_DECLARE(apr_status_t) ap_read_pid(apr_pool_t *p, const char *filename, pid_t *mypid); 00222 00223 typedef struct piped_log piped_log; 00224 00225 /** 00226 * The piped logging structure. Piped logs are used to move functionality 00227 * out of the main server. For example, log rotation is done with piped logs. 00228 */ 00229 struct piped_log { 00230 /** The pool to use for the piped log */ 00231 apr_pool_t *p; 00232 /** The pipe between the server and the logging process */ 00233 apr_file_t *fds[2]; 00234 /* XXX - an #ifdef that needs to be eliminated from public view. Shouldn't 00235 * be hard */ 00236 #ifdef AP_HAVE_RELIABLE_PIPED_LOGS 00237 /** The name of the program the logging process is running */ 00238 char *program; 00239 /** The pid of the logging process */ 00240 apr_proc_t *pid; 00241 #endif 00242 }; 00243 00244 /** 00245 * Open the piped log process 00246 * @param p The pool to allocate out of 00247 * @param program The program to run in the logging process 00248 * @return The piped log structure 00249 * @deffunc piped_log *ap_open_piped_log(apr_pool_t *p, const char *program) 00250 */ 00251 AP_DECLARE(piped_log *) ap_open_piped_log(apr_pool_t *p, const char *program); 00252 00253 /** 00254 * Close the piped log and kill the logging process 00255 * @param pl The piped log structure 00256 * @deffunc void ap_close_piped_log(piped_log *pl) 00257 */ 00258 AP_DECLARE(void) ap_close_piped_log(piped_log *pl); 00259 00260 /** 00261 * A macro to access the read side of the piped log pipe 00262 * @param pl The piped log structure 00263 * @return The native file descriptor 00264 * @deffunc ap_piped_log_read_fd(pl) 00265 */ 00266 #define ap_piped_log_read_fd(pl) ((pl)->fds[0]) 00267 00268 /** 00269 * A macro to access the write side of the piped log pipe 00270 * @param pl The piped log structure 00271 * @return The native file descriptor 00272 * @deffunc ap_piped_log_read_fd(pl) 00273 */ 00274 #define ap_piped_log_write_fd(pl) ((pl)->fds[1]) 00275 00276 AP_DECLARE_HOOK(void, error_log, (const char *file, int line, int level, 00277 apr_status_t status, const server_rec *s, 00278 const request_rec *r, apr_pool_t *pool, 00279 const char *errstr)) 00280 00281 #ifdef __cplusplus 00282 } 00283 #endif 00284 00285 #endif /* !APACHE_HTTP_LOG_H */