From cd18241c33bc34665b24052d4821a95fba09ee4c Mon Sep 17 00:00:00 2001 From: Srdjan Date: Tue, 9 Sep 2014 11:14:11 +1200 Subject: [PATCH] Log koha actions to syslog too * Added kohasite and syslog_facility to config * syslog_facility is set to "user" and commented out for the fresh site install * If syslog_facility is enabled in config, log to syslog as (value of kohasite config) * /etc/rsyslog.d/99-.conf is created with filter instructions to direct log entries to standard log dir (/var/log/koha/) action.log; syslog daemons other than rsyslog need to be configured (or not) to do the same, otherwise catch all syslog log file is used http://bugs.koha-community.org/show_bug.cgi?id=12952 --- C4/Log.pm | 8 ++++++++ debian/scripts/koha-create | 6 +++++- debian/scripts/koha-dump | 1 + debian/scripts/koha-remove | 2 ++ debian/templates/koha-conf-site.xml.in | 4 ++++ debian/templates/rsyslog-site.conf.in | 2 ++ t/Log.t | 1 + 7 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 debian/templates/rsyslog-site.conf.in diff --git a/C4/Log.pm b/C4/Log.pm index 80c3493..7e3bbe7 100644 --- a/C4/Log.pm +++ b/C4/Log.pm @@ -26,6 +26,7 @@ use warnings; use C4::Context; use C4::Dates qw(format_date); +use Sys::Syslog qw(:standard :macros); use vars qw($VERSION @ISA @EXPORT); @@ -79,6 +80,13 @@ sub logaction { my $sth=$dbh->prepare("Insert into action_logs (timestamp,user,module,action,object,info) values (now(),?,?,?,?,?)"); $sth->execute($usernumber,$modulename,$actionname,$objectnumber,$infos); $sth->finish; + + my $facility = C4::Context->config("syslog_facility") or return; + my $kohasite = C4::Context->config("kohasite"); + openlog($kohasite, 'nofatal', $facility); + $objectnumber = '' unless defined $objectnumber; + syslog(LOG_NOTICE, "$modulename: $actionname ($objectnumber); [$usernumber] $infos"); + closelog(); } =item GetLogStatus diff --git a/debian/scripts/koha-create b/debian/scripts/koha-create index 6891ac1..5c4aa2a 100755 --- a/debian/scripts/koha-create +++ b/debian/scripts/koha-create @@ -546,8 +546,12 @@ eof # Generate and install Apache site-available file and log dir. generate_config_file apache-site.conf.in \ "/etc/apache2/sites-available/$name.conf" + # Generate and install rsyslog conf + generate_config_file rsyslog-site.conf.in \ + "/etc/rsyslog.d/99-$name.conf" mkdir "/var/log/koha/$name" - chown "$username:$username" "/var/log/koha/$name" + chown "$username:adm" "/var/log/koha/$name" + chmod 0775 "/var/log/koha/$name" # Generate and install main Koha config file. diff --git a/debian/scripts/koha-dump b/debian/scripts/koha-dump index bf4bd5f..23a4b38 100755 --- a/debian/scripts/koha-dump +++ b/debian/scripts/koha-dump @@ -63,6 +63,7 @@ tar -C / -czf "$metadump" \ "etc/koha/sites/$name" \ "etc/apache2/sites-available/$instancefile" \ "etc/apache2/sites-enabled/$instancefile" \ + "etc/rsyslog.d/99-$name.conf" \ "var/lib/koha/$name" \ "var/log/koha/$name" diff --git a/debian/scripts/koha-remove b/debian/scripts/koha-remove index 528db75..39e3afd 100755 --- a/debian/scripts/koha-remove +++ b/debian/scripts/koha-remove @@ -81,6 +81,8 @@ eof [ -f "$instancefile" ] && \ rm "$instancefile" + [ -f "/etc/rsyslog.d/99-$name.conf" ] && \ + rm "/etc/rsyslog.d/99-$name.conf" [ -f "/etc/koha/sites/$name/koha-conf.xml" ] && \ rm "/etc/koha/sites/$name/koha-conf.xml" [ -f "/etc/koha/sites/$name/zebra-biblios.cfg" ] && \ diff --git a/debian/templates/koha-conf-site.xml.in b/debian/templates/koha-conf-site.xml.in index 371b1d2..7506631 100644 --- a/debian/templates/koha-conf-site.xml.in +++ b/debian/templates/koha-conf-site.xml.in @@ -248,6 +248,7 @@ --> + __KOHASITE__ mysql __DB_NAME__ __DB_HOST__ @@ -282,6 +283,9 @@ __AUTHORITIES_INDEXING_MODE__ /var/lock/koha/__KOHASITE__ /etc/koha/searchengine/queryparser.yaml + diff --git a/debian/templates/rsyslog-site.conf.in b/debian/templates/rsyslog-site.conf.in new file mode 100644 index 0000000..bd566d3 --- /dev/null +++ b/debian/templates/rsyslog-site.conf.in @@ -0,0 +1,2 @@ +if $programname == '__KOHASITE__' then /var/log/koha/__KOHASITE__/action.log +if $programname == '__KOHASITE__' then ~ diff --git a/t/Log.t b/t/Log.t index 601b909..d11cd9f 100755 --- a/t/Log.t +++ b/t/Log.t @@ -13,6 +13,7 @@ BEGIN { use_ok('C4::Log'); } +t::lib::Mocks::mock_config('syslog_facility', 'user'); t::lib::Mocks::mock_preference('BorrowersLog', 1); t::lib::Mocks::mock_preference('CataloguingLog', 1); t::lib::Mocks::mock_preference('IssueLog', 1); -- 1.9.1