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

Datahub::Factory::Logger - A role for classes that need logging capabilities

SYNOPSIS

    package MyApp::View;
    use Moo;

    with 'Datahub::Factory::Logger';

    sub something {
        my ($self) = @_;
        $self->log->debug("started bar"); # logs with default class catergory "MyApp::View"
        $self->log->error("started bar");
    }

DESCRIPTION

A logging role building a very lightweight wrapper to Log::Any. Connecting a Log::Any::Adapter should be performed prior to logging the first log message, otherwise nothing will happen, just like with Log::Any.

The logger needs to be setup before using the logger, which could happen in the main application:

    package main;
    use Log::Any::Adapter;
    use Log::Log4perl;

    Log::Any::Adapter->set('Log4perl');
    Log::Log4perl::init('./log4perl.conf');

    my $app = MyApp::View->new;
    $app->something();  # will print debug and error messages

with log4perl.conf like:

    log4perl.rootLogger=DEBUG,OUT
    log4perl.appender.OUT=Log::Log4perl::Appender::Screen
    log4perl.appender.OUT.stderr=1
    log4perl.appender.OUT.utf8=1

    log4perl.appender.OUT.layout=PatternLayout
    log4perl.appender.OUT.layout.ConversionPattern=%d [%P] - %p %l time=%r : %m%n

See Log::Log4perl for more configuration options and selecting which messages to log and which not.

DATAHUB FACTORY COMMAND LINE

When using the dhconveyor command line, the logger can be activated using the -D option on all Datahub Factory commands:

     $ dhconveyor -D transport ...

METHODS

Log::Any

ACKNOWLEDGMENTS

Code and documentation blatantly stolen from Catmandu who got it from MooX::Log::Any.