blib/lib/Lemonldap/NG/Common/Logger/MessageBroker.pm untested

filter: Statementstmt 0.0% 0 / 22 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 2 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 50 CC 9 SCAR 44.0
CC
9
Cov
0%
new
90.0
BEGIN
2.0
CRAP 81.2
1 package Lemonldap::NG::Common::Logger::MessageBroker;
2  
3 use strict;
4  
5 our $VERSION = '2.21.0';
6  
7 sub new {
8 my $self = bless {}, shift;
9 my ( $conf, %args ) = @_;
10 my $show = 1;
11 die 'Missing conf->loggerBroker' unless $conf->{loggerBroker};
12 $conf->{loggerBroker} =~ s/^::/Lemonldap::NG::Common::MessageBroker::/;
13 my $brokerChannel =
14 $args{user}
15 ? ( $conf->{loggerUserBrokerChannel} || 'llng-userlogs' )
16 : ( $conf->{loggerBrokerChannel} || 'llng-logs' );
17 my $type = $args{user} ? 'logs' : 'userLogs';
18 eval "use $conf->{loggerBroker}";
19 die "Unable to load $conf->{loggerBroker}: $@" if $@;
20 $self->{broker} = $conf->{loggerBroker}->new( $conf->{loggerBrokerOpts} )
21 or die 'Unable to create message broker connector';
22  
23 foreach (qw(error warn notice info debug)) {
24 if ($show) {
25 eval qq'sub $_ {\$_[0]->{broker}->publish("$brokerChannel", {
26 type => "$type",
27 data => \$_[1],
28 time => time,
29 level => "$_",
30 })}';
31 die $@ if ($@);
32 }
33 else {
34 eval qq'sub $_ {1}';
35 }
36 $show = 0 if ( $conf->{logLevel} eq $_ );
37 }
38 die "Unknown logLevel $conf->{logLevel}" if $show;
39 return $self;
40 }
41  
42 1;