MooseX::Role::LogHandler - A Logging Role for Moose based on Log::Handler
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" }
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.
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.
debug
error
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 }
Log::Handler, Moose, MooseX::Log::Log4perl, MooseX::LogDispatch
Please report any bugs or feature requests to bug-moosex-loghandler@rt.cpan.org, or through the web interface at http://rt.cpan.org.
bug-moosex-loghandler@rt.cpan.org
Or come bother us in #moose on irc.perl.org.
#moose
irc.perl.org
NJ Walker <njwalker@cpan.org>
<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
<lammel@cpan.org>
<perigrin@cpan.org>
<ash@cpan.org>
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.
To install MooseX::Role::LogHandler, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::Role::LogHandler
CPAN shell
perl -MCPAN -e shell install MooseX::Role::LogHandler
For more information on module installation, please visit the detailed CPAN module installation guide.