File Coverage

blib/lib/DJabberd/Log.pm
Criterion Covered Total %
statement 24 39 61.5
branch 2 10 20.0
condition 1 5 20.0
subroutine 5 6 83.3
pod 0 2 0.0
total 32 62 51.6


line stmt bran cond sub pod time code
1              
2             package DJabberd::Log::Junk;
3              
4 17     17   102323 use Log::Log4perl qw(:resurrect);
  17         616947  
  17         81  
5              
6             package DJabberd::Log;
7 17     17   24810 use strict;
  17         28  
  17         123  
8 17     17   317 use warnings;
  17         20  
  17         182  
9              
10 17     17   389 no warnings 'redefine';
  17         24  
  17         230  
11              
12             our $has_run;
13             our $logger;
14              
15             sub get_logger {
16 0     0 0 0 my ($class, $category) = @_;
17 0         0 my ($package, $filename, $line) = caller;
18              
19 0         0 my $autostarted = 0;
20 0 0       0 unless ($has_run) {
21 0         0 my @locations = (
22             "etc/log.conf",
23             "/etc/djabberd/log.conf",
24             "etc/log.conf.default"
25             );
26 0         0 DJabberd::Log->set_logger(@locations);
27 0         0 $autostarted = 1;
28             }
29              
30 0   0     0 my $ret = Log::Log4perl->get_logger($category || $package);
31             # Let user know that we've used the hardcoded list of locations from above
32             # rather than any special settings he might have wanted.
33 0 0       0 $ret->logwarn("Logger was started on demand from ", $filename, " line ", $line) if $autostarted;
34 0         0 return $ret;
35             }
36              
37             sub set_logger {
38 17     17 0 691 my ($class, @locations) = @_;
39              
40 17         21 my $used_file;
41 17 50       72 @locations = () if $ENV{LOGLEVEL};
42 17         32 foreach my $conffile (@locations) {
43 0 0       0 next unless -e $conffile;
44 0         0 Log::Log4perl->init_and_watch($conffile, 1);
45 0         0 $logger = Log::Log4perl->get_logger();
46 0         0 $used_file = $conffile;
47 0         0 last;
48             }
49              
50 17   50     57 my $loglevel = $ENV{LOGLEVEL} || "WARN";
51              
52 17 50       79 unless ($used_file) {
53 17         62 my $conf = qq{
54             log4perl.logger.DJabberd = $loglevel, screen
55             log4perl.logger.DJabberd.Hook = $loglevel
56              
57             # This psuedo class is used to control if raw XML is to be showed or not
58             # at DEBUG it shows all raw traffic
59             # at INFO it censors out the actual data
60             log4perl.logger.DJabberd.Connection.XML = $loglevel
61              
62             log4perl.appender.screen = Log::Log4perl::Appender::ScreenColoredLevels
63             log4perl.appender.screen.layout = Log::Log4perl::Layout::PatternLayout
64             log4perl.appender.screen.layout.ConversionPattern = %P %-5p %-40c %m %n
65             };
66 17         93 Log::Log4perl->init(\$conf);
67 17         152550 $logger = Log::Log4perl->get_logger();
68 17         3068 $used_file = "BUILT-IN-DEFAULTS";
69             }
70              
71 17         92 $logger->info("Started logging using '$used_file'");
72 17         546 $has_run++;
73             }
74              
75             # Local Variables:
76             # mode: perl
77             # c-basic-indent: 4
78             # indent-tabs-mode: nil
79             # End:
80              
81             1;