$VERSION
=
'1.39'
;
my
%default_reasonToLevel
=
(
TRACE
=>
$DEBUG
,
ASSERT
=>
$DEBUG
,
INFO
=>
$INFO
,
NOTICE
=>
$INFO
,
WARNING
=>
$WARN
,
MISTAKE
=>
$WARN
,
ERROR
=>
$ERROR
,
FAULT
=>
$ERROR
,
ALERT
=>
$FATAL
,
FAILURE
=>
$FATAL
,
PANIC
=>
$FATAL
);
@reasons
==
keys
%default_reasonToLevel
or panic __
"Not all reasons have a default translation"
;
Log::Log4perl->wrapper_register(
$_
)
for
qw/
Log::Report
Log::Report::Dispatcher
Log::Report::Dispatcher::Try
/
;
sub
init($)
{
my
(
$self
,
$args
) =
@_
;
$args
->{
accept
} ||=
'ALL'
;
$self
->SUPER::init(
$args
);
my
$name
=
$self
->name;
$self
->{LRDL_levels} = {
%default_reasonToLevel
};
if
(
my
$to_level
=
delete
$args
->{to_level})
{
my
@to
=
@$to_level
;
while
(
@to
)
{
my
(
$reasons
,
$level
) =
splice
@to
, 0, 2;
my
@reasons
= expand_reasons
$reasons
;
$level
=~ m/^[0-5]$/
or error __x
"Log4perl level '{level}' must be in 0-5"
,
level
=>
$level
;
$self
->{LRDL_levels}{
$_
} =
$level
for
@reasons
;
}
}
if
(
my
$config
=
delete
$args
->{config}) {
Log::Log4perl->init(
$config
) or
return
;
}
$self
;
}
sub
logger(;$)
{
my
(
$self
,
$domain
) =
@_
;
defined
$domain
or
return
Log::Log4perl->get_logger(
$self
->name);
$Log::Log4perl::LOGGERS_BY_NAME
->{
$domain
}
||= Log::Log4perl->get_logger(
$self
->name);
}
sub
log
($$$$)
{
my
(
$self
,
$opts
,
$reason
,
$msg
,
$domain
) =
@_
;
my
$text
=
$self
->translate(
$opts
,
$reason
,
$msg
) or
return
;
my
$level
=
$self
->reasonToLevel(
$reason
);
local
$Log::Log4perl::caller_depth
=
$Log::Log4perl::caller_depth
+ 3;
$text
=~ s/\s+$//s;
$self
->logger(
$domain
)->
log
(
$level
,
$text
);
$self
;
}
sub
reasonToLevel($) {
$_
[0]->{LRDL_levels}{
$_
[1]} }
1;