NAME

MooseX::Role::LogHandler - A Logging Role for Moose based on Log::Handler

SYNOPSIS

package MyApp;
use Moose;

# customise log file destination from /tmp/__PACKAGE__.log  
has logfile => ( isa => 'Str', is => 'ro', default => sub { '/tmp/my.log'} ); 
# or more full config
has logconf => ( isa => 'HashRef', is => 'ro', default => sub {{file => {filename => '/tmp/my.log', maxlevel => 'debug'}}});

with 'MooseX::Role::LogHandler';

sub foo {
  my ($self) = @_;
  $self->logger->debug("started bar");    ### logs with default class catergory "MyApp"

}

DESCRIPTION

A logging role building a very lightweight wrapper to Log::Handler for use with your Moose classes.

For compatibility the logger attribute can be accessed to use a common interface for application logging.

ACCESSORS

logger

The logger attribute holds the Log::Handler object that implements all logging methods for the defined log levels, such as debug or error. As this method is defined also in other logging roles/systems like MooseX::Log::LogDispatch this can be thought of as a common logging interface.

package MyApp::View::JSON;
extends 'MyApp::View';

with 'MooseX::Role::LogHandler';

sub bar {
  $self->logger->debug("Something could be crappy here");	     # logs a debug message
  $self->logger->debug("Something else could be crappy here"); # logs a debug message
}

SEE ALSO

Log::Handler, Moose, MooseX::Log::Log4perl, MooseX::LogDispatch

BUGS AND LIMITATIONS

Please report any bugs or feature requests to bug-moosex-loghandler@rt.cpan.org, or through the web interface at http://rt.cpan.org.

Or come bother us in #moose on irc.perl.org.

AUTHOR

NJ Walker <njwalker@cpan.org>

All (inc. most documentation) based on the work by Roland Lammel <lammel@cpan.org> who was in turn inspired by Chris Prather <perigrin@cpan.org> and Ash Berlin <ash@cpan.org> on MooseX::LogDispatch

CONTRIBUTORS

LICENCE AND COPYRIGHT

Copyright (c) 2011-2013, NJ Walker <njwalker@cpan.org>, Some rights reserved.

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