From: Jim Jagielski Date: Fri, 24 Feb 2017 19:39:00 +0000 (+0000) Subject: Support use of optional "tag" in syslog entries. Streamline the patch. X-Git-Tag: 2.5.0-alpha~611 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=215b84c41ec93d77dbe47012bbe342fb6af7b382;p=apache Support use of optional "tag" in syslog entries. Streamline the patch. PR 60525. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1784318 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 52ac3bc847..2affdfb7e8 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,9 @@ -*- coding: utf-8 -*- Changes with Apache 2.5.0 + *) mod_syslog: Support use of optional "tag" in syslog entries. + PR 60525. [Ben Rubson , Jim Jagielski] + *) MPMs unix: Place signals handlers and helpers out of DSOs to avoid a possible crash if a signal is caught during (graceful) restart. PR 60487. [Yann Ylavic] diff --git a/docs/manual/mod/core.xml b/docs/manual/mod/core.xml index b754934df3..c7f83b10af 100644 --- a/docs/manual/mod/core.xml +++ b/docs/manual/mod/core.xml @@ -1538,7 +1538,7 @@ ErrorDocument 404 /cgi-bin/bad_urls.pl ErrorLog Location where the server will log errors - ErrorLog file-path|syslog[:facility] + ErrorLog file-path|syslog[:[facility][:tag]] ErrorLog logs/error_log (Unix) ErrorLog logs/error.log (Windows and OS/2) server configvirtual host @@ -1571,10 +1571,15 @@ ErrorLog "|/usr/local/bin/httpd_errors" syntax where facility can be one of the names usually documented in syslog(1). The facility is effectively global, and if it is changed in individual virtual hosts, the final facility specified affects the - entire server.

+ entire server. Same rules apply for the syslog tag, which by default + uses the Apache binary name, httpd in most cases. You can + also override this by using the syslog::tag + syntax.

ErrorLog syslog:user +ErrorLog syslog:user:httpd.srv1 +ErrorLog syslog::httpd.srv2

Additional modules can provide their own ErrorLog providers. The syntax diff --git a/modules/loggers/mod_syslog.c b/modules/loggers/mod_syslog.c index cc4057315e..5ddce9616b 100644 --- a/modules/loggers/mod_syslog.c +++ b/modules/loggers/mod_syslog.c @@ -113,17 +113,37 @@ static void *syslog_error_log_init(apr_pool_t *p, server_rec *s) openlog(ap_server_argv0, LOG_NDELAY|LOG_CONS|LOG_PID, LOG_LOCAL7); } else { + /* s->error_fname could be [level]:[tag] (see #60525) */ + const char *tag; + apr_size_t flen; const TRANS *fac; - for (fac = facilities; fac->t_name; fac++) { - if (!strcasecmp(fname, fac->t_name)) { - openlog(ap_server_argv0, LOG_NDELAY|LOG_CONS|LOG_PID, - fac->t_val); - return success; + tag = strchr(fname, ':'); + if (tag) { + flen = tag - fname; + tag++; + if (*tag == '\0') { + tag = ap_server_argv0; } + } else { + flen = strlen(fname); + tag = ap_server_argv0; + } + if (flen == 0) { + /* Was something like syslog::foobar */ + openlog(tag, LOG_NDELAY|LOG_CONS|LOG_PID, LOG_LOCAL7); + } else { + for (fac = facilities; fac->t_name; fac++) { + if (!strncasecmp(fname, fac->t_name, flen)) { + openlog(tag, LOG_NDELAY|LOG_CONS|LOG_PID, + fac->t_val); + return success; + } + } + /* Huh? Invalid level name? */ + return NULL; } } - return success; }