Log::Any::Test(3pm) | User Contributed Perl Documentation | Log::Any::Test(3pm) |
Log::Any::Test - Test what you're logging with Log::Any
version 1.713
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.
Using "Log::Any::Test" signals "Log::Any" to send all subsequent log messages to a single global in-memory buffer and to make the log proxy provide a number of testing functions. To use it, load "Log::Any::Test" before anything that loads "Log::Any". To actually use the test methods, you need to load "Log::Any" and get a log object from it, as shown in the "SYNOPSIS".
The test_name is optional in the *_ok methods; a reasonable default will be provided.
{ category => 'Foo', level => 'error', message => 'this is an error' }, { category => 'Bar::Baz', level => 'debug', message => 'this is a debug' }
Log::Any, Test::Log::Dispatch
This software is copyright (c) 2017 by Jonathan Swartz, David Golden, and Doug Bell.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
2023-01-07 | perl v5.36.0 |