MooseX::LogDispatch - A Logging Role for Moose
This document describes MooseX::LogDispatch version 1.1000
package MyApp; use Moose; with MooseX::LogDispatch; # or # with MooseX::LogDispatch::Levels # This is optional. Will log to screen if not provided has log_dispatch_conf => ( is => 'ro', lazy => 1, default => sub { my $self = shift; My::Configurator->new( # <- you write this class! file => $self->log_file, debug => $self->debug, ); } ); # This is the same as the old FileBased config parameter to the role. If you # prefer you could name the attribute 'config_filename' instead. has log_dispatch_conf => ( is => 'ro', lazy => 1, default => "/path/to/my/logger.conf" ); # Here's another variant, using a Log::Dispatch::Configurator-style # hashref to configure things without an explicit subclass has log_dispatch_conf => ( is => 'ro', isa => 'HashRef', lazy => 1, required => 1, default => sub { my $self = shift; return $self->debug ? { class => 'Log::Dispatch::Screen', min_level => 'debug', stderr => 1, format => '[%p] %m at %F line %L%n', } : { class => 'Log::Dispatch::Syslog', min_level => 'info', facility => 'daemon', ident => $self->daemon_name, format => '[%p] %m', }; }, ); sub foo { my ($self) = @_; $self->logger->debug("started foo"); .... $self->logger->debug('ending foo'); }
Log::Dispatch role for use with your Moose classes.
This is the main Log::Dispatch::Config object that does all the work. It has methods for each of the log levels, such as debug or error.
debug
error
This is an optional attribute you can give to your class. If you define it as a hashref value, that will be interpreted in the style of the configuration hashrefs documented in Log::Dispatch::Config documents where they show examples of using a PLUGGABLE CONFIGURATOR for pluggable configuration.
You can also gain greater flexibility by defining your own complete Log::Dispatch::Configurator subclass and having your log_dispatch_config attribute be an instance of this class.
log_dispatch_config
If this attribute has a value of a string, it will be taken to by the path to a config file for Log::Dispatch::Configurator::AppConfig.
By lazy-loading this attribute (lazy => 1), you can have the configuration determined at runtime. This is nice if you want to change your log format and/or destination at runtime based on things like MooseX::Getopt / MooseX::Daemonize parameters.
lazy => 1
If you don't provide this attribute, we'll default to sending everything to the screen in a reasonable debugging format.
If this attribute has a true value, and Log::Dispatch::Config has a configured log instance, this will be used in preference to anything set via log_dispatch_config.
The main use for this attribute is when you want to use this module in another library module - i.e. the consumer of this role is not the end user. Setting this attribute to true makes it much easier for the end user to configure logging.
MooseX::LogDispatch::Levels, Log::Dispatch::Configurator, Log::Dispatch::Config, Log::Dispatch.
The old with Logger(...) style has been depreacted in favour of just using one of two roles and making the config much more flexible. To remove the warning notice, set the MX_LOGDISPATCH_NO_DEPRECATION environment variable to true.
with Logger(...)
MX_LOGDISPATCH_NO_DEPRECATION
Please report any bugs or feature requests to bug-moosex-logdispatch@rt.cpan.org, or through the web interface at http://rt.cpan.org.
bug-moosex-logdispatch@rt.cpan.org
Or come bother us in #moose on irc.perl.org.
#moose
irc.perl.org
Ash Berlin <ash@cpan.org>
<ash@cpan.org>
Based on work by Chris Prather <perigrin@cpan.org>
<perigrin@cpan.org>
Thanks to Brandon Black <blblack@gmail.com> for showing me a much nicer way to configure things.
<blblack@gmail.com>
Some development sponsored by Takkle Inc.
Copyright (c) 2007, Ash Berlin <ash@cpan.org>. Some rights reserved.
Copyright (c) 2007, Chris Prather <perigrin@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::LogDispatch, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::LogDispatch
CPAN shell
perl -MCPAN -e shell install MooseX::LogDispatch
For more information on module installation, please visit the detailed CPAN module installation guide.