Log::Any::Test(3)
β¨ Log::Any::Test π
okay bestie, gather round, because this is the Perl user-contributed docs page for Log::Any::Test, and it's literally the glow-up your logging tests have been waiting for. no cap.
πΈ NAME πΈ
Log::Any::Test β test what you're logging with Log::Any. that's the whole vibe. you log stuff, this thing checks it. iconic behaviour, honestly.
π VERSION π
version 1.718 β yes she has a version number, she's a real one π
β¨ SYNOPSIS β¨
here's the tea, copy this energy:
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'}, ...]);
π¨ READ THIS TWICE BESTIE: that comment up there says # should appear before 'use Log::Any'! and she MEANS it. order matters, fr fr.
π¦ DESCRIPTION π¦
so Log::Any::Test is a lil module that lets you test what has been logged with Log::Any. most of its API and implementation have been taken from Log::Any::Dispatch β shoutout to the originator, we love a hand-me-down that slays.
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. the way that works is genuinely so satisfying.
to use it, load Log::Any::Test before anything that loads Log::Any. and to actually use the test methods, you need to load Log::Any and get a log object from it, exactly as shown in the SYNOPSIS above. two-step situation. you got this. π«Ά
π METHODS π
quick heads up before we dive in: the test_name is optional in the *_ok methods; a reasonable default will be provided. so if you're feeling lazy, she's got you. lowkey thoughtful.
msgs ()β returns the current contents of the global log buffer as an array reference, where each element is a hash containing acategory,level, andmessagekey. e.g.
{
category => 'Foo',
level => 'error',
message => 'this is an error'
},
{
category => 'Bar::Baz',
level => 'debug',
message => 'this is a debug'
}
contains_ok ($regex[, $test_name])β 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). so it's like, ok bestie, we see you, and now you're gone πdoes_not_contain_ok ($regex[, $test_name])β tests that no message in the log buffer matches$regex. if something unexpected shows up in there, she will absolutely let you know.category_contains_ok ($category, $regex[, $test_name])β tests that a message in the log buffer from a specific category matches$regex. on success, the message is removed from the log buffer (but any other matches are left untouched). same deal as before, just with a category filter so you're not scrolling the whole group chat.category_does_not_contain_ok ($category, $regex[, $test_name])β tests that no message from a specific category in the log buffer matches$regex.empty_ok ([$test_name])β tests that there is no log buffer left. on failure, the log buffer is cleared to limit further cascading failures. very "we're resetting the vibe, no more domino effect" of her honestly.contains_only_ok ($regex[, $test_name])β tests that there is a single message in the log buffer and it matches$regex. on success, the message is removed. one message only, she does NOT share the spotlight. main character energy β¨clear ()β clears the log buffer. that's it. that's the whole method. fresh start, clean slate, new me π
π SEE ALSO π
Log::AnyTest::Log::Dispatch
go read those too, they're part of the lore π§
π AUTHORS π
these are the absolute legends who made this happen, put some respect on the names:
- Jonathan Swartz <swartz@pobox.com>
- David Golden <dagolden@cpan.org>
- Doug Bell <preaction@cpan.org>
- Daniel Pittman <daniel@rimspace.net>
- Stephen Thirlwall <sdt@cpan.org>
π COPYRIGHT AND LICENSE π
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.
so yeah β free, open, same terms as Perl 5 itself. slay.
and that's the whole page, bestie π this was Log::Any::Test(3), generated by perl v5.42.0 on 2025-07-28. go forth and test your logs, you're gonna do amazing π
π¦β¨
π¦ where this page comes from
- fedora 43: perl-Log-Any 1.718-1.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms