3 #package to deal with Logging Actions in DB
6 # Copyright 2000-2002 Katipo Communications
7 # Copyright 2011 MJ Ray and software.coop
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it
12 # under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 3 of the License, or
14 # (at your option) any later version.
16 # Koha is distributed in the hope that it will be useful, but
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with Koha; if not, see <http://www.gnu.org/licenses>.
27 use JSON
qw( to_json );
33 use vars
qw(@ISA @EXPORT);
38 @EXPORT = qw(&logaction &cronlogaction);
43 C4::Log - Koha Log Facility functions
51 The functions in this module perform various functions in order to log all the operations done on the Database, including deleting and undeleting books, adding/editing members, etc.
59 &logaction($modulename, $actionname, $objectnumber, $infos, $interface);
61 Adds a record into action_logs table to report the different changes upon the database.
62 Each log entry includes the number of the user currently logged in. For batch
63 jobs, which operate without authenticating a user and setting up a session, the user
64 number is set to 0, which is the same as the superlibrarian's number.
70 my ($modulename, $actionname, $objectnumber, $infos, $interface)=@_;
72 # Get ID of logged in user. if called from a batch job,
73 # no user session exists and C4::Context->userenv() returns
75 my $userenv = C4
::Context
->userenv();
76 my $usernumber = (ref($userenv) eq 'HASH') ?
$userenv->{'number'} : 0;
78 $interface //= C4
::Context
->interface;
80 my $dbh = C4
::Context
->dbh;
81 my $sth=$dbh->prepare("Insert into action_logs (timestamp,user,module,action,object,info,interface) values (now(),?,?,?,?,?,?)");
82 $sth->execute($usernumber,$modulename,$actionname,$objectnumber,$infos,$interface);
85 my $logger = Koha
::Logger
->get(
87 interface
=> $interface,
88 category
=> "ActionLogs.$modulename.$actionname"
93 "ACTION LOG: " . to_json
(
96 module
=> $modulename,
97 action
=> $actionname,
98 object
=> $objectnumber,
108 &cronlogaction($infos);
110 Convenience routine to add a record into action_logs table from a cron job.
111 Logs the path and name of the calling script plus the information privided by param $infos.
118 my $loginfo = (caller(0))[1];
119 $loginfo .= ' ' . $infos if $infos;
120 logaction
( 'CRONJOBS', 'Run', undef, $loginfo ) if C4
::Context
->preference('CronjobLog');
130 Koha Development Team <http://koha-community.org/>