The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Leyland::Logger - Logging facilities for Leyland application

VERSION

version 0.001007

SYNOPSIS

        # if you're planning on creating a new Leyland logger class,
        # then do something like this:

        package Leyland::Logger::SomeLogger;

        use Moose;
        use namespace::autoclean;
        use SomeLogger;

        has 'obj' => (is => 'ro', isa => 'SomeLogger', writer => '_set_obj');

        with 'Leyland::Logger';

        sub init {
                my ($self, $opts) = @_;

                $self->_set_obj(SomeLogger->new(%$opts));
        }

        sub log {
                my ($self, $msg) = @_;

                $self->obj->log(level => $msg->{level}, message => $msg->{message});
        }

        __PACKAGE__->meta->make_immutable;

DESCRIPTION

This Moose role describes how Leyland logger classes, used to log messages generated by the application, are to be built. A logger class will probably use a logger engine, like <Log::Dispatch>, to log messages.

Leyland's default logger class is Leyland::Logger::STDERR, which simply logs messages to the standard error output stream.

ATTRIBUTES

exec

A subroutine reference to be automatically called before printing a log message. This subroutine will receive anything in the "args" attribute, plus the message to log. Not used by default.

args

An array refernce of arguments to pass to the "exec" subroutine.

REQUIRED METHODS

Consuming classes must implement the following methods:

init( \%opts )

Receives whatever options where defined for the logger in the application's configuration hash-ref, and initializes a logger object for usage by the logger class. If initialization is not needed, you can define a method that doesn't do anything.

log( { level => $level, message => $msg } )

Receives a hash-ref with a level string and a message to log, and prints the message to the log, possibly using the object created by the init() method.

METHODS

debug( $msg )

Generates a debug message.

info( $msg )

Generates an info message.

warn( $msg )

Generates a warning message.

error( $msg )

Generates an error message.

set_exec( \&sub, [ @args ] )

Receives a reference to a subroutine and possibly a list of arguments, saves the subroutine as the "exec" attribute and the arguments as the "args" attribute.

has_exec()

Returns a true value if the "exec" attribute has a subroutine reference in it.

clear_exec()

Removes the current value of the "exec" attribute (if any).

has_args()

Returns a true value if the "args" attribute has an array-reference in it.

clear_args()

Removes the current value of the "args" attribute (if any).

AUTHOR

Ido Perlmuter, <ido at ido50.net>

BUGS

Please report any bugs or feature requests to bug-Leyland at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Leyland. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

        perldoc Leyland::Logger

You can also look for information at:

LICENSE AND COPYRIGHT

Copyright 2010-2011 Ido Perlmuter.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.