NAME

Test::Smoke::LogMixin - "Role" that adds logging methods to "traditional" objects.

SYNOPSIS

package MyPackage;
use warnings;
use strict;
use Test::Smoke::LogMixin;

sub new {
    my $class = shift;
    my %selfish = @_;
    $selfish{_verbose} ||= 0;
    return bless \%selfish, $class;
}
1;

package main;
use MyPackage;
my $o = MyPackage->new(_verbose => 2);
$o->log_debug("This will end up in the log");

DESCRIPTION

This package with these mixin-methods acts like a role to extend your traditional (created with bless()) object with 4 new methods. It has some extra Test::Smoke::App::Base logic to determine the log-level (by looking at $app->option('verbose')). For other object types it tries to fiend if there are methods by the name verbose or v, or maybe the keys _verbose or _v (See also Test::Smoke::ObjectBase).

The three log methods use the sprintf() way of composing strings whenever more than 1 argument is passed!

$app->verbosity

Return the verbosity of this app.

Arguments

None.

Returns

The value of either _verbose or _v

$app->log_warn($fmt, @values)

prinf $fmt, @values to the currently selected filehandle.

Arguments

Positional.

$fmt => a (s)printf format

The format gets an extra new line if one wasn't present.

@values => optional vaules for the template.

Returns

use in void context.

Exceptions

None.

$app->log_info($fmt, @values)

prinf $fmt, @values to the currently selected filehandle if the 'verbose' option is set.

Arguments

Positional.

$fmt => a (s)printf format

The format gets an extra new line if one wasn't present.

@values => optional vaules for the template.

Returns

use in void context.

Exceptions

None.

$app->log_debug($fmt, @values)

prinf $fmt, @values to the currently selected filehandle if the 'verbose' option is set to a value > 1.

Arguments

Positional.

$fmt => a (s)printf format

The format gets an extra new line if one wasn't present.

@values => optional vaules for the template.

Returns

use in void context.

Exceptions

None.

NAME

Test::Smoke::Logger - Helper object for logging.

SYNOPSIS

use Test::Smoke::LogMixin;
my $logger = Test::Smoke::Logger->new(v => 1);
$logger->log_warn("Minimal log level"); # v >= 0
$logger->log_info("Medium log level");  # v <= 1
$logger->log_debug("High log level");   # v >  1

DESCRIPTION

Test::Smoke::Logger->new(%arguments)

Return a logger instance.

Arguments

Named, hash:

v => <0|1|2>

Returns

The Test::Smoke::Logger instance.

COPYRIGHT

(c) 2020, All rights reserved.

* Abe Timmerman <abeltje@cpan.org>

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

See:

* <http://www.perl.com/perl/misc/Artistic.html>,
* <http://www.gnu.org/copyleft/gpl.html>

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.