| Log-Any documentation | Contained in the Log-Any distribution. |
Log::Any::Test -- Test what you're logging with Log::Any
version 0.12
use Test::More;
use Log::Any::Test; # should appear before 'use Log::Any'!
use Log::Any qw($log);
# ...
# call something that logs using Log::Any
# ...
# now test to make sure you logged the right things
$log->contains_ok(qr/good log message/, "good message was logged");
$log->does_not_contain_ok(qr/unexpected log message/, "unexpected message was not logged");
$log->empty_ok("no more logs");
# or
my $msgs = $log->msgs;
cmp_deeply($msgs, [{message => 'msg1', level => 'debug'}, ...]);
Log::Any::Test is a simple module that allows you to test what has been
logged with Log::Any. Most of its API and implementation have been taken from
Log::Any::Dispatch (Log::Any::Dispatch).
Using Log::Any::Test sends all subsequent Log::Any log messages to a single
global in-memory buffer. It should be used before Log::Any.
The test_name is optional in the *_ok methods; a reasonable default will be provided.
Returns the current contents of the global log buffer as an array reference, where each element is a hash containing a category, level, and message key. e.g.
{
category => 'Foo',
level => 'error',
message => 'this is an error'
},
{
category => 'Bar::Baz',
level => 'debug',
message => 'this is a debug'
}
Tests that a message in the log buffer matches $regex. On success, the message is removed from the log buffer (but any other matches are left untouched).
Tests that no message in the log buffer matches $regex.
Tests that there is no log buffer left. On failure, the log buffer is cleared to limit further cascading failures.
Tests that there is a single message in the log buffer and it matches $regex. On success, the message is removed.
Clears the log buffer.
Jonathan Swartz
Copyright (C) 2009 Jonathan Swartz, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
This software is copyright (c) 2011 by Jonathan Swartz.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
| Log-Any documentation | Contained in the Log-Any distribution. |
package Log::Any::Test; BEGIN { $Log::Any::Test::VERSION = '0.12'; } use strict; use warnings; # 'use Log::Any::Test' just defines a test version of Log::Any::Adapter. # package Log::Any::Adapter; BEGIN { $Log::Any::Adapter::VERSION = '0.12'; } use Log::Any::Adapter::Test; use strict; use warnings; our $Initialized = 1; # Eliminate 'subroutine redefined' warning in case Log::Any::Adapter already loaded # BEGIN { no strict 'refs'; delete 'Log::Any::Adapter::'->{get_logger} } sub get_logger { my ( $self, $category ) = @_; return Log::Any::Adapter::Test->new( category => $category ); } 1; __END__