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 / +3 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);
20
21
21
use Koha::Logger;
22
use Koha::Logger;
22
use C4::SIP::Trapper;
23
use C4::SIP::Trapper;
Lines 85-93 __PACKAGE__ ->run(@parms); Link Here
85
# Child
86
# Child
86
#
87
#
87
88
88
my $activeSIPServer;
89
my $activeLogger;
90
91
# process_request is the callback used by Net::Server to handle
89
# process_request is the callback used by Net::Server to handle
92
# an incoming connection request.
90
# an incoming connection request.
93
91
Lines 100-106 sub process_request { Link Here
100
    $self->{config} = $config;
98
    $self->{config} = $config;
101
99
102
    $self->{account} = undef;  # Clear out the account from the last request, it may be different
100
    $self->{account} = undef;  # Clear out the account from the last request, it may be different
103
    $self->{logger} = _set_logger( Koha::Logger->get( { interface => 'sip' } ) );
101
    $self->{logger} = set_logger( Koha::Logger->get( { interface => 'sip' } ) );
104
102
105
    # Flush previous MDCs to prevent accidentally leaking incorrect MDC-entries
103
    # Flush previous MDCs to prevent accidentally leaking incorrect MDC-entries
106
    Log::Log4perl::MDC->put( "accountid", undef );
104
    Log::Log4perl::MDC->put( "accountid", undef );
Lines 171-177 sub raw_transport { Link Here
171
    }
169
    }
172
    alarm 0;
170
    alarm 0;
173
171
174
    $self->{logger} = _set_logger(
172
    $self->{logger} = set_logger(
175
        Koha::Logger->get(
173
        Koha::Logger->get(
176
            {
174
            {
177
                interface => 'sip',
175
                interface => 'sip',
Lines 421-478 sub get_timeout { Link Here
421
    }
419
    }
422
}
420
}
423
421
424
=head2 get_SIPServer
425
426
    my $sipServer = C4::SIP::SIPServer::get_SIPServer()
427
428
@RETURNS C4::SIP::SIPServer, the current server's child-process used to handle this SIP-transaction
429
430
=cut
431
432
sub get_SIPServer {
433
    unless($activeSIPServer) {
434
        my @cc = caller(1);
435
        die "$cc[3]() asks for \$activeSIPServer, but he is not defined yet";
436
    }
437
    return $activeSIPServer;
438
}
439
440
sub _set_SIPServer {
441
    my ($sipServer) = @_;
442
    unless (blessed($sipServer) && $sipServer->isa('C4::SIP::SIPServer')) {
443
        my @cc = caller(0);
444
        die "$cc[3]():> \$sipServer '$sipServer' is not a C4::SIP::SIPServer-object";
445
    }
446
    $activeSIPServer = $sipServer;
447
    return $activeSIPServer;
448
}
449
450
=head2 get_logger
451
452
    my $logger = C4::SIP::SIPServer::get_logger()
453
454
@RETURNS Koha::Logger, the logger used to log this SIP-transaction
455
456
=cut
457
458
sub get_logger {
459
    unless($activeLogger) {
460
        my @cc = caller(1);
461
        die "$cc[3]() asks for \$activeLogger, but he is not defined yet";
462
    }
463
    return $activeLogger;
464
}
465
466
sub _set_logger {
467
    my ($logger) = @_;
468
    unless (blessed($logger) && $logger->isa('Koha::Logger')) {
469
        my @cc = caller(0);
470
        die "$cc[3]():> \$logger '$logger' is not a Koha::Logger-object";
471
    }
472
    $activeLogger = $logger;
473
    return $activeLogger;
474
}
475
476
1;
422
1;
477
423
478
__END__
424
__END__
(-)a/C4/SIP/Sip.pm (-2 / +3 lines)
Lines 14-19 use IO::Handle; Link Here
14
14
15
use C4::SIP::Sip::Constants qw(SIP_DATETIME FID_SCREEN_MSG);
15
use C4::SIP::Sip::Constants qw(SIP_DATETIME FID_SCREEN_MSG);
16
use C4::SIP::Sip::Checksum qw(checksum);
16
use C4::SIP::Sip::Checksum qw(checksum);
17
use C4::SIP::Logger qw(get_logger);
17
18
18
use base qw(Exporter);
19
use base qw(Exporter);
19
20
Lines 204-210 sub syslog { Link Here
204
205
205
    my $message = @args ? sprintf($mask, @args) : $mask;
206
    my $message = @args ? sprintf($mask, @args) : $mask;
206
207
207
    C4::SIP::SIPServer::get_logger()->$method($message);
208
    my $logger = C4::SIP::Logger::get_logger();
209
    $logger->$method($message) if $logger;
208
}
210
}
209
211
210
1;
212
1;
211
- 

Return to bug 15253