http_log.inc 14 KB

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