in reply to Logger object access to different modules
################################################## sub get_logger { # Get an instance (shortcut) ################################################## # get_logger() can be called in the following ways: # # (1) Log::Log4perl::get_logger() => () # (2) Log::Log4perl->get_logger() => ("Log::Log4perl") # (3) Log::Log4perl::get_logger($cat) => ($cat) # # (5) Log::Log4perl->get_logger($cat) => ("Log::Log4perl", $cat) # (6) L4pSubclass->get_logger($cat) => ("L4pSubclass", $cat) # Note that (4) L4pSubclass->get_logger() => ("L4pSubclass") # is indistinguishable from (3) and therefore can't be allowed. # Wrapper classes always have to specify the category explicitely. my $category; if(@_ == 0) { # 1 my $level = 0; do { $category = scalar caller($level++); } while exists $WRAPPERS_REGISTERED{ $category }; } elsif(@_ == 1) { # 2, 3 $category = $_[0]; my $level = 0; while(exists $WRAPPERS_REGISTERED{ $category }) { $category = scalar caller($level++); } } else { # 5, 6 $category = $_[1]; } # Delegate this to the logger module return Log::Log4perl::Logger->get_logger($category); }
|
---|