View | Details | Raw Unified | Return to bug 18205
Collapse All | Expand All

(-)a/C4/Context.pm (-1 / +1 lines)
Lines 1029-1035 sub interface { Link Here
1029
    if (defined $interface) {
1029
    if (defined $interface) {
1030
        $interface = lc $interface;
1030
        $interface = lc $interface;
1031
        if ($interface eq 'opac' || $interface eq 'intranet' || $interface eq 'sip' ||
1031
        if ($interface eq 'opac' || $interface eq 'intranet' || $interface eq 'sip' ||
1032
            $interface eq 'commandline' || $interface eq 'rest' ) {
1032
            $interface eq 'commandline' || $interface eq 'api' ) {
1033
            $context->{interface} = $interface;
1033
            $context->{interface} = $interface;
1034
        } else {
1034
        } else {
1035
            warn "invalid interface : '$interface'";
1035
            warn "invalid interface : '$interface'";
(-)a/Koha/Logger/Mojo.pm (-20 / +20 lines)
Lines 29-53 Koha::Logger::Mojo Link Here
29
    $c->app->log->warn( 'WARNING: Serious error encountered' );
29
    $c->app->log->warn( 'WARNING: Serious error encountered' );
30
30
31
    EXAMPLE CONFIGS:
31
    EXAMPLE CONFIGS:
32
    log4perl.logger.rest = ERROR, REST
32
    log4perl.logger.api = ERROR, API
33
    log4perl.appender.REST=Log::Log4perl::Appender::File
33
    log4perl.appender.API=Log::Log4perl::Appender::File
34
    log4perl.appender.REST.filename=__LOG_DIR__/rest.log
34
    log4perl.appender.API.filename=__LOG_DIR__/api.log
35
    log4perl.appender.REST.create_at_logtime=true
35
    log4perl.appender.API.create_at_logtime=true
36
    log4perl.appender.REST.syswrite=true
36
    log4perl.appender.API.syswrite=true
37
    log4perl.appender.REST.recreate=true
37
    log4perl.appender.API.recreate=true
38
    log4perl.appender.REST.mode=append
38
    log4perl.appender.API.mode=append
39
    log4perl.appender.REST.layout=PatternLayout
39
    log4perl.appender.API.layout=PatternLayout
40
    log4perl.appender.REST.layout.ConversionPattern=[%d] [%p] %m %l %n
40
    log4perl.appender.API.layout.ConversionPattern=[%d] [%p] %m %l %n
41
41
42
    log4perl.logger.rest.Mojolicious.Plugin.OpenAPI = WARN, REST
42
    log4perl.logger.api.Mojolicious.Plugin.OpenAPI = WARN, API
43
    log4perl.appender.REST=Log::Log4perl::Appender::File
43
    log4perl.appender.API=Log::Log4perl::Appender::File
44
    log4perl.appender.REST.filename=__LOG_DIR__/rest.log
44
    log4perl.appender.API.filename=__LOG_DIR__/api.log
45
    log4perl.appender.REST.create_at_logtime=true
45
    log4perl.appender.API.create_at_logtime=true
46
    log4perl.appender.REST.syswrite=true
46
    log4perl.appender.API.syswrite=true
47
    log4perl.appender.REST.recreate=true
47
    log4perl.appender.API.recreate=true
48
    log4perl.appender.REST.mode=append
48
    log4perl.appender.API.mode=append
49
    log4perl.appender.REST.layout=PatternLayout
49
    log4perl.appender.API.layout=PatternLayout
50
    log4perl.appender.REST.layout.ConversionPattern=[%d] [%p] %m %l %n
50
    log4perl.appender.API.layout.ConversionPattern=[%d] [%p] %m %l %n
51
51
52
=head1 DESCRIPTION
52
=head1 DESCRIPTION
53
53
Lines 99-105 sub get { Link Here
99
Overloads MojoX::Log::Log4perl::_get_logger by optionally including interface
99
Overloads MojoX::Log::Log4perl::_get_logger by optionally including interface
100
and category.
100
and category.
101
101
102
For REST API, 'rest' should be the root category by default (defined in startup)
102
For REST API, 'api' should be the root category by default (defined in startup)
103
103
104
=cut
104
=cut
105
105
(-)a/Koha/REST/V1.pm (-1 / +1 lines)
Lines 40-46 Overloaded Mojolicious->startup method. It is called at application startup. Link Here
40
sub startup {
40
sub startup {
41
    my $self = shift;
41
    my $self = shift;
42
42
43
    C4::Context->interface('rest');
43
    C4::Context->interface('api');
44
44
45
    $self->log(Koha::Logger::Mojo->get);
45
    $self->log(Koha::Logger::Mojo->get);
46
46
(-)a/etc/log4perl.conf (-9 / +9 lines)
Lines 12-23 log4perl.appender.OPAC.mode=append Link Here
12
log4perl.appender.OPAC.layout=PatternLayout
12
log4perl.appender.OPAC.layout=PatternLayout
13
log4perl.appender.OPAC.layout.ConversionPattern=[%d] [%p] %m %l %n
13
log4perl.appender.OPAC.layout.ConversionPattern=[%d] [%p] %m %l %n
14
14
15
log4perl.logger.rest = WARN, REST
15
log4perl.logger.api = WARN, API
16
log4perl.appender.REST=Log::Log4perl::Appender::File
16
log4perl.appender.API=Log::Log4perl::Appender::File
17
log4perl.appender.REST.filename=__LOG_DIR__/rest.log
17
log4perl.appender.API.filename=__LOG_DIR__/api.log
18
log4perl.appender.REST.create_at_logtime=true
18
log4perl.appender.API.create_at_logtime=true
19
log4perl.appender.REST.syswrite=true
19
log4perl.appender.API.syswrite=true
20
log4perl.appender.REST.recreate=true
20
log4perl.appender.API.recreate=true
21
log4perl.appender.REST.mode=append
21
log4perl.appender.API.mode=append
22
log4perl.appender.REST.layout=PatternLayout
22
log4perl.appender.API.layout=PatternLayout
23
log4perl.appender.REST.layout.ConversionPattern=[%d] [%p] %m %l %n
23
log4perl.appender.API.layout.ConversionPattern=[%d] [%p] %m %l %n
(-)a/t/Koha/Logger/Mojo.t (-4 / +4 lines)
Lines 37-53 use_ok('Koha::Logger::Mojo'); Link Here
37
37
38
# Create test context
38
# Create test context
39
my $config = {
39
my $config = {
40
    'log4perl.logger.rest' => 'ERROR, TEST',
40
    'log4perl.logger.api' => 'ERROR, TEST',
41
    'log4perl.appender.TEST' => 'Log::Log4perl::Appender::TestBuffer',
41
    'log4perl.appender.TEST' => 'Log::Log4perl::Appender::TestBuffer',
42
    'log4perl.appender.TEST.layout' => 'SimpleLayout',
42
    'log4perl.appender.TEST.layout' => 'SimpleLayout',
43
};
43
};
44
C4::Context->interface('rest');
44
C4::Context->interface('api');
45
t::lib::Mocks::mock_config('log4perl_conf', $config);
45
t::lib::Mocks::mock_config('log4perl_conf', $config);
46
46
47
subtest 'check inteface' => sub {
47
subtest 'check inteface' => sub {
48
    plan tests => 1;
48
    plan tests => 1;
49
49
50
    is(C4::Context->interface, 'rest', 'Using appropriate interface.');
50
    is(C4::Context->interface, 'api', 'Using appropriate interface.');
51
};
51
};
52
52
53
subtest 'get() tests' => sub {
53
subtest 'get() tests' => sub {
Lines 62-68 subtest 'Test configuration effectiveness' => sub { Link Here
62
    plan tests => 6;
62
    plan tests => 6;
63
63
64
    get '/test' => sub {
64
    get '/test' => sub {
65
        package Koha::REST::V1::Test; # otherwise category would be rest.main
65
        package Koha::REST::V1::Test; # otherwise category would be api.main
66
        $_[0]->app->log->error('Very problem');
66
        $_[0]->app->log->error('Very problem');
67
        $_[0]->app->log->warn('Such issue');
67
        $_[0]->app->log->warn('Such issue');
68
        $_[0]->render(text => 'Hello World');
68
        $_[0]->render(text => 'Hello World');
(-)a/t/db_dependent/Log.t (-7 / +6 lines)
Lines 125-134 subtest 'logaction(): interface is correctly logged' => sub { Link Here
125
125
126
    # Explicit interfaces
126
    # Explicit interfaces
127
    $dbh->do("DELETE FROM action_logs;");
127
    $dbh->do("DELETE FROM action_logs;");
128
    C4::Context->interface( 'rest' );
128
    C4::Context->interface( 'api' );
129
    logaction( "MEMBERS", "MODIFY", 1, 'test info', 'rest');
129
    logaction( "MEMBERS", "MODIFY", 1, 'test info', 'api');
130
    $logs = GetLogs();
130
    $logs = GetLogs();
131
    is( @{$logs}[0]->{ interface }, 'rest', 'Passed interface is respected (rest)');
131
    is( @{$logs}[0]->{ interface }, 'api', 'Passed interface is respected (api)');
132
132
133
};
133
};
134
134
Lines 142-148 subtest 'GetLogs() respects interface filters' => sub { Link Here
142
    logaction( 'MEMBERS', 'MODIFY', 1, 'sip info',         'sip');
142
    logaction( 'MEMBERS', 'MODIFY', 1, 'sip info',         'sip');
143
    logaction( 'MEMBERS', 'MODIFY', 1, 'intranet info',    'intranet');
143
    logaction( 'MEMBERS', 'MODIFY', 1, 'intranet info',    'intranet');
144
    logaction( 'MEMBERS', 'MODIFY', 1, 'commandline info', 'commandline');
144
    logaction( 'MEMBERS', 'MODIFY', 1, 'commandline info', 'commandline');
145
    logaction( 'MEMBERS', 'MODIFY', 1, 'rest info', 'rest');
145
    logaction( 'MEMBERS', 'MODIFY', 1, 'api info', 'api');
146
146
147
    my $logs = scalar @{ GetLogs() };
147
    my $logs = scalar @{ GetLogs() };
148
    is( $logs, 5, 'If no filter on interfaces is passed, all logs are returned');
148
    is( $logs, 5, 'If no filter on interfaces is passed, all logs are returned');
Lines 159-166 subtest 'GetLogs() respects interface filters' => sub { Link Here
159
    $logs = GetLogs(undef,undef,undef,undef,undef,undef,undef,['commandline']);
159
    $logs = GetLogs(undef,undef,undef,undef,undef,undef,undef,['commandline']);
160
    is( @{$logs}[0]->{ interface }, 'commandline', 'Interface correctly filtered (commandline)');
160
    is( @{$logs}[0]->{ interface }, 'commandline', 'Interface correctly filtered (commandline)');
161
161
162
    $logs = GetLogs(undef,undef,undef,undef,undef,undef,undef,['rest']);
162
    $logs = GetLogs(undef,undef,undef,undef,undef,undef,undef,['api']);
163
    is( @{$logs}[0]->{ interface }, 'rest', 'Interface correctly filtered (rest)');
163
    is( @{$logs}[0]->{ interface }, 'api', 'Interface correctly filtered (api)');
164
164
165
};
165
};
166
166
167
- 

Return to bug 18205