1
2package DJabberd::Log::Junk;
3
4use Log::Log4perl qw(:resurrect);
5
6package DJabberd::Log;
7use strict;
8use warnings;
9
10no warnings 'redefine';
11
12our $has_run;
13our $logger;
14
15sub get_logger {
16    my ($class, $category) = @_;
17    my ($package, $filename, $line) = caller;
18
19    my $autostarted = 0;
20    unless ($has_run) {
21        my @locations = (
22            "etc/log.conf",
23            "/etc/djabberd/log.conf",
24            "etc/log.conf.default"
25        );
26        DJabberd::Log->set_logger(@locations);
27        $autostarted = 1;
28    }
29
30    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    $ret->logwarn("Logger was started on demand from ", $filename, " line ", $line) if $autostarted;
34    return $ret;
35}
36
37sub set_logger {
38    my ($class, @locations) = @_;
39
40    my $used_file;
41    @locations = () if $ENV{LOGLEVEL};
42    foreach my $conffile (@locations) {
43        next unless -e $conffile;
44        Log::Log4perl->init_and_watch($conffile, 1);
45        $logger = Log::Log4perl->get_logger();
46        $used_file = $conffile;
47        last;
48    }
49
50    my $loglevel = $ENV{LOGLEVEL} || "WARN";
51
52    unless ($used_file) {
53        my $conf = qq{
54log4perl.logger.DJabberd = $loglevel, screen
55log4perl.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
60log4perl.logger.DJabberd.Connection.XML = $loglevel
61
62log4perl.appender.screen = Log::Log4perl::Appender::ScreenColoredLevels
63log4perl.appender.screen.layout = Log::Log4perl::Layout::PatternLayout
64log4perl.appender.screen.layout.ConversionPattern = %P %-5p %-40c %m %n
65};
66        Log::Log4perl->init(\$conf);
67        $logger = Log::Log4perl->get_logger();
68        $used_file = "BUILT-IN-DEFAULTS";
69    }
70
71    $logger->info("Started logging using '$used_file'");
72    $has_run++;
73}
74
75# Local Variables:
76# mode: perl
77# c-basic-indent: 4
78# indent-tabs-mode: nil
79# End:
80
811;
82