I have a class whose constructor accepts a Log::Dispatch object to send log-messages to.
I would like to write some tests for the logging behavior. I have in mind a specialised subclass of Log::Dispatch::Output which also has test methods.
Before I do any more work on this module, is there already something like this? (I know there are modules to test warnings and output, but I'm looking for something specifically that will hook onto Log::Dispatch and maybe Log::Log4perl.)
The way this module would work is something like:
use Test::Log::Dispatch; use Log::Dispatch;
# log_tester is a reference to a singleton Log::Dispatch::Output # class that collects log messages.
my $log = Log::Dispatch->new()->add(log_tester);
my $obj = Some::Class->new( log => $log );
# Do stuff that one would expect generates log messages
log_ok( { level => 'warn', message => 'ouch' },
"ouch warning");The test takes a hash of log parameters to check against the last log event. If one of them fails, the test fails.
An issue is what kind of interface to implement. I'm thinking aside from log_ok to have log_like() for testing Regexps.
I'm trying to think about the semantics to differentiate between checking if an event has occurred at all vs. checking the last event.
Comments/suggestions appreciated.
Thanks, Rob
