Bug 16436 - Allow action logs to be logged to the koha log file
authorKyle M Hall <kyle@bywatersolutions.com>
Tue, 3 May 2016 18:58:57 +0000 (18:58 +0000)
committerKyle M Hall <kyle@bywatersolutions.com>
Tue, 2 Aug 2016 10:19:31 +0000 (10:19 +0000)
Test Plan:
1) Ensure that your Koha::Logger configuration is in good working order
2) Apply this patch
3) Modify the first line of your log4perl.conf file from:
    log4perl.logger.intranet = WARN, INTRANET
   to
    log4perl.logger.intranet = INFO, INTRANET
4) Change a system preference setting
5) Note the new line in your log file!

Signed-off-by: Srdjan <srdjan@catalyst.net.nz>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
C4/Log.pm

index de5f1d0..cff1e6f 100644 (file)
--- a/C4/Log.pm
+++ b/C4/Log.pm
@@ -24,8 +24,11 @@ package C4::Log;
 use strict;
 use warnings;
 
+use JSON qw( to_json );
+
 use C4::Context;
 use Koha::DateUtils;
+use Koha::Logger;
 
 use vars qw(@ISA @EXPORT);
 
@@ -77,6 +80,26 @@ 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 $logger = Koha::Logger->get(
+        {
+            interface => 'intranet',
+            category  => "ActionLogs.$modulename.$actionname"
+        }
+    );
+    $logger->info(
+        sub {
+            "ACTION LOG: " . to_json(
+                {
+                    user   => $usernumber,
+                    module => $modulename,
+                    action => $actionname,
+                    object => $objectnumber,
+                    info   => $infos
+                }
+            );
+        }
+    );
 }
 
 =item cronlogaction
@@ -144,10 +167,10 @@ sub displaylog {
                SELECT action_logs.timestamp, action_logs.action, action_logs.info,
                                borrowers.cardnumber, borrowers.surname, borrowers.firstname, borrowers.userid,
                        biblio.biblionumber, biblio.title, biblio.author
-        FROM action_logs 
-               LEFT JOIN borrowers ON borrowers.borrowernumber=action_logs.user 
+        FROM action_logs
+               LEFT JOIN borrowers ON borrowers.borrowernumber=action_logs.user
         LEFT JOIN  biblio   ON action_logs.object=biblio.biblionumber
-        WHERE action_logs.module = 'cataloguing' 
+        WHERE action_logs.module = 'cataloguing'
        |;
        my %filtermap = ();
     if ($modulename eq "catalogue" or $modulename eq "acqui") {
@@ -158,13 +181,13 @@ sub displaylog {
                );
     } elsif ($modulename eq "members") {
         $strsth=qq|
-               SELECT action_logs.timestamp, action_logs.action, action_logs.info, 
+               SELECT action_logs.timestamp, action_logs.action, action_logs.info,
                        borrowers.cardnumber, borrowers.surname, borrowers.firstname, borrowers.userid,
                        bor2.cardnumber, bor2.surname, bor2.firstname, bor2.userid
-        FROM action_logs 
-               LEFT JOIN borrowers ON borrowers.borrowernumber=action_logs.user 
+        FROM action_logs
+               LEFT JOIN borrowers ON borrowers.borrowernumber=action_logs.user
                LEFT JOIN borrowers as bor2 ON action_logs.object=bor2.borrowernumber
-        WHERE action_logs.module = 'members' 
+        WHERE action_logs.module = 'members'
                |;
                %filtermap = (
                       user => 'borrowers.surname',
@@ -204,7 +227,7 @@ sub displaylog {
 
 $logs = GetLogs($datefrom,$dateto,$user,\@modules,$action,$object,$info);
 
-Return: 
+Return:
 C<$logs> is a ref to a hash which containts all columns from action_logs
 
 =cut