--- trunk/lib/WebPAC/Common.pm 2005/07/17 10:42:23 15 +++ trunk/lib/WebPAC/Common.pm 2005/07/24 15:07:56 32 @@ -3,7 +3,11 @@ use warnings; use strict; -use Log::Log4perl qw(get_logger :levels); +use Log::Log4perl qw/get_logger :levels/; +use Time::HiRes qw/time/; + +# If ture, enable logging debug +my $log_debug = 0; =head1 NAME @@ -138,17 +142,28 @@ will be created. If any mode which inherits from this one is called with C flag, it will turn logging to debug level. +This function will also read C value from current object and try +to read that as configuration file if it exists, if it doesn't it will +fallback to default C. + +You can disable all logging by adding C to constructor of WebPAC +object. Object in C class will disable logging +automatically. + =cut sub _init_logger { my $self = shift; my $file = shift; - if ($file) { - Log::Log4perl->init($file); - } else { - my $conf = q( ); - if ($self->{'debug'}) { - $conf = << '_log4perl_'; + $file ||= $self->{'log_conf'}; + $file = 'conf/log.conf'; + my $name = (caller(2))[3] || caller; + + my $conf = q( ); + if ($self->{'no_log'}) { + warn "# $name disabled logging\n" if ($log_debug); + } elsif ($self->{'debug'}) { + $conf = << '_log4perl_'; log4perl.rootLogger=INFO, SCREEN @@ -159,9 +174,18 @@ log4perl.appender.SCREEN.layout.ConversionPattern=%d %p> %F{1}:%L %M - %m%n _log4perl_ - } - Log::Log4perl->init( \$conf ); + warn "# $name is using debug logger\n" if ($log_debug); + } elsif ($name !~ m/Test::Exception/o) { + warn "# disabled logging for Text::Exception\n" if ($log_debug); + } elsif ($file) { + warn "# $name is using $file logger\n" if ($log_debug); + Log::Log4perl->init($file); + } else { + warn "# $name is using null logger\n" if ($log_debug); } + Log::Log4perl->init( \$conf ); + + return 1; } @@ -177,9 +201,11 @@ sub _get_logger { my $self = shift; - $self->{'_logger_ok'} ||= $self->_init_logger; + my $name = (caller(2))[3] || caller; + $self->{'_logger_'} ||= $self->_init_logger; + + warn "# get_logger( $name )\n" if ($log_debug); - my $name = (caller(1))[3] || caller; return get_logger($name); }