From: Jan Kaluža Date: Mon, 23 Sep 2013 14:16:17 +0000 (+0000) Subject: mod_syslog: New module implementing syslog ap_error_log provider. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9117bb2f5e4dcf6ff46692c6180ca7249f338946;p=thirdparty%2Fapache%2Fhttpd.git mod_syslog: New module implementing syslog ap_error_log provider. Previously, this code was part of core, now it's in separate module. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1525600 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index f27e513044b..89018a0f86a 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,10 @@ -*- coding: utf-8 -*- Changes with Apache 2.5.0 + *) mod_syslog: New module implementing syslog ap_error_log provider. + Previously, this code was part of core, now it's in separate module. + [Jan Kaluza] + *) core: Add ap_errorlog_provider to make ErrorLog logging modular. Move syslog support from core to new mod_syslog. [Jan Kaluza] diff --git a/docs/manual/mod/mod_syslog.xml b/docs/manual/mod/mod_syslog.xml new file mode 100644 index 00000000000..a463ab00d85 --- /dev/null +++ b/docs/manual/mod/mod_syslog.xml @@ -0,0 +1,54 @@ + + + + + + + + + +mod_syslog +Provides "syslog" ErrorLog provider +Extension +mod_syslog.c +syslog_module + + + +

This module provides "syslog" ErrorLog provider. It allows logging + error messages via syslogd(8).

+
+ +
+ Examples + +

Using syslog in ErrorLog directive (see core) + instead of a filename enables logging via syslogd(8) if the system supports it. + The default is to use syslog facility local7, + but you can override this by using the syslog:facility + 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.

+ + ErrorLog syslog:user + +
+ + +
diff --git a/docs/manual/mod/mod_syslog.xml.meta b/docs/manual/mod/mod_syslog.xml.meta new file mode 100644 index 00000000000..cb174b302fe --- /dev/null +++ b/docs/manual/mod/mod_syslog.xml.meta @@ -0,0 +1,12 @@ + + + + + mod_syslog + /mod/ + .. + + + en + + diff --git a/modules/loggers/config.m4 b/modules/loggers/config.m4 index 762e773e945..58ad35f72e4 100644 --- a/modules/loggers/config.m4 +++ b/modules/loggers/config.m4 @@ -3,7 +3,17 @@ dnl modules enabled in this directory by default dnl APACHE_MODULE(name, helptext[, objects[, structname[, default[, config]]]]) APACHE_MODPATH_INIT(loggers) - + +APACHE_MODULE(syslog, logging to syslog, , , all, [ + AC_CHECK_HEADERS(syslog.h, [ap_HAVE_SYSLOG_H="yes"], [ap_HAVE_SYSLOG_H="no"]) + if test $ap_HAVE_SYSLOG_H = "no"; then + AC_MSG_WARN([Your system does not support syslog.]) + enable_syslog="no" + else + enable_syslog="yes" + fi +]) + APACHE_MODULE(log_config, logging configuration. You won't be able to log requests to the server without this module., , , yes) APACHE_MODULE(log_debug, configurable debug logging, , , most) APACHE_MODULE(log_forensic, forensic logging) diff --git a/modules/loggers/mod_syslog.c b/modules/loggers/mod_syslog.c new file mode 100644 index 00000000000..6ab703d158f --- /dev/null +++ b/modules/loggers/mod_syslog.c @@ -0,0 +1,157 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include "ap_mpm.h" +#include "ap_provider.h" +#include +#include +#include +#include +#include +#include +#include +#include "unixd.h" +#include "scoreboard.h" +#include "mpm_common.h" + +#include "syslog.h" + +#if APR_HAVE_UNISTD_H +#include +#endif + +typedef struct { + const char *t_name; + int t_val; +} TRANS; + +static const TRANS facilities[] = { + {"auth", LOG_AUTH}, +#ifdef LOG_AUTHPRIV + {"authpriv",LOG_AUTHPRIV}, +#endif +#ifdef LOG_CRON + {"cron", LOG_CRON}, +#endif +#ifdef LOG_DAEMON + {"daemon", LOG_DAEMON}, +#endif +#ifdef LOG_FTP + {"ftp", LOG_FTP}, +#endif +#ifdef LOG_KERN + {"kern", LOG_KERN}, +#endif +#ifdef LOG_LPR + {"lpr", LOG_LPR}, +#endif +#ifdef LOG_MAIL + {"mail", LOG_MAIL}, +#endif +#ifdef LOG_NEWS + {"news", LOG_NEWS}, +#endif +#ifdef LOG_SYSLOG + {"syslog", LOG_SYSLOG}, +#endif +#ifdef LOG_USER + {"user", LOG_USER}, +#endif +#ifdef LOG_UUCP + {"uucp", LOG_UUCP}, +#endif +#ifdef LOG_LOCAL0 + {"local0", LOG_LOCAL0}, +#endif +#ifdef LOG_LOCAL1 + {"local1", LOG_LOCAL1}, +#endif +#ifdef LOG_LOCAL2 + {"local2", LOG_LOCAL2}, +#endif +#ifdef LOG_LOCAL3 + {"local3", LOG_LOCAL3}, +#endif +#ifdef LOG_LOCAL4 + {"local4", LOG_LOCAL4}, +#endif +#ifdef LOG_LOCAL5 + {"local5", LOG_LOCAL5}, +#endif +#ifdef LOG_LOCAL6 + {"local6", LOG_LOCAL6}, +#endif +#ifdef LOG_LOCAL7 + {"local7", LOG_LOCAL7}, +#endif + {NULL, -1}, +}; + + +static void *syslog_error_log_init(apr_pool_t *p, server_rec *s) +{ + char *fname = s->error_fname; + if (*fname == '\0') { + openlog(ap_server_argv0, LOG_NDELAY|LOG_CONS|LOG_PID, LOG_LOCAL7); + } + else { + 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 NULL; + } + } + } + + return NULL; +} + +static apr_status_t syslog_error_log(const ap_errorlog_info *info, + void *handle, const char *errstr, int len) +{ + int level = info->level; + syslog(level < LOG_PRIMASK ? level : APLOG_DEBUG, "%.*s", (int)len, errstr); + return APR_SUCCESS; +} + + +static void syslog_register_hooks(apr_pool_t *p) +{ + static const ap_errorlog_provider syslog_provider = { + &syslog_error_log_init, + &syslog_error_log + }; + + ap_register_provider(p, AP_ERRORLOG_PROVIDER_GROUP, "syslog", + AP_ERRORLOG_PROVIDER_VERSION, &syslog_provider); +} + +AP_DECLARE_MODULE(syslog) = +{ + STANDARD20_MODULE_STUFF, + NULL, + NULL, + NULL, + NULL, + NULL, + syslog_register_hooks, +};