Skip to content

Commit

Permalink
mod_log_config: open_multi_logs: Add some warning for undefined log f…
Browse files Browse the repository at this point in the history
…ormat alias and get rid of duplicate code
  • Loading branch information
thomasmey committed Dec 22, 2024
1 parent d77a1fc commit 33c3bb3
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions modules/loggers/mod_log_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1604,51 +1604,46 @@ static int open_multi_logs(server_rec *s, apr_pool_t *p)
int i;
multi_log_state *mls = ap_get_module_config(s->module_config,
&log_config_module);
config_log_state *clsarray;
config_log_state *clsarray = NULL;
int nelts = 0;
const char *dummy;
const char *format;

if (mls->default_format_string) {
/* is the format string an defined alias, like "CLF" */
format = apr_table_get(mls->formats, mls->default_format_string);
if (format) {
mls->default_format = parse_log_string(p, format, &dummy);
}
}

if (!mls->default_format) {
/* TODO: may use "CLF" instead from mls->formats here
* which is added in make_config_log_state
*/
mls->default_format = parse_log_string(p, DEFAULT_LOG_FORMAT, &dummy);
/* no default format set, fallback to CLF as default format string */
ap_log_error(APLOG_MARK, APLOG_INFO, 0, s, "Using CLF as default format for server \"%s\"", s->server_hostname);
mls->default_format_string = "CLF";
format = apr_table_get(mls->formats, mls->default_format_string);
mls->default_format = parse_log_string(p, format, &dummy);
}

if (mls->config_logs->nelts) {
clsarray = (config_log_state *) mls->config_logs->elts;
for (i = 0; i < mls->config_logs->nelts; ++i) {
config_log_state *cls = &clsarray[i];

if (cls->format_string) {
format = apr_table_get(mls->formats, cls->format_string);
if (format) {
cls->format = parse_log_string(p, format, &dummy);
}
}

if (!open_config_log(s, p, cls, mls->default_format)) {
/* Failure already logged by open_config_log */
return DONE;
}
}
nelts = mls->config_logs->nelts;
}
else if (mls->server_config_logs) {
clsarray = (config_log_state *) mls->server_config_logs->elts;
for (i = 0; i < mls->server_config_logs->nelts; ++i) {
nelts = mls->server_config_logs->nelts;
}

if (clsarray && nelts) {
for (i = 0; i < nelts; ++i) {
config_log_state *cls = &clsarray[i];

if (cls->format_string) {
format = apr_table_get(mls->formats, cls->format_string);
if (format) {
cls->format = parse_log_string(p, format, &dummy);
} else {
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, "Unknown log format alias \"%s\" using default \"%s\" instead", cls->format_string, mls->default_format_string);
}
}

Expand Down

0 comments on commit 33c3bb3

Please sign in to comment.