|get_logger($category)||Returns a new instance of Test::Logger that can be used to log expected messages in the category passed.|
|Test::Logger->expect([dotted.path, warn => qrthis, warn => qrthat], ..)||
Class convenience method. Used like this:
|start||Class method. Start logging. When you call this method it temporarly redirects all logging from the standard logging locations to the internal logging routine until end is called. Takes parameters to change the behavior of this (and only this) test. See below.|
|fatal(@what)||Instance methods. String of things that youre expecting to log, at the level youre expecting them, in what class.|
|end($name)||Ends the test and compares what weve got with what we expected. Switches logging back from being captured to going to wherever it was originally directed in the config.|
Sometimes youre going to be testing something that generates a load of spurious log messages that you simply want to ignore without testing their contents, but you dont want to have to reconfigure your log file. The simpliest way to do this is to do:
All logging functions stop working. Do not alter the Logging classes (for example, by changing the config file and use Log4perls init_and_watch functionality) after this call has been made.
This function will be effectivly a no-op if the enviromental variable NO_SUPRESS_LOGGING is set to a true value (so if your code is behaving weirdly you can turn all the logging back on from the command line without changing any of the code)
Its a bad idea to completely ignore all messages. What you probably want to do is ignore some of the trivial messages that you dont care about, and just test that there arent any unexpected messages of a set priority.
You can temporarly ignore any logging messages that are made by passing parameters to the start routine
# for this test, just ignore DEBUG, INFO, and WARN Test::Log4perl->start( ignore_priority => "warn" ); # you can use the levels constants to do the same thing use Log::Log4perl qw(:levels); Test::Log4perl->start( ignore_priority => $WARN );
You might want to ignore all logging events at all (this can be used as quick way to not test the actual log messages, but just ignore the output.
# for this test, ignore everything Test::Log4perl->start( ignore_priority => "everything" ); # contary to readability, the same thing (try not to write this) use Log::Log4perl qw(:levels); Test::Log4perl->start( ignore_priority => $OFF );
Or you might want to not ignore anything (which is the default, unless youve played with the method calls mentioned below:)
# for this test, ignore nothing Test::Log4perl->start( ignore_priority => "nothing" ); # contary to readability, the same thing (try not to write this) use Log::Log4perl qw(:levels); Test::Log4perl->start( ignore_priority => $ALL );
You can also perminatly effect what things are ignored with the ignore_priority method call. This persists between tests and isnt autoically reset after each call to start.
# ignore DEBUG, INFO and WARN for all future tests Test::Log4perl->ignore_priority("warn"); # you can use the levels constants to do the same thing use Log::Log4perl qw(:levels); Test::Log4perl->ignore_priority($WARN); # ignore everything (no log messages will be logged) Test::Log4perl->ignore_priority("everything"); # ignore nothing (messages will be logged reguardless of priority) Test::Log4perl->ignore_priority("nothing");
Obviously, you may temporarly override whatever perminant
Logging methods dont return the number of appenders theyve written to (or rather, they do, as its always zero.)
Mark Fowler <firstname.lastname@example.org>
Copyright 2005 Fotango Ltd all rights reserved. Licensed under the same terms as Perl itself.
|perl v5.20.3||TEST::LOG4PERL (3)||2006-08-07|