问题
I have an apache module that logs some lines. If I log with ap_log_error
and have set LogLevel
to debug I see the message. However, if I try to use ap_log_perror I can see error-level logs but the debug logs don't show up. It seems as if the two are at a different level, but I can't figure out how to set the pool's level (or get it for that matter).
I see there's a call ap_get_server_module_loglevel
but I'm not sure what the right index is. Trying 0 I see the level I set in the apache.conf toplevel (trace1 in this case). There are no virtual hosts with log levels configured. Every pool I have access to appears to behave in the same way.
static int foo_setup_handler(apr_pool_t *pconf,
apr_pool_t *plog,
apr_pool_t *ptemp,
server_rec *s) {
int mod_log = ap_get_server_module_loglevel(s, 0);
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
"Post Config server mod 0 loglevel %d",
mod_log);
ap_log_perror(APLOG_MARK, APLOG_ERR, APR_SUCCESS, pconf,
" P E++++++++++++++++");
ap_log_perror(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, pconf,
"P D conf ++++++++++++++++");
ap_log_perror(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, plog,
"P D log ++++++++++++++++");
ap_log_perror(APLOG_MARK, APLOG_WARNING, APR_SUCCESS, plog,
"P W log ++++++++++++++++");
ap_log_perror(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, ptemp,
"P D temp++++++++++++++++");
and here's the output in the error log. (I removed the date and thread id from the line below)
... [:debug] [pid 2..:tid 1...] mod_foo.c(123): Post Config server mod 0 loglevel 8
... [:error] [pid 2..:tid 1...] P E++++++++++++++++
... [:warn] [pid 2..:tid 1...] P W log ++++++++++++++++
any ideas why perror log messages are not showing up at the configured level but do show up at the WARNING or ERROR level?
回答1:
This is a bug? in Apache. See this bug report.
Basically, ap_log_perror
calls log_error_core
with const server_rec *s
set to NULL, and that runs afoul of the logic here:
if (s == NULL) {
/*
* If we are doing stderr logging (startup), don't log messages that are
* above the default server log level unless it is a startup/shutdown
* notice
*/
#ifndef DEBUG
if ((level_and_mask != APLOG_NOTICE)
&& (level_and_mask > ap_default_loglevel)) {
return;
}
#endif
So ap_log_perror will only ever show Notices, or messages above the default level (which is normally Warning)
来源:https://stackoverflow.com/questions/52724041/apache-modules-ap-log-perror-is-at-a-different-level-than-ap-log-error