# perldoc > Log::Any::Test

## NAME
    [Log::Any::Test](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny%3A%3ATest/markdown) - Test what you're logging with [Log::Any](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny/markdown)

## VERSION
    version 1.717

## SYNOPSIS
        use [Test::More](https://www.chedong.com/phpMan.php/perldoc/Test%3A%3AMore/markdown);
        use [Log::Any::Test](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny%3A%3ATest/markdown);    # should appear before 'use [Log::Any](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny/markdown)'!
        use [Log::Any](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny/markdown) qw($log);

        # ...
        # call something that logs using [Log::Any](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny/markdown)
        # ...

        # 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'}, ...]);

## DESCRIPTION
    "[Log::Any::Test](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny%3A%3ATest/markdown)" is a simple module that allows you to test what has been logged with [Log::Any](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny/markdown).
    Most of its API and implementation have been taken from [Log::Any::Dispatch](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny%3A%3ADispatch/markdown).

    Using "[Log::Any::Test](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny%3A%3ATest/markdown)" signals "[Log::Any](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny/markdown)" 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](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny%3A%3ATest/markdown)" before anything that loads "[Log::Any](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny/markdown)". To actually use the test methods,
    you need to load "[Log::Any](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny/markdown)" and get a log object from it, as shown in the "SYNOPSIS".

## METHODS
    The test_name is optional in the *_ok methods; a reasonable default will be provided.

    msgs ()
        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](https://www.chedong.com/phpMan.php/perldoc/Bar%3A%3ABaz/markdown)',
            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).

    does_not_contain_ok ($regex[, $test_name])
        Tests that no message in the log buffer matches *$regex*.

    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).

    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.

    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.

    clear ()
        Clears the log buffer.

## SEE ALSO
    [Log::Any](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny/markdown), [Test::Log::Dispatch](https://www.chedong.com/phpMan.php/perldoc/Test%3A%3ALog%3A%3ADispatch/markdown)

## AUTHORS
    *   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.

