6 |
use Log::Log4perl qw/get_logger :levels/; |
use Log::Log4perl qw/get_logger :levels/; |
7 |
use Time::HiRes qw/time/; |
use Time::HiRes qw/time/; |
8 |
|
|
9 |
|
# If ture, enable logging debug |
10 |
|
my $log_debug = 0; |
11 |
|
|
12 |
=head1 NAME |
=head1 NAME |
13 |
|
|
14 |
WebPAC::Common - internal methods called from other WebPAC modules |
WebPAC::Common - internal methods called from other WebPAC modules |
142 |
will be created. If any mode which inherits from this one is called |
will be created. If any mode which inherits from this one is called |
143 |
with C<debug> flag, it will turn logging to debug level. |
with C<debug> flag, it will turn logging to debug level. |
144 |
|
|
145 |
|
This function will also read C<log_conf> value from current object and try |
146 |
|
to read that as configuration file if it exists. |
147 |
|
|
148 |
=cut |
=cut |
149 |
|
|
150 |
sub _init_logger { |
sub _init_logger { |
151 |
my $self = shift; |
my $self = shift; |
152 |
my $file = shift; |
my $file = shift; |
153 |
|
$file ||= $self->{'log_conf'}; |
154 |
|
$file = 'conf/log.conf'; |
155 |
|
my $name = (caller(2))[3] || caller; |
156 |
if ($file) { |
if ($file) { |
157 |
|
warn "# $name is using $file logger\n" if ($log_debug); |
158 |
Log::Log4perl->init($file); |
Log::Log4perl->init($file); |
159 |
} else { |
} else { |
160 |
my $conf = q( ); |
my $conf = q( ); |
170 |
log4perl.appender.SCREEN.layout.ConversionPattern=%d %p> %F{1}:%L %M - %m%n |
log4perl.appender.SCREEN.layout.ConversionPattern=%d %p> %F{1}:%L %M - %m%n |
171 |
|
|
172 |
_log4perl_ |
_log4perl_ |
173 |
|
warn "# $name is using debug logger\n" if ($log_debug); |
174 |
|
} else { |
175 |
|
warn "# $name is using null logger\n" if ($log_debug); |
176 |
} |
} |
177 |
Log::Log4perl->init( \$conf ); |
Log::Log4perl->init( \$conf ); |
178 |
} |
} |
191 |
sub _get_logger { |
sub _get_logger { |
192 |
my $self = shift; |
my $self = shift; |
193 |
|
|
194 |
$self->{'_logger_ok'} ||= $self->_init_logger; |
my $name = (caller(2))[3] || caller; |
195 |
|
$self->{'_logger_'} ||= $self->_init_logger; |
196 |
|
|
197 |
|
warn "# get_logger( $name )\n" if ($log_debug); |
198 |
|
|
|
my $name = (caller(1))[3] || caller; |
|
199 |
return get_logger($name); |
return get_logger($name); |
200 |
} |
} |
201 |
|
|