http_log.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  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. * @file http_log.h
  18. * @brief Apache Logging library
  19. *
  20. * @defgroup APACHE_CORE_LOG Logging library
  21. * @ingroup APACHE_CORE
  22. * @{
  23. */
  24. #ifndef APACHE_HTTP_LOG_H
  25. #define APACHE_HTTP_LOG_H
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #include "apr_thread_proc.h"
  30. #include "http_config.h"
  31. #ifdef HAVE_SYSLOG
  32. #include <syslog.h>
  33. #ifndef LOG_PRIMASK
  34. #define LOG_PRIMASK 7
  35. #endif
  36. #define APLOG_EMERG LOG_EMERG /* system is unusable */
  37. #define APLOG_ALERT LOG_ALERT /* action must be taken immediately */
  38. #define APLOG_CRIT LOG_CRIT /* critical conditions */
  39. #define APLOG_ERR LOG_ERR /* error conditions */
  40. #define APLOG_WARNING LOG_WARNING /* warning conditions */
  41. #define APLOG_NOTICE LOG_NOTICE /* normal but significant condition */
  42. #define APLOG_INFO LOG_INFO /* informational */
  43. #define APLOG_DEBUG LOG_DEBUG /* debug-level messages */
  44. #define APLOG_TRACE1 (LOG_DEBUG + 1) /* trace-level 1 messages */
  45. #define APLOG_TRACE2 (LOG_DEBUG + 2) /* trace-level 2 messages */
  46. #define APLOG_TRACE3 (LOG_DEBUG + 3) /* trace-level 3 messages */
  47. #define APLOG_TRACE4 (LOG_DEBUG + 4) /* trace-level 4 messages */
  48. #define APLOG_TRACE5 (LOG_DEBUG + 5) /* trace-level 5 messages */
  49. #define APLOG_TRACE6 (LOG_DEBUG + 6) /* trace-level 6 messages */
  50. #define APLOG_TRACE7 (LOG_DEBUG + 7) /* trace-level 7 messages */
  51. #define APLOG_TRACE8 (LOG_DEBUG + 8) /* trace-level 8 messages */
  52. #define APLOG_LEVELMASK 15 /* mask off the level value */
  53. #else
  54. #define APLOG_EMERG 0 /* system is unusable */
  55. #define APLOG_ALERT 1 /* action must be taken immediately */
  56. #define APLOG_CRIT 2 /* critical conditions */
  57. #define APLOG_ERR 3 /* error conditions */
  58. #define APLOG_WARNING 4 /* warning conditions */
  59. #define APLOG_NOTICE 5 /* normal but significant condition */
  60. #define APLOG_INFO 6 /* informational */
  61. #define APLOG_DEBUG 7 /* debug-level messages */
  62. #define APLOG_TRACE1 8 /* trace-level 1 messages */
  63. #define APLOG_TRACE2 9 /* trace-level 2 messages */
  64. #define APLOG_TRACE3 10 /* trace-level 3 messages */
  65. #define APLOG_TRACE4 11 /* trace-level 4 messages */
  66. #define APLOG_TRACE5 12 /* trace-level 5 messages */
  67. #define APLOG_TRACE6 13 /* trace-level 6 messages */
  68. #define APLOG_TRACE7 14 /* trace-level 7 messages */
  69. #define APLOG_TRACE8 15 /* trace-level 8 messages */
  70. #define APLOG_LEVELMASK 15 /* mask off the level value */
  71. #endif
  72. /* APLOG_NOERRNO is ignored and should not be used. It will be
  73. * removed in a future release of Apache.
  74. */
  75. #define APLOG_NOERRNO (APLOG_LEVELMASK + 1)
  76. /** Use APLOG_TOCLIENT on ap_log_rerror() to give content
  77. * handlers the option of including the error text in the
  78. * ErrorDocument sent back to the client. Setting APLOG_TOCLIENT
  79. * will cause the error text to be saved in the request_rec->notes
  80. * table, keyed to the string "error-notes", if and only if:
  81. * - the severity level of the message is APLOG_WARNING or greater
  82. * - there are no other "error-notes" set in request_rec->notes
  83. * Once error-notes is set, it is up to the content handler to
  84. * determine whether this text should be sent back to the client.
  85. * Note: Client generated text streams sent back to the client MUST
  86. * be escaped to prevent CSS attacks.
  87. */
  88. #define APLOG_TOCLIENT ((APLOG_LEVELMASK + 1) * 2)
  89. /* normal but significant condition on startup, usually printed to stderr */
  90. #define APLOG_STARTUP ((APLOG_LEVELMASK + 1) * 4)
  91. #ifndef DEFAULT_LOGLEVEL
  92. #define DEFAULT_LOGLEVEL APLOG_WARNING
  93. #endif
  94. /**
  95. * APLOGNO() should be used at the start of the format string passed
  96. * to ap_log_error() and friends. The argument must be a 5 digit decimal
  97. * number. It creates a tag of the form "AH02182: "
  98. * See docs/log-message-tags/README for details.
  99. */
  100. #define APLOGNO(n) "AH" #n ": "
  101. /**
  102. * APLOG_NO_MODULE may be passed as module_index to ap_log_error() and related
  103. * functions if the module causing the log message is not known. Normally this
  104. * should not be used directly. Use ::APLOG_MARK or ::APLOG_MODULE_INDEX
  105. * instead.
  106. *
  107. * @see APLOG_MARK
  108. * @see APLOG_MODULE_INDEX
  109. * @see ap_log_error
  110. */
  111. #define APLOG_NO_MODULE -1
  112. #ifdef __cplusplus
  113. /**
  114. * C++ modules must invoke ::APLOG_USE_MODULE or ::AP_DECLARE_MODULE in
  115. * every file which uses ap_log_* before the first use of ::APLOG_MARK
  116. * or ::APLOG_MODULE_INDEX.
  117. * (C modules *should* do that as well, to enable module-specific log
  118. * levels. C modules need not obey the ordering, though).
  119. */
  120. #else /* __cplusplus */
  121. /**
  122. * Constant to store module_index for the current file.
  123. * Objects with static storage duration are set to NULL if not
  124. * initialized explicitly. This means that if aplog_module_index
  125. * is not initialized using the ::APLOG_USE_MODULE or the
  126. * ::AP_DECLARE_MODULE macro, we can safely fall back to
  127. * use ::APLOG_NO_MODULE. This variable will usually be optimized away.
  128. */
  129. static int * const aplog_module_index;
  130. #endif /* __cplusplus */
  131. /**
  132. * APLOG_MODULE_INDEX contains the module_index of the current module if
  133. * it has been set via the ::APLOG_USE_MODULE or ::AP_DECLARE_MODULE macro.
  134. * Otherwise it contains ::APLOG_NO_MODULE (for example in unmodified httpd
  135. * 2.2 modules).
  136. *
  137. * If ::APLOG_MARK is used in ap_log_error() and related functions,
  138. * ::APLOG_MODULE_INDEX will be passed as module_index. In cases where
  139. * ::APLOG_MARK cannot be used, ::APLOG_MODULE_INDEX should normally be passed
  140. * as module_index.
  141. *
  142. * @see APLOG_MARK
  143. * @see ap_log_error
  144. */
  145. #ifdef __cplusplus
  146. #define APLOG_MODULE_INDEX (*aplog_module_index)
  147. #else /* __cplusplus */
  148. #define APLOG_MODULE_INDEX \
  149. (aplog_module_index ? *aplog_module_index : APLOG_NO_MODULE)
  150. #endif /* __cplusplus */
  151. /**
  152. * APLOG_MAX_LOGLEVEL can be defined to remove logging above some
  153. * specified level at compile time.
  154. *
  155. * This requires a C99 compiler.
  156. */
  157. #ifdef DOXYGEN
  158. #define APLOG_MAX_LOGLEVEL
  159. #endif
  160. #ifndef APLOG_MAX_LOGLEVEL
  161. #define APLOG_MODULE_IS_LEVEL(s,module_index,level) \
  162. ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) || \
  163. (s == NULL) || \
  164. (ap_get_server_module_loglevel(s, module_index) \
  165. >= ((level)&APLOG_LEVELMASK) ) )
  166. #define APLOG_C_MODULE_IS_LEVEL(c,module_index,level) \
  167. ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) || \
  168. (ap_get_conn_module_loglevel(c, module_index) \
  169. >= ((level)&APLOG_LEVELMASK) ) )
  170. #define APLOG_CS_MODULE_IS_LEVEL(c,s,module_index,level) \
  171. ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) || \
  172. (ap_get_conn_server_module_loglevel(c, s, module_index) \
  173. >= ((level)&APLOG_LEVELMASK) ) )
  174. #define APLOG_R_MODULE_IS_LEVEL(r,module_index,level) \
  175. ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) || \
  176. (ap_get_request_module_loglevel(r, module_index) \
  177. >= ((level)&APLOG_LEVELMASK) ) )
  178. #else
  179. #define APLOG_MODULE_IS_LEVEL(s,module_index,level) \
  180. ( (((level)&APLOG_LEVELMASK) <= APLOG_MAX_LOGLEVEL) && \
  181. ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) || \
  182. (s == NULL) || \
  183. (ap_get_server_module_loglevel(s, module_index) \
  184. >= ((level)&APLOG_LEVELMASK) ) ) )
  185. #define APLOG_CS_MODULE_IS_LEVEL(c,s,module_index,level) \
  186. ( (((level)&APLOG_LEVELMASK) <= APLOG_MAX_LOGLEVEL) && \
  187. ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) || \
  188. (ap_get_conn_server_module_loglevel(c, s, module_index) \
  189. >= ((level)&APLOG_LEVELMASK) ) ) )
  190. #define APLOG_C_MODULE_IS_LEVEL(c,module_index,level) \
  191. ( (((level)&APLOG_LEVELMASK) <= APLOG_MAX_LOGLEVEL) && \
  192. ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) || \
  193. (ap_get_conn_module_loglevel(c, module_index) \
  194. >= ((level)&APLOG_LEVELMASK) ) ) )
  195. #define APLOG_R_MODULE_IS_LEVEL(r,module_index,level) \
  196. ( (((level)&APLOG_LEVELMASK) <= APLOG_MAX_LOGLEVEL) && \
  197. ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) || \
  198. (ap_get_request_module_loglevel(r, module_index) \
  199. >= ((level)&APLOG_LEVELMASK) ) ) )
  200. #endif
  201. #define APLOG_IS_LEVEL(s,level) \
  202. APLOG_MODULE_IS_LEVEL(s,APLOG_MODULE_INDEX,level)
  203. #define APLOG_C_IS_LEVEL(c,level) \
  204. APLOG_C_MODULE_IS_LEVEL(c,APLOG_MODULE_INDEX,level)
  205. #define APLOG_CS_IS_LEVEL(c,s,level) \
  206. APLOG_CS_MODULE_IS_LEVEL(c,s,APLOG_MODULE_INDEX,level)
  207. #define APLOG_R_IS_LEVEL(r,level) \
  208. APLOG_R_MODULE_IS_LEVEL(r,APLOG_MODULE_INDEX,level)
  209. #define APLOGinfo(s) APLOG_IS_LEVEL(s,APLOG_INFO)
  210. #define APLOGdebug(s) APLOG_IS_LEVEL(s,APLOG_DEBUG)
  211. #define APLOGtrace1(s) APLOG_IS_LEVEL(s,APLOG_TRACE1)
  212. #define APLOGtrace2(s) APLOG_IS_LEVEL(s,APLOG_TRACE2)
  213. #define APLOGtrace3(s) APLOG_IS_LEVEL(s,APLOG_TRACE3)
  214. #define APLOGtrace4(s) APLOG_IS_LEVEL(s,APLOG_TRACE4)
  215. #define APLOGtrace5(s) APLOG_IS_LEVEL(s,APLOG_TRACE5)
  216. #define APLOGtrace6(s) APLOG_IS_LEVEL(s,APLOG_TRACE6)
  217. #define APLOGtrace7(s) APLOG_IS_LEVEL(s,APLOG_TRACE7)
  218. #define APLOGtrace8(s) APLOG_IS_LEVEL(s,APLOG_TRACE8)
  219. #define APLOGrinfo(r) APLOG_R_IS_LEVEL(r,APLOG_INFO)
  220. #define APLOGrdebug(r) APLOG_R_IS_LEVEL(r,APLOG_DEBUG)
  221. #define APLOGrtrace1(r) APLOG_R_IS_LEVEL(r,APLOG_TRACE1)
  222. #define APLOGrtrace2(r) APLOG_R_IS_LEVEL(r,APLOG_TRACE2)
  223. #define APLOGrtrace3(r) APLOG_R_IS_LEVEL(r,APLOG_TRACE3)
  224. #define APLOGrtrace4(r) APLOG_R_IS_LEVEL(r,APLOG_TRACE4)
  225. #define APLOGrtrace5(r) APLOG_R_IS_LEVEL(r,APLOG_TRACE5)
  226. #define APLOGrtrace6(r) APLOG_R_IS_LEVEL(r,APLOG_TRACE6)
  227. #define APLOGrtrace7(r) APLOG_R_IS_LEVEL(r,APLOG_TRACE7)
  228. #define APLOGrtrace8(r) APLOG_R_IS_LEVEL(r,APLOG_TRACE8)
  229. #define APLOGcinfo(c) APLOG_C_IS_LEVEL(c,APLOG_INFO)
  230. #define APLOGcdebug(c) APLOG_C_IS_LEVEL(c,APLOG_DEBUG)
  231. #define APLOGctrace1(c) APLOG_C_IS_LEVEL(c,APLOG_TRACE1)
  232. #define APLOGctrace2(c) APLOG_C_IS_LEVEL(c,APLOG_TRACE2)
  233. #define APLOGctrace3(c) APLOG_C_IS_LEVEL(c,APLOG_TRACE3)
  234. #define APLOGctrace4(c) APLOG_C_IS_LEVEL(c,APLOG_TRACE4)
  235. #define APLOGctrace5(c) APLOG_C_IS_LEVEL(c,APLOG_TRACE5)
  236. #define APLOGctrace6(c) APLOG_C_IS_LEVEL(c,APLOG_TRACE6)
  237. #define APLOGctrace7(c) APLOG_C_IS_LEVEL(c,APLOG_TRACE7)
  238. #define APLOGctrace8(c) APLOG_C_IS_LEVEL(c,APLOG_TRACE8)
  239. AP_DECLARE_DATA extern int ap_default_loglevel;
  240. /**
  241. * APLOG_MARK is a convenience macro for use as the first three parameters in
  242. * ap_log_error() and related functions, i.e. file, line, and module_index.
  243. *
  244. * The module_index parameter was introduced in version 2.3.6. Before that
  245. * version, APLOG_MARK only replaced the file and line parameters.
  246. * This means that APLOG_MARK can be used with ap_log_*error in all versions
  247. * of Apache httpd.
  248. *
  249. * @see APLOG_MODULE_INDEX
  250. * @see ap_log_error
  251. * @see ap_log_cerror
  252. * @see ap_log_rerror
  253. * @see ap_log_cserror
  254. */
  255. #define APLOG_MARK __FILE__,__LINE__,APLOG_MODULE_INDEX
  256. /**
  257. * Set up for logging to stderr.
  258. * @param p The pool to allocate out of
  259. */
  260. AP_DECLARE(void) ap_open_stderr_log(apr_pool_t *p);
  261. /**
  262. * Replace logging to stderr with logging to the given file.
  263. * @param p The pool to allocate out of
  264. * @param file Name of the file to log stderr output
  265. */
  266. AP_DECLARE(apr_status_t) ap_replace_stderr_log(apr_pool_t *p,
  267. const char *file);
  268. /**
  269. * Open the error log and replace stderr with it.
  270. * @param pconf Not used
  271. * @param plog The pool to allocate the logs from
  272. * @param ptemp Pool used for temporary allocations
  273. * @param s_main The main server
  274. * @note ap_open_logs isn't expected to be used by modules, it is
  275. * an internal core function
  276. */
  277. int ap_open_logs(apr_pool_t *pconf, apr_pool_t *plog,
  278. apr_pool_t *ptemp, server_rec *s_main);
  279. /**
  280. * Perform special processing for piped loggers in MPM child
  281. * processes.
  282. * @param p Not used
  283. * @param s Not used
  284. * @note ap_logs_child_init is not for use by modules; it is an
  285. * internal core function
  286. */
  287. void ap_logs_child_init(apr_pool_t *p, server_rec *s);
  288. /*
  289. * The primary logging functions, ap_log_error, ap_log_rerror, ap_log_cerror,
  290. * and ap_log_perror use a printf style format string to build the log message.
  291. * It is VERY IMPORTANT that you not include any raw data from the network,
  292. * such as the request-URI or request header fields, within the format
  293. * string. Doing so makes the server vulnerable to a denial-of-service
  294. * attack and other messy behavior. Instead, use a simple format string
  295. * like "%s", followed by the string containing the untrusted data.
  296. */
  297. /**
  298. * ap_log_error() - log messages which are not related to a particular
  299. * request or connection. This uses a printf-like format to log messages
  300. * to the error_log.
  301. * @param file The file in which this function is called
  302. * @param line The line number on which this function is called
  303. * @param module_index The module_index of the module generating this message
  304. * @param level The level of this error message
  305. * @param status The status code from the previous command
  306. * @param s The server on which we are logging
  307. * @param fmt The format string
  308. * @param ... The arguments to use to fill out fmt.
  309. * @note ap_log_error is implemented as a macro
  310. * @note Use APLOG_MARK to fill out file and line
  311. * @note If a request_rec is available, use that with ap_log_rerror()
  312. * in preference to calling this function. Otherwise, if a conn_rec is
  313. * available, use that with ap_log_cerror() in preference to calling
  314. * this function.
  315. * @warning It is VERY IMPORTANT that you not include any raw data from
  316. * the network, such as the request-URI or request header fields, within
  317. * the format string. Doing so makes the server vulnerable to a
  318. * denial-of-service attack and other messy behavior. Instead, use a
  319. * simple format string like "%s", followed by the string containing the
  320. * untrusted data.
  321. */
  322. #ifdef DOXYGEN
  323. AP_DECLARE(void) ap_log_error(const char *file, int line, int module_index,
  324. int level, apr_status_t status,
  325. const server_rec *s, const char *fmt, ...);
  326. #else
  327. #ifdef AP_HAVE_C99
  328. /* need additional step to expand APLOG_MARK first */
  329. #define ap_log_error(...) ap_log_error__(__VA_ARGS__)
  330. /* need server_rec *sr = ... for the case if s is verbatim NULL */
  331. #define ap_log_error__(file, line, mi, level, status, s, ...) \
  332. do { const server_rec *sr__ = s; if (APLOG_MODULE_IS_LEVEL(sr__, mi, level)) \
  333. ap_log_error_(file, line, mi, level, status, sr__, __VA_ARGS__); \
  334. } while(0)
  335. #else
  336. #define ap_log_error ap_log_error_
  337. #endif
  338. AP_DECLARE(void) ap_log_error_(const char *file, int line, int module_index,
  339. int level, apr_status_t status,
  340. const server_rec *s, const char *fmt, ...)
  341. __attribute__((format(printf,7,8)));
  342. #endif
  343. /**
  344. * ap_log_perror() - log messages which are not related to a particular
  345. * request, connection, or virtual server. This uses a printf-like
  346. * format to log messages to the error_log.
  347. * @param file The file in which this function is called
  348. * @param line The line number on which this function is called
  349. * @param module_index ignored dummy value for use by APLOG_MARK
  350. * @param level The level of this error message
  351. * @param status The status code from the previous command
  352. * @param p The pool which we are logging for
  353. * @param fmt The format string
  354. * @param ... The arguments to use to fill out fmt.
  355. * @note ap_log_perror is implemented as a macro
  356. * @note Use APLOG_MARK to fill out file, line, and module_index
  357. * @warning It is VERY IMPORTANT that you not include any raw data from
  358. * the network, such as the request-URI or request header fields, within
  359. * the format string. Doing so makes the server vulnerable to a
  360. * denial-of-service attack and other messy behavior. Instead, use a
  361. * simple format string like "%s", followed by the string containing the
  362. * untrusted data.
  363. */
  364. #ifdef DOXYGEN
  365. AP_DECLARE(void) ap_log_perror(const char *file, int line, int module_index,
  366. int level, apr_status_t status, apr_pool_t *p,
  367. const char *fmt, ...);
  368. #else
  369. #if defined(AP_HAVE_C99) && defined(APLOG_MAX_LOGLEVEL)
  370. /* need additional step to expand APLOG_MARK first */
  371. #define ap_log_perror(...) ap_log_perror__(__VA_ARGS__)
  372. #define ap_log_perror__(file, line, mi, level, status, p, ...) \
  373. do { if ((level) <= APLOG_MAX_LOGLEVEL ) \
  374. ap_log_perror_(file, line, mi, level, status, p, \
  375. __VA_ARGS__); } while(0)
  376. #else
  377. #define ap_log_perror ap_log_perror_
  378. #endif
  379. AP_DECLARE(void) ap_log_perror_(const char *file, int line, int module_index,
  380. int level, apr_status_t status, apr_pool_t *p,
  381. const char *fmt, ...)
  382. __attribute__((format(printf,7,8)));
  383. #endif
  384. /**
  385. * ap_log_rerror() - log messages which are related to a particular
  386. * request. This uses a printf-like format to log messages to the
  387. * error_log.
  388. * @param file The file in which this function is called
  389. * @param line The line number on which this function is called
  390. * @param module_index The module_index of the module generating this message
  391. * @param level The level of this error message
  392. * @param status The status code from the previous command
  393. * @param r The request which we are logging for
  394. * @param fmt The format string
  395. * @param ... The arguments to use to fill out fmt.
  396. * @note ap_log_rerror is implemented as a macro
  397. * @note Use APLOG_MARK to fill out file, line, and module_index
  398. * @warning It is VERY IMPORTANT that you not include any raw data from
  399. * the network, such as the request-URI or request header fields, within
  400. * the format string. Doing so makes the server vulnerable to a
  401. * denial-of-service attack and other messy behavior. Instead, use a
  402. * simple format string like "%s", followed by the string containing the
  403. * untrusted data.
  404. */
  405. #ifdef DOXYGEN
  406. AP_DECLARE(void) ap_log_rerror(const char *file, int line, int module_index,
  407. int level, apr_status_t status,
  408. const request_rec *r, const char *fmt, ...);
  409. #else
  410. #ifdef AP_HAVE_C99
  411. /* need additional step to expand APLOG_MARK first */
  412. #define ap_log_rerror(...) ap_log_rerror__(__VA_ARGS__)
  413. #define ap_log_rerror__(file, line, mi, level, status, r, ...) \
  414. do { if (APLOG_R_MODULE_IS_LEVEL(r, mi, level)) \
  415. ap_log_rerror_(file, line, mi, level, status, r, __VA_ARGS__); \
  416. } while(0)
  417. #else
  418. #define ap_log_rerror ap_log_rerror_
  419. #endif
  420. AP_DECLARE(void) ap_log_rerror_(const char *file, int line, int module_index,
  421. int level, apr_status_t status,
  422. const request_rec *r, const char *fmt, ...)
  423. __attribute__((format(printf,7,8)));
  424. #endif
  425. /**
  426. * ap_log_cerror() - log messages which are related to a particular
  427. * connection. This uses a printf-like format to log messages to the
  428. * error_log.
  429. * @param file The file in which this function is called
  430. * @param line The line number on which this function is called
  431. * @param level The level of this error message
  432. * @param module_index The module_index of the module generating this message
  433. * @param status The status code from the previous command
  434. * @param c The connection which we are logging for
  435. * @param fmt The format string
  436. * @param ... The arguments to use to fill out fmt.
  437. * @note ap_log_cerror is implemented as a macro
  438. * @note Use APLOG_MARK to fill out file, line, and module_index
  439. * @note If a request_rec is available, use that with ap_log_rerror()
  440. * in preference to calling this function.
  441. * @warning It is VERY IMPORTANT that you not include any raw data from
  442. * the network, such as the request-URI or request header fields, within
  443. * the format string. Doing so makes the server vulnerable to a
  444. * denial-of-service attack and other messy behavior. Instead, use a
  445. * simple format string like "%s", followed by the string containing the
  446. * untrusted data.
  447. */
  448. #ifdef DOXYGEN
  449. AP_DECLARE(void) ap_log_cerror(const char *file, int line, int module_index,
  450. int level, apr_status_t status,
  451. const conn_rec *c, const char *fmt, ...);
  452. #else
  453. #ifdef AP_HAVE_C99
  454. /* need additional step to expand APLOG_MARK first */
  455. #define ap_log_cerror(...) ap_log_cerror__(__VA_ARGS__)
  456. #define ap_log_cerror__(file, line, mi, level, status, c, ...) \
  457. do { if (APLOG_C_MODULE_IS_LEVEL(c, mi, level)) \
  458. ap_log_cerror_(file, line, mi, level, status, c, __VA_ARGS__); \
  459. } while(0)
  460. #else
  461. #define ap_log_cerror ap_log_cerror_
  462. #endif
  463. AP_DECLARE(void) ap_log_cerror_(const char *file, int line, int module_index,
  464. int level, apr_status_t status,
  465. const conn_rec *c, const char *fmt, ...)
  466. __attribute__((format(printf,7,8)));
  467. #endif
  468. /**
  469. * ap_log_cserror() - log messages which are related to a particular
  470. * connection and to a vhost other than c->base_server. This uses a
  471. * printf-like format to log messages to the error_log.
  472. * @param file The file in which this function is called
  473. * @param line The line number on which this function is called
  474. * @param level The level of this error message
  475. * @param module_index The module_index of the module generating this message
  476. * @param status The status code from the previous command
  477. * @param c The connection which we are logging for
  478. * @param s The server which we are logging for
  479. * @param fmt The format string
  480. * @param ... The arguments to use to fill out fmt.
  481. * @note ap_log_cserror is implemented as a macro
  482. * @note Use APLOG_MARK to fill out file, line, and module_index
  483. * @note If a request_rec is available, use that with ap_log_rerror()
  484. * in preference to calling this function. This function is mainly useful for
  485. * modules like mod_ssl to use before the request_rec is created.
  486. * @warning It is VERY IMPORTANT that you not include any raw data from
  487. * the network, such as the request-URI or request header fields, within
  488. * the format string. Doing so makes the server vulnerable to a
  489. * denial-of-service attack and other messy behavior. Instead, use a
  490. * simple format string like "%s", followed by the string containing the
  491. * untrusted data.
  492. */
  493. #ifdef DOXYGEN
  494. AP_DECLARE(void) ap_log_cserror(const char *file, int line, int module_index,
  495. int level, apr_status_t status,
  496. const conn_rec *c, const server_rec *s,
  497. const char *fmt, ...);
  498. #else
  499. #ifdef AP_HAVE_C99
  500. /* need additional step to expand APLOG_MARK first */
  501. #define ap_log_cserror(...) ap_log_cserror__(__VA_ARGS__)
  502. #define ap_log_cserror__(file, line, mi, level, status, c, s, ...) \
  503. do { if (APLOG_CS_MODULE_IS_LEVEL(c, s, mi, level)) \
  504. ap_log_cserror_(file, line, mi, level, status, c, s, \
  505. __VA_ARGS__); \
  506. } while(0)
  507. #else
  508. #define ap_log_cserror ap_log_cserror_
  509. #endif
  510. AP_DECLARE(void) ap_log_cserror_(const char *file, int line, int module_index,
  511. int level, apr_status_t status,
  512. const conn_rec *c, const server_rec *s,
  513. const char *fmt, ...)
  514. __attribute__((format(printf,8,9)));
  515. #endif
  516. /*
  517. * The buffer logging functions, ap_log_data, ap_log_rdata, ap_log_cdata,
  518. * and ap_log_csdata log a buffer in printable and hex format. The exact
  519. * format is controlled by processing flags, described next.
  520. */
  521. /**
  522. * Processing flags for ap_log_data() et al
  523. *
  524. * AP_LOG_DATA_DEFAULT - default formatting, with printable chars and hex
  525. * AP_LOG_DATA_SHOW_OFFSET - prefix each line with hex offset from the start
  526. * of the buffer
  527. */
  528. #define AP_LOG_DATA_DEFAULT 0
  529. #define AP_LOG_DATA_SHOW_OFFSET 1
  530. /**
  531. * ap_log_data() - log buffers which are not related to a particular request
  532. * or connection.
  533. * @param file The file in which this function is called
  534. * @param line The line number on which this function is called
  535. * @param module_index The module_index of the module logging this buffer
  536. * @param level The log level
  537. * @param s The server on which we are logging
  538. * @param label A label for the buffer, to be logged preceding the buffer
  539. * @param data The buffer to be logged
  540. * @param len The length of the buffer
  541. * @param flags Special processing flags like AP_LOG_DATA_SHOW_OFFSET
  542. * @note ap_log_data is implemented as a macro.
  543. * @note Use APLOG_MARK to fill out file, line, and module_index
  544. * @note If a request_rec is available, use that with ap_log_rdata()
  545. * in preference to calling this function. Otherwise, if a conn_rec is
  546. * available, use that with ap_log_cdata() in preference to calling
  547. * this function.
  548. */
  549. #ifdef DOXYGEN
  550. AP_DECLARE(void) ap_log_data(const char *file, int line, int module_index,
  551. int level, const server_rec *s, const char *label,
  552. const void *data, apr_size_t len, unsigned int flags);
  553. #else
  554. #ifdef AP_HAVE_C99
  555. /* need additional step to expand APLOG_MARK first */
  556. #define ap_log_data(...) ap_log_data__(__VA_ARGS__)
  557. /* need server_rec *sr = ... for the case if s is verbatim NULL */
  558. #define ap_log_data__(file, line, mi, level, s, ...) \
  559. do { const server_rec *sr__ = s; if (APLOG_MODULE_IS_LEVEL(sr__, mi, level)) \
  560. ap_log_data_(file, line, mi, level, sr__, __VA_ARGS__); \
  561. } while(0)
  562. #else
  563. #define ap_log_data ap_log_data_
  564. #endif
  565. AP_DECLARE(void) ap_log_data_(const char *file, int line, int module_index,
  566. int level, const server_rec *s, const char *label,
  567. const void *data, apr_size_t len, unsigned int flags);
  568. #endif
  569. /**
  570. * ap_log_rdata() - log buffers which are related to a particular request.
  571. * @param file The file in which this function is called
  572. * @param line The line number on which this function is called
  573. * @param module_index The module_index of the module logging this buffer
  574. * @param level The log level
  575. * @param r The request which we are logging for
  576. * @param label A label for the buffer, to be logged preceding the buffer
  577. * @param data The buffer to be logged
  578. * @param len The length of the buffer
  579. * @param flags Special processing flags like AP_LOG_DATA_SHOW_OFFSET
  580. * @note ap_log_rdata is implemented as a macro.
  581. * @note Use APLOG_MARK to fill out file, line, and module_index
  582. * @note If a request_rec is available, use that with ap_log_rerror()
  583. * in preference to calling this function. Otherwise, if a conn_rec is
  584. * available, use that with ap_log_cerror() in preference to calling
  585. * this function.
  586. */
  587. #ifdef DOXYGEN
  588. AP_DECLARE(void) ap_log_rdata(const char *file, int line, int module_index,
  589. int level, const request_rec *r, const char *label,
  590. const void *data, apr_size_t len, unsigned int flags);
  591. #else
  592. #ifdef AP_HAVE_C99
  593. /* need additional step to expand APLOG_MARK first */
  594. #define ap_log_rdata(...) ap_log_rdata__(__VA_ARGS__)
  595. #define ap_log_rdata__(file, line, mi, level, r, ...) \
  596. do { if (APLOG_R_MODULE_IS_LEVEL(r, mi, level)) \
  597. ap_log_rdata_(file, line, mi, level, r, __VA_ARGS__); \
  598. } while(0)
  599. #else
  600. #define ap_log_rdata ap_log_rdata_
  601. #endif
  602. AP_DECLARE(void) ap_log_rdata_(const char *file, int line, int module_index,
  603. int level, const request_rec *r, const char *label,
  604. const void *data, apr_size_t len, unsigned int flags);
  605. #endif
  606. /**
  607. * ap_log_cdata() - log buffers which are related to a particular connection.
  608. * @param file The file in which this function is called
  609. * @param line The line number on which this function is called
  610. * @param module_index The module_index of the module logging this buffer
  611. * @param level The log level
  612. * @param c The connection which we are logging for
  613. * @param label A label for the buffer, to be logged preceding the buffer
  614. * @param data The buffer to be logged
  615. * @param len The length of the buffer
  616. * @param flags Special processing flags like AP_LOG_DATA_SHOW_OFFSET
  617. * @note ap_log_cdata is implemented as a macro
  618. * @note Use APLOG_MARK to fill out file, line, and module_index
  619. * @note If a request_rec is available, use that with ap_log_rerror()
  620. * in preference to calling this function. Otherwise, if a conn_rec is
  621. * available, use that with ap_log_cerror() in preference to calling
  622. * this function.
  623. */
  624. #ifdef DOXYGEN
  625. AP_DECLARE(void) ap_log_cdata(const char *file, int line, int module_index,
  626. int level, const conn_rec *c, const char *label,
  627. const void *data, apr_size_t len, unsigned int flags);
  628. #else
  629. #ifdef AP_HAVE_C99
  630. /* need additional step to expand APLOG_MARK first */
  631. #define ap_log_cdata(...) ap_log_cdata__(__VA_ARGS__)
  632. #define ap_log_cdata__(file, line, mi, level, c, ...) \
  633. do { if (APLOG_C_MODULE_IS_LEVEL(c, mi, level)) \
  634. ap_log_cdata_(file, line, mi, level, c, __VA_ARGS__); \
  635. } while(0)
  636. #else
  637. #define ap_log_cdata ap_log_cdata_
  638. #endif
  639. AP_DECLARE(void) ap_log_cdata_(const char *file, int line, int module_index,
  640. int level, const conn_rec *c, const char *label,
  641. const void *data, apr_size_t len, unsigned int flags);
  642. #endif
  643. /**
  644. * ap_log_csdata() - log buffers which are related to a particular connection
  645. * and to a vhost other than c->base_server.
  646. * @param file The file in which this function is called
  647. * @param line The line number on which this function is called
  648. * @param module_index The module_index of the module logging this buffer
  649. * @param level The log level
  650. * @param c The connection which we are logging for
  651. * @param s The server which we are logging for
  652. * @param label A label for the buffer, to be logged preceding the buffer
  653. * @param data The buffer to be logged
  654. * @param len The length of the buffer
  655. * @param flags Special processing flags like AP_LOG_DATA_SHOW_OFFSET
  656. * @note ap_log_csdata is implemented as a macro
  657. * @note Use APLOG_MARK to fill out file, line, and module_index
  658. * @note If a request_rec is available, use that with ap_log_rerror()
  659. * in preference to calling this function. Otherwise, if a conn_rec is
  660. * available, use that with ap_log_cerror() in preference to calling
  661. * this function.
  662. */
  663. #ifdef DOXYGEN
  664. AP_DECLARE(void) ap_log_csdata(const char *file, int line, int module_index,
  665. int level, const conn_rec *c, const server_rec *s,
  666. const char *label, const void *data,
  667. apr_size_t len, unsigned int flags);
  668. #else
  669. #ifdef AP_HAVE_C99
  670. /* need additional step to expand APLOG_MARK first */
  671. #define ap_log_csdata(...) ap_log_csdata__(__VA_ARGS__)
  672. #define ap_log_csdata__(file, line, mi, level, c, s, ...) \
  673. do { if (APLOG_CS_MODULE_IS_LEVEL(c, s, mi, level)) \
  674. ap_log_csdata_(file, line, mi, level, c, s, __VA_ARGS__); \
  675. } while(0)
  676. #else
  677. #define ap_log_cdata ap_log_cdata_
  678. #endif
  679. AP_DECLARE(void) ap_log_csdata_(const char *file, int line, int module_index,
  680. int level, const conn_rec *c, const server_rec *s,
  681. const char *label, const void *data,
  682. apr_size_t len, unsigned int flags);
  683. #endif
  684. /**
  685. * Convert stderr to the error log
  686. * @param s The current server
  687. */
  688. AP_DECLARE(void) ap_error_log2stderr(server_rec *s);
  689. /**
  690. * Log the command line used to start the server.
  691. * @param p The pool to use for logging
  692. * @param s The server_rec whose process's command line we want to log.
  693. * The command line is logged to that server's error log.
  694. */
  695. AP_DECLARE(void) ap_log_command_line(apr_pool_t *p, server_rec *s);
  696. /**
  697. * Log common (various) MPM shared data at startup.
  698. * @param s The server_rec of the error log we want to log to.
  699. * Misc commonly logged data is logged to that server's error log.
  700. */
  701. AP_DECLARE(void) ap_log_mpm_common(server_rec *s);
  702. /**
  703. * Log the current pid of the parent process
  704. * @param p The pool to use for processing
  705. * @param fname The name of the file to log to. If the filename is not
  706. * absolute then it is assumed to be relative to ServerRoot.
  707. */
  708. AP_DECLARE(void) ap_log_pid(apr_pool_t *p, const char *fname);
  709. /**
  710. * Remove the pidfile.
  711. * @param p The pool to use for processing
  712. * @param fname The name of the pid file to remove. If the filename is not
  713. * absolute then it is assumed to be relative to ServerRoot.
  714. */
  715. AP_DECLARE(void) ap_remove_pid(apr_pool_t *p, const char *fname);
  716. /**
  717. * Retrieve the pid from a pidfile.
  718. * @param p The pool to use for processing
  719. * @param filename The name of the file containing the pid. If the filename is not
  720. * absolute then it is assumed to be relative to ServerRoot.
  721. * @param mypid Pointer to pid_t (valid only if return APR_SUCCESS)
  722. */
  723. AP_DECLARE(apr_status_t) ap_read_pid(apr_pool_t *p, const char *filename, pid_t *mypid);
  724. /** @see piped_log */
  725. typedef struct piped_log piped_log;
  726. /**
  727. * Open the piped log process
  728. * @param p The pool to allocate out of
  729. * @param program The program to run in the logging process
  730. * @return The piped log structure
  731. * @note The log program is invoked as @p APR_PROGRAM_ENV,
  732. * @see ap_open_piped_log_ex to modify this behavior
  733. */
  734. AP_DECLARE(piped_log *) ap_open_piped_log(apr_pool_t *p, const char *program);
  735. /**
  736. * Open the piped log process specifying the execution choice for program
  737. * @param p The pool to allocate out of
  738. * @param program The program to run in the logging process
  739. * @param cmdtype How to invoke program, e.g. APR_PROGRAM, APR_SHELLCMD_ENV, etc
  740. * @return The piped log structure
  741. */
  742. AP_DECLARE(piped_log *) ap_open_piped_log_ex(apr_pool_t *p,
  743. const char *program,
  744. apr_cmdtype_e cmdtype);
  745. /**
  746. * Close the piped log and kill the logging process
  747. * @param pl The piped log structure
  748. */
  749. AP_DECLARE(void) ap_close_piped_log(piped_log *pl);
  750. /**
  751. * A function to return the read side of the piped log pipe
  752. * @param pl The piped log structure
  753. * @return The native file descriptor
  754. */
  755. AP_DECLARE(apr_file_t *) ap_piped_log_read_fd(piped_log *pl);
  756. /**
  757. * A function to return the write side of the piped log pipe
  758. * @param pl The piped log structure
  759. * @return The native file descriptor
  760. */
  761. AP_DECLARE(apr_file_t *) ap_piped_log_write_fd(piped_log *pl);
  762. /**
  763. * hook method to generate unique id for connection or request
  764. * @ingroup hooks
  765. * @param c the conn_rec of the connections
  766. * @param r the request_req (may be NULL)
  767. * @param id the place where to store the unique id
  768. * @return OK or DECLINE
  769. */
  770. AP_DECLARE_HOOK(int, generate_log_id,
  771. (const conn_rec *c, const request_rec *r, const char **id))
  772. #ifdef __cplusplus
  773. }
  774. #endif
  775. #endif /* !APACHE_HTTP_LOG_H */
  776. /** @} */