Here is a little snippet I use in tests. It's useful for checking for specific log messages.
use Test::More 'no_plan'; use Test::MockObject; my $mock_logger = Test::MockObject->new; $mock_logger->fake_module('Log::Log4perl', get_logger => sub { $mock_logger } ); @Log::Log4perl::EXPORT_OK = qw( get_logger ); $mock_logger->set_true( qw( debug info warn error fatal )); # execute some code that uses Log::Log4perl... my ( $method, $args ) = $mock_logger->next_call; is( $method, 'debug', 'log is a debug message'); is( $args->[1], 'bomb is ticking', '... with the expected text');