The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Log::Any::Adapter::TAP - Logging adapter suitable for use in TAP testcases

VERSION

version 0.002000_00

DESCRIPTION

When running testcases, you probably want to see some of your logging output. One sensible approach is to have all warn and more serious messages emitted as diag output on STDERR, and less serious messages emitted as note comments on STDOUT.

So, thats what this logging adapter does. Simply say

  use Log::Any::Adapter 'TAP';

at the start of your testcase, and now you have your logging output as part of your TAP stream.

By default, debug and trace are suppressed, but you can enable them with TAP_LOG_FILTER. See below.

ENVIRONMENT

ENV{TAP_LOG_FILTER}

Specify the lowest log level which should be suppressed. The default is debug, which suppresses debug and trace messages. A value of "none" enables all logging levels.

If you want to affect specific logging categories use a notation like

  TAP_LOG_FILTER=trace,MyPackage=none,NoisyPackage=warn prove -lv

The filter level may end with a "+N" or "-N" indicating an offset from the named level, so debug-1 is equivalent to trace and debug+1 is equivalent to info.

ENV{TAP_LOG_ORIGIN}

Set this variable to 1 to show which category the message came from, or 2 to see the file and line number it came from, or 3 to see both.

ENV{TAP_LOG_SHOW_USAGE}

Defaults to true, which prints a #note on stdout describing these environment variables when Log::Any::Adapter::TAP is first loaded.

Set TAP_LOG_SHOW_USAGE=0 to suppress this message.

ATTRIBUTES

filter

  use Log::Any::Adapter 'TAP', filter => 'info';
  use Log::Any::Adapter 'TAP', filter => 'debug+3';

Messages equal to or less than the level of filter are suppressed.

The default filter is 'debug', meaning debug and trace are suppressed.

filter may be:

  • a level name like 'info', 'debug', etc, or a level alias as documented in Log::Any.

  • undef, or the string 'none', which do not suppress anything

  • a level name with a numeric offset, where a number will be added or subtracted from the log level. Larger numbers are for more important levels, so debug+1 is equivalent to info

dumper

  use Log::Any::Adapter 'TAP', dumper => sub { my $val=shift; ... };

Use a custom dumper function for converting perl data to strings. The dumper is only used for the "*f()" formatting functions, and for log levels 'debug' and 'trace'. All normal logging will stringify the object in the normal way.

METHODS

new

See "new" in Log::Any::Adapter::Base. Accepts the above attributes.

write_msg

  $self->write_msg( $level_name, $message_string )

This is an internal method which all the other logging methods call. You can override it if you want to create a derived logger that handles line wrapping differently, or write to different file handles.

_default_dumper

  $string = _default_dumper( $perl_data );

This is a function which dumps a value in a human readable format. Currently it uses Data::Dumper with a max depth of 4, but might change in the future.

This is the default value for the 'dumper' attribute.

AUTHOR

Michael Conrad <mike@nrdvana.net>

COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Michael Conrad.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.