Commit bf653a24 authored by Nigel Kukard's avatar Nigel Kukard
Browse files

* More flexible configuration of logging

parent 8a7d2faa
......@@ -207,14 +207,13 @@ sub configure {
}
# Check log_mail
if (!defined($config{'server'}{'log_mail'}) || $config{'server'}{'log_mail'} eq "maillog") {
$cfg->{'log_mail'} = "maillog";
} elsif ($config{'server'}{'log_mail'} eq "main") {
$cfg->{'log_mail'} = "main";
} else {
die("ERROR: log_mail option is invalid\n");
if (defined($config{'server'}{'log_mail'}) && $config{'server'}{'log_mail'} ne "main") {
# COMPATIBILITY
if ($config{'server'}{'log_mail'} eq "maillog") {
$cfg->{'log_mail'} = 'mail@syslog:native';
} else {
$cfg->{'log_mail'} = $config{'server'}{'log_mail'};
}
}
# Save our config and stuff
......@@ -266,12 +265,36 @@ sub post_configure_hook {
$self->log(LOG_NOTICE,"[CBPOLICYD] Session tracking is DISABLED.");
}
# If we logging to syslog, open...
if ($log_mail eq "maillog") {
$self->log(LOG_DEBUG,"[CBPOLICYD] Opening syslog.");
Sys::Syslog::setlogsock("unix") || $self->log(LOG_ERR,"[CBPOLICYD] Failed to set log socket: $!");
Sys::Syslog::openlog("cbpolicyd",'pid|ndelay','mail') || $self->log(LOG_ERR,"[CBPOLICYD] Failed to open syslog socket: $!");
$self->log(LOG_DEBUG,"[CBPOLICYD] Syslog open.");
# Check if we have some custom logging...
if (defined($log_mail)) {
# More flexible method to configure logging
if ($log_mail =~ /^([^@]+)(?:@([^:]+))?(?:\:(\S+))?$/) {
my $facility = $1;
my $method = defined($2) ? $2 : 'syslog';
my $destination = $3;
# Check method of logging
if ($method eq "syslog") {
$destination = 'native' if (!defined($destination));
$facility = 'mail' if (!defined($facility));
$self->log(LOG_DEBUG,"[CBPOLICYD] Opening syslog, destination = '$destination', facility = '$facility'.");
# We may have some args to pass to setlogsock
my @syslogArgs = split(/,/,$destination);
if (!Sys::Syslog::setlogsock(@syslogArgs)) {
$self->log(LOG_ERR,"[CBPOLICYD] Failed to set log socket: $!");
}
if (!Sys::Syslog::openlog("cbpolicyd",'pid|ndelay',$facility)) {
$self->log(LOG_ERR,"[CBPOLICYD] Failed to open syslog socket: $!");
}
} else {
$self->log(LOG_WARN,"[CBPOLICYD] Value of 'log_mail' not understood. Method '$method' is invalid.");
}
} else {
$self->log(LOG_WARN,"[CBPOLICYD] Value '$log_mail' of 'log_mail' not understood.");
}
}
}
......@@ -577,7 +600,7 @@ sub server_exit
$self->log(LOG_DEBUG,"System modules destroyed.");
# Check if we using syslog
if ($log_mail eq "maillog") {
if (defined($log_mail)) {
$self->log(LOG_DEBUG,"Closing syslog.");
Sys::Syslog::closelog();
$self->log(LOG_DEBUG,"Syslog closed.");
......@@ -627,7 +650,7 @@ sub maillog
# Log to syslog
if ($log_mail eq "maillog") {
if (defined($log_mail)) {
# If we have args use printf style
if (@args) {
Sys::Syslog::syslog('info',$msg,@args);
......@@ -636,7 +659,7 @@ sub maillog
}
# Or log to main mechanism
} elsif ($log_mail eq "main") {
} else {
$self->log(LOG_INFO,sprintf($msg,@args));
}
}
......
......@@ -65,9 +65,28 @@ EOT
#log_file=/var/log/cbpolicyd.log
# Log destination for mail logs...
# main - log to policyd's main log mechanism
# maillog - log mail via syslog
#log_mail=maillog
# main - Default. Log to policyd's main log mechanism, accepts NO args
# syslog - log mail via syslog
# format: log_mail=facility@method,args
#
# Valid methods for syslog:
# native - Let Sys::Syslog decide
# unix - Unix socket
# udp - UDP socket
# stream - Stream (for Solaris)
#
# Example: unix native
#log_mail=mail@syslog:native
#
# Example: unix socket
#log_mail=mail@syslog:unix
#
# Example: udp
#log_mail=mail@syslog:udp,127.0.0.1
#
# Example: Solaris
#log_mail=local0@syslog:stream,/dev/log
log_mail=maillog
# Things to log in extreme detail
# modules - Log detailed module running information
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment