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

(-)a/C4/SIP/Logger.pm (+47 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
package C4::SIP::Logger;
3
4
use Modern::Perl;
5
6
our $activeSIPServer;
7
our $activeLogger;
8
9
=head2 get_SIPServer
10
11
    my $sipServer = C4::SIP::SIPServer::get_SIPServer()
12
13
@RETURNS C4::SIP::SIPServer, the current server's child-process used to handle this SIP-transaction
14
15
=cut
16
17
sub get_SIPServer {
18
    return $activeSIPServer;
19
}
20
21
sub _set_SIPServer {
22
    my ($sipServer) = @_;
23
    $activeSIPServer = $sipServer;
24
    return $activeSIPServer;
25
}
26
27
=head2 get_logger
28
29
    my $logger = C4::SIP::SIPServer::get_logger()
30
31
@RETURNS Koha::Logger, the logger used to log this SIP-transaction
32
33
=cut
34
35
sub get_logger {
36
    return $activeLogger;
37
}
38
39
sub set_logger {
40
    my ($logger) = @_;
41
    $activeLogger = $logger;
42
    return $activeLogger;
43
}
44
45
1;
46
47
__END__
(-)a/C4/SIP/SIPServer.pm (-57 / +4 lines)
Lines 17-22 use C4::SIP::Sip::Constants qw(:all); Link Here
17
use C4::SIP::Sip::Configuration;
17
use C4::SIP::Sip::Configuration;
18
use C4::SIP::Sip::Checksum qw(checksum verify_cksum);
18
use C4::SIP::Sip::Checksum qw(checksum verify_cksum);
19
use C4::SIP::Sip::MsgType qw( handle login_core );
19
use C4::SIP::Sip::MsgType qw( handle login_core );
20
use C4::SIP::Logger qw(set_logger);
21
20
use Koha::Caches;
22
use Koha::Caches;
21
23
22
use Koha::Logger;
24
use Koha::Logger;
Lines 86-94 __PACKAGE__ ->run(@parms); Link Here
86
# Child
88
# Child
87
#
89
#
88
90
89
my $activeSIPServer;
90
my $activeLogger;
91
92
# process_request is the callback used by Net::Server to handle
91
# process_request is the callback used by Net::Server to handle
93
# an incoming connection request.
92
# an incoming connection request.
94
93
Lines 104-110 sub process_request { Link Here
104
    Koha::Caches->flush_L1_caches();
103
    Koha::Caches->flush_L1_caches();
105
104
106
    $self->{account} = undef;  # Clear out the account from the last request, it may be different
105
    $self->{account} = undef;  # Clear out the account from the last request, it may be different
107
    $self->{logger} = _set_logger( Koha::Logger->get( { interface => 'sip' } ) );
106
    $self->{logger} = set_logger( Koha::Logger->get( { interface => 'sip' } ) );
108
107
109
    # Flush previous MDCs to prevent accidentally leaking incorrect MDC-entries
108
    # Flush previous MDCs to prevent accidentally leaking incorrect MDC-entries
110
    Log::Log4perl::MDC->put( "accountid", undef );
109
    Log::Log4perl::MDC->put( "accountid", undef );
Lines 175-181 sub raw_transport { Link Here
175
    }
174
    }
176
    alarm 0;
175
    alarm 0;
177
176
178
    $self->{logger} = _set_logger(
177
    $self->{logger} = set_logger(
179
        Koha::Logger->get(
178
        Koha::Logger->get(
180
            {
179
            {
181
                interface => 'sip',
180
                interface => 'sip',
Lines 425-482 sub get_timeout { Link Here
425
    }
424
    }
426
}
425
}
427
426
428
=head2 get_SIPServer
429
430
    my $sipServer = C4::SIP::SIPServer::get_SIPServer()
431
432
@RETURNS C4::SIP::SIPServer, the current server's child-process used to handle this SIP-transaction
433
434
=cut
435
436
sub get_SIPServer {
437
    unless($activeSIPServer) {
438
        my @cc = caller(1);
439
        die "$cc[3]() asks for \$activeSIPServer, but he is not defined yet";
440
    }
441
    return $activeSIPServer;
442
}
443
444
sub _set_SIPServer {
445
    my ($sipServer) = @_;
446
    unless (blessed($sipServer) && $sipServer->isa('C4::SIP::SIPServer')) {
447
        my @cc = caller(0);
448
        die "$cc[3]():> \$sipServer '$sipServer' is not a C4::SIP::SIPServer-object";
449
    }
450
    $activeSIPServer = $sipServer;
451
    return $activeSIPServer;
452
}
453
454
=head2 get_logger
455
456
    my $logger = C4::SIP::SIPServer::get_logger()
457
458
@RETURNS Koha::Logger, the logger used to log this SIP-transaction
459
460
=cut
461
462
sub get_logger {
463
    unless($activeLogger) {
464
        my @cc = caller(1);
465
        die "$cc[3]() asks for \$activeLogger, but he is not defined yet";
466
    }
467
    return $activeLogger;
468
}
469
470
sub _set_logger {
471
    my ($logger) = @_;
472
    unless (blessed($logger) && $logger->isa('Koha::Logger')) {
473
        my @cc = caller(0);
474
        die "$cc[3]():> \$logger '$logger' is not a Koha::Logger-object";
475
    }
476
    $activeLogger = $logger;
477
    return $activeLogger;
478
}
479
480
1;
427
1;
481
428
482
__END__
429
__END__
(-)a/C4/SIP/Sip.pm (-2 / +3 lines)
Lines 15-20 use List::Util qw(first); Link Here
15
15
16
use C4::SIP::Sip::Constants qw(SIP_DATETIME FID_SCREEN_MSG);
16
use C4::SIP::Sip::Constants qw(SIP_DATETIME FID_SCREEN_MSG);
17
use C4::SIP::Sip::Checksum qw(checksum);
17
use C4::SIP::Sip::Checksum qw(checksum);
18
use C4::SIP::Logger qw(get_logger);
18
19
19
use base qw(Exporter);
20
use base qw(Exporter);
20
21
Lines 215-221 sub syslog { Link Here
215
216
216
    my $message = @args ? sprintf($mask, @args) : $mask;
217
    my $message = @args ? sprintf($mask, @args) : $mask;
217
218
218
    C4::SIP::SIPServer::get_logger()->$method($message);
219
    my $logger = C4::SIP::Logger::get_logger();
220
    $logger->$method($message) if $logger;
219
}
221
}
220
222
221
1;
223
1;
222
- 

Return to bug 15253