diff --git a/C4/Reports/Guided.pm b/C4/Reports/Guided.pm index 1d8b195b3c..635494d548 100644 --- a/C4/Reports/Guided.pm +++ b/C4/Reports/Guided.pm @@ -18,6 +18,7 @@ package C4::Reports::Guided; # along with Koha; if not, see . use Modern::Perl; + use CGI qw ( -utf8 ); use Carp qw( carp croak ); use JSON qw( from_json ); @@ -609,12 +610,20 @@ sub execute_query { $dbh->do( 'UPDATE saved_sql SET last_run = NOW() WHERE id = ?', undef, $report_id ) if $report_id; + Koha::Logger->get( { prefix => 0, interface => 'reports', category => 'execute.query' } ) + ->info("Report $report_id : $sql, $offset, $limit") if $report_id; + Koha::Logger->get( { prefix => 0, interface => 'reports', category => 'execute.time.start' } ) + ->info("Report starting: $report_id") if $report_id; + my $sth = $dbh->prepare($sql); eval { $sth->execute(@$sql_params, $offset, $limit); }; warn $@ if $@; + Koha::Logger->get( { prefix => 0, interface => 'reports', category => 'execute.time.end' } ) + ->info("Report finished: $report_id") if $report_id; + return ( $sth, { queryerr => $sth->errstr } ) if ($sth->err); return ( $sth ); } diff --git a/Koha/Logger.pm b/Koha/Logger.pm index 3f335c2981..2bc6c35055 100644 --- a/Koha/Logger.pm +++ b/Koha/Logger.pm @@ -51,13 +51,16 @@ BEGIN { Normally, the category should follow the current package and the interface should be set correctly via C4::Context. + If the category should not be prefixed if plack, set the param 'prefix' to 0. =cut sub get { my ( $class, $params ) = @_; my $interface = $params ? ( $params->{interface} || C4::Context->interface ) : C4::Context->interface; my $category = $params ? ( $params->{category} || caller ) : caller; - my $l4pcat = ( C4::Context->psgi_env ? 'plack-' : q{} ) . $interface . '.' . $category; + my $prefix = $params->{prefix} // 1; + + my $l4pcat = ( ( $prefix && C4::Context->psgi_env ) ? 'plack-' : q{} ) . $interface . '.' . $category; my $init = _init(); my $self = {}; diff --git a/t/Logger.t b/t/Logger.t index 2b63c8efa5..4281c3b6ff 100755 --- a/t/Logger.t +++ b/t/Logger.t @@ -27,7 +27,7 @@ use Test::Warn; use Test::Exception; subtest 'Test01 -- Simple tests for Koha::Logger' => sub { - plan tests => 10; + plan tests => 13; my $ret; t::lib::Mocks::mock_config('log4perl_conf', undef); @@ -76,6 +76,21 @@ HERE Koha::Logger->clear_mdc(); is( Koha::Logger->get_mdc( 'foo' ), undef, "MDC value was cleared by clear_mdc" ); + + is( + Koha::Logger->get( { interface => 'cli', category => 'Test.Category' } )->category(), "cli.Test.Category", + "Category is cli.Test.Category" + ); + $ENV{'PLACK_ENV'} = 1; + is( + Koha::Logger->get( { interface => 'cli', category => 'Test.Category' } )->category(), + "plack-cli.Test.Category", "Category under plack is is plack-cli.Test.Category" + ); + is( + Koha::Logger->get( { interface => 'cli', category => 'Test.Category', prefix => 0 } )->category(), + "cli.Test.Category", "Category under plack with prefixing disabled is is cli.Test.Category" + ); + delete $ENV{'PLACK_ENV'}; }; sub mytempfile {