Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Log::Log4perl->remove_logger($logger) to remove a logger from
the system.
- Loading branch information
Showing
4 changed files
with
94 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,56 @@ | |||
# http://stackoverflow.com/questions/5914088 and | |||
# https://github.com/mschilli/log4perl/issues/7 | |||
|
|||
use strict; | |||
use Test::More; | |||
use Log::Log4perl::Appender::TestBuffer; | |||
|
|||
plan tests => 6; | |||
|
|||
use Log::Log4perl qw(get_logger :easy); | |||
|
|||
# $Log::Log4perl::CHATTY_DESTROY_METHODS = 1; | |||
|
|||
my $conf = q( | |||
log4perl.category.main = WARN, LogBuffer | |||
log4perl.category.Bar.Twix = WARN, LogBuffer | |||
log4perl.appender.LogBuffer = Log::Log4perl::Appender::TestBuffer | |||
log4perl.appender.LogBuffer.layout = \ | |||
Log::Log4perl::Layout::PatternLayout | |||
log4perl.appender.LogBuffer.layout.ConversionPattern = %d %F{1} %L> %m %n | |||
); | |||
|
|||
Log::Log4perl::init(\$conf); | |||
|
|||
my $buffer = Log::Log4perl::Appender::TestBuffer->by_name("LogBuffer"); | |||
|
|||
my $logger = get_logger("Bar::Twix"); | |||
|
|||
ok(exists $Log::Log4perl::Logger::LOGGERS_BY_NAME->{"Bar.Twix"}, | |||
"logger exists"); | |||
|
|||
Log::Log4perl->remove_logger( $logger ); | |||
undef $logger; | |||
|
|||
ok(!exists $Log::Log4perl::Logger::LOGGERS_BY_NAME->{"Bar.Twix"}, | |||
"logger gone"); | |||
|
|||
# now remove a stealth logger | |||
$logger = get_logger("main"); | |||
|
|||
ok(exists $Log::Log4perl::Logger::LOGGERS_BY_NAME->{"main"}, | |||
"logger exists"); | |||
|
|||
WARN "before"; | |||
|
|||
Log::Log4perl->remove_logger( $logger ); | |||
undef $logger; | |||
|
|||
ok(!exists $Log::Log4perl::Logger::LOGGERS_BY_NAME->{"main"}, | |||
"logger gone"); | |||
|
|||
# this should be a no-op now. | |||
WARN "after"; | |||
|
|||
like($buffer->buffer, qr/before/, "log message before logger removal present"); | |||
unlike($buffer->buffer, qr/after/, "log message after logger removal absent"); |