| 1 | |||||||||||||||||||||
| 2 | package DJabberd::Log::Junk; | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 20 | ▶ | use Log::Log4perl qw(:resurrect); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | package DJabberd::Log; | ||||||||||||||||||||
| 7 | 20 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 20 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 20 | ▶ | no warnings 'redefine'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 20 | our $has_run; | |||||||||||||||||||
| 13 | 20 | our $logger; | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 340 | ▶ | sub get_logger { | ||||||||||||||||||
|
Subroutine
get_logger: called CC=4 SCAR=15.5
Pod
undocumented
| |||||||||||||||||||||
| 16 | 340 | my ($class, $category) = @_; | |||||||||||||||||||
| 17 | 340 | my ($package, $filename, $line) = caller; | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 340 | my $autostarted = 0; | |||||||||||||||||||
| 20 | 340 | ▶ | unless ($has_run) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 21 | 0 | my @locations = ( | |||||||||||||||||||
| 22 | "etc/log.conf", | ||||||||||||||||||||
| 23 | "/etc/djabberd/log.conf", | ||||||||||||||||||||
| 24 | "etc/log.conf.default" | ||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||
| 26 | 0 | DJabberd::Log->set_logger(@locations); | |||||||||||||||||||
| 27 | 0 | $autostarted = 1; | |||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 340 | ▶ | my $ret = Log::Log4perl->get_logger($category || $package); | ||||||||||||||||||
|
Condition66%2/3
$category || $package
MC/DC0%0/2
$category || $package
$category
$package
Truth table66%2/3
A || B
A= $categoryB= $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 | 340 | ▶ | $ret->logwarn("Logger was started on demand from ", $filename, " line ", $line) if $autostarted; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | 340 | return $ret; | |||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 20 | ▶ | sub set_logger { | ||||||||||||||||||
|
Subroutine
set_logger: called CC=6 SCAR=21.2
Pod
undocumented
| |||||||||||||||||||||
| 38 | 20 | my ($class, @locations) = @_; | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 20 | my $used_file; | |||||||||||||||||||
| 41 | 20 | ▶ | @locations = () if $ENV{LOGLEVEL}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | 20 | foreach my $conffile (@locations) { | |||||||||||||||||||
| 43 | 0 | ▶ | next unless -e $conffile; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | 0 | Log::Log4perl->init_and_watch($conffile, 1); | |||||||||||||||||||
| 45 | 0 | $logger = Log::Log4perl->get_logger(); | |||||||||||||||||||
| 46 | 0 | $used_file = $conffile; | |||||||||||||||||||
| 47 | 0 | last; | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 20 | ▶ | my $loglevel = $ENV{LOGLEVEL} || "WARN"; | ||||||||||||||||||
|
Condition50%1/2
$ENV{'LOGLEVEL'} || 'WARN'
MC/DC0%0/1
$ENV{'LOGLEVEL'} || 'WARN'
$ENV{'LOGLEVEL'}
Truth table50%1/2
A
A= $ENV{'LOGLEVEL'}
| |||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 20 | ▶ | unless ($used_file) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 53 | 20 | 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 | 20 | Log::Log4perl->init(\$conf); | |||||||||||||||||||
| 67 | 20 | $logger = Log::Log4perl->get_logger(); | |||||||||||||||||||
| 68 | 20 | $used_file = "BUILT-IN-DEFAULTS"; | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 20 | $logger->info("Started logging using '$used_file'"); | |||||||||||||||||||
| 72 | 20 | $has_run++; | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | # Local Variables: | ||||||||||||||||||||
| 76 | # mode: perl | ||||||||||||||||||||
| 77 | # c-basic-indent: 4 | ||||||||||||||||||||
| 78 | # indent-tabs-mode: nil | ||||||||||||||||||||
| 79 | # End: | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 20 | 1; | |||||||||||||||||||