File Coverage

blib/lib/OpenPlugin/Log/Log4perl.pm
Criterion Covered Total %
statement 27 44 61.3
branch 1 2 50.0
condition n/a
subroutine 10 19 52.6
pod 0 15 0.0
total 38 80 47.5


line stmt bran cond sub pod time code
1             package OpenPlugin::Log::Log4perl;
2              
3             # $Id: Log4perl.pm,v 1.15 2003/04/12 03:17:42 andreychek Exp $
4              
5 6     6   19612 use strict;
  6         17  
  6         322  
6 6     6   6031 use OpenPlugin::Log();
  6         18  
  6         136  
7 6     6   93 use base qw( OpenPlugin::Log );
  6         12  
  6         784  
8 6     6   76 use Log::Log4perl 0.25 qw( get_logger );
  6         230  
  6         226  
9              
10             $OpenPlugin::Log::Log4perl::VERSION = sprintf("%d.%02d", q$Revision: 1.15 $ =~ /(\d+)\.(\d+)/);
11              
12             sub init {
13 6     6 0 18 my ( $self, $args ) = @_;
14              
15 6         17 $Log::Log4perl::caller_depth = 1;
16 6         107 my $params = $self->OP->get_plugin_info( "log" )->{'driver'}{'Log4perl'};
17              
18             # Each line from the config needs to start with "log4perl."
19 6         13 foreach my $string ( keys %{ $params } ) {
  6         38  
20 24 50       70 unless( $string =~ m/^log4perl\./ ) {
21 24         62 $string = "log4perl." . $string;
22             }
23             }
24 6         53 Log::Log4perl::init( $params );
25              
26 6         34793 return $self;
27             }
28              
29             # Here, we're just trying to mimic Log4perl's interface. Since Log4perl wasn't
30             # designed to be subclassed, we need to create all the methods we want to use,
31             # and pass parameters sent from them to Log4perl's functions
32              
33             # TODO: Is there a better way to do this? Is there a way we can have init()
34             # return a Log::Log4perl object instead of a OpenPlugin::Plugin::Log object?
35             # Are there any drawbacks with this?
36              
37             #################
38             # Logging Methods
39 0     0 0 0 sub debug { shift; get_logger((caller(0))[0])->debug( @_ ); }
  0         0  
40 3     3 0 6 sub info { shift; get_logger((caller(0))[0])->info( @_ ); }
  3         31  
41 0     0 0 0 sub warn { shift; get_logger((caller(0))[0])->warn( @_ ); }
  0         0  
42 0     0 0 0 sub error { shift; get_logger((caller(0))[0])->error( @_ ); }
  0         0  
43 0     0 0 0 sub fatal { shift; get_logger((caller(0))[0])->fatal( @_ ); }
  0         0  
44              
45             #############################
46             # Debug level testing methods
47 1     1 0 11 sub is_debug { return get_logger((caller(0))[0])->is_debug }
48 1     1 0 9 sub is_info { return get_logger((caller(0))[0])->is_info }
49 2     2 0 33 sub is_warn { return get_logger((caller(0))[0])->is_warn }
50 1     1 0 9 sub is_error { return get_logger((caller(0))[0])->is_error }
51 0     0 0   sub is_fatal { return get_logger((caller(0))[0])->is_fatal }
52              
53             #############################
54             # Alter logging levels
55 0     0 0   sub more_logging { shift; return get_logger((caller(0))[0])->more_logging( @_ ) }
  0            
56 0     0 0   sub less_logging { shift; return get_logger((caller(0))[0])->less_logging( @_ ) }
  0            
57 0     0 0   sub inc_level { shift; return get_logger((caller(0))[0])->inc_level( @_ ) }
  0            
58 0     0 0   sub dec_level { shift; return get_logger((caller(0))[0])->dec_level( @_ ) }
  0            
59              
60              
61             1;
62              
63             __END__