use Data::Dumper qw( Dumper );
use JSON qw( to_json );
+use Scalar::Util qw( blessed );
+use File::Basename qw( basename );
use C4::Context;
use Koha::Logger;
+use Koha::ActionLogs;
use vars qw(@ISA @EXPORT);
$usernumber ||= 0;
$interface //= C4::Context->interface;
- if ( ref($infos) && ref($infos) !~ /HASH|ARRAY/ && $infos->isa('Koha::Object') ) {
+ if( blessed($infos) && $infos->isa('Koha::Object') ) {
$infos = $infos->get_from_storage if $infos->in_storage;
- $infos = Dumper( $infos->unblessed );
+ local $Data::Dumper::Sortkeys = 1;
if ( $infos->isa('Koha::Item') && $modulename eq 'CATALOGUING' && $actionname eq 'MODIFY' ) {
- $infos = "item " . $infos;
+ $infos = "item " . Dumper( $infos->unblessed );
+ } else {
+ $infos = Dumper( $infos->unblessed );
}
}
- my $dbh = C4::Context->dbh;
- my $sth=$dbh->prepare("Insert into action_logs (timestamp,user,module,action,object,info,interface) values (now(),?,?,?,?,?,?)");
- $sth->execute($usernumber,$modulename,$actionname,$objectnumber,$infos,$interface);
- $sth->finish;
+ my $script = ( $interface eq 'cron' or $interface eq 'commandline' )
+ ? basename($0)
+ : undef;
+
+ my @trace;
+ my $depth = C4::Context->preference('ActionLogsTraceDepth') || 0;
+ for ( my $i = 0 ; $i < $depth ; $i++ ) {
+ my ( $package, $filename, $line, $subroutine ) = caller($i);
+ last unless defined $line;
+ push(
+ @trace,
+ {
+ package => $package,
+ filename => $filename,
+ line => $line,
+ subroutine => $subroutine,
+ }
+ );
+ }
+ my $trace = @trace ? to_json( \@trace, { utf8 => 1, pretty => 0 } ) : undef;
+
+ Koha::ActionLog->new(
+ {
+ timestamp => \'NOW()',
+ user => $usernumber,
+ module => $modulename,
+ action => $actionname,
+ object => $objectnumber,
+ info => $infos,
+ interface => $interface,
+ script => $script,
+ trace => $trace,
+ }
+ )->store();
my $logger = Koha::Logger->get(
{
#'
sub cronlogaction {
- my ($infos)=@_;
+ my $params = shift;
+ my $info = $params->{info};
+ my $action = $params->{action};
+ $action ||= "Run";
my $loginfo = (caller(0))[1];
- $loginfo .= ' ' . $infos if $infos;
- logaction( 'CRONJOBS', 'Run', undef, $loginfo ) if C4::Context->preference('CronjobLog');
+ $loginfo .= ' ' . $info if $info;
+ logaction( 'CRONJOBS', $action, $$, $loginfo ) if C4::Context->preference('CronjobLog');
}
1;