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.


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 when they show examples of using "PLUGGABLE CONFIGURATOR" in Log::Dispatch::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.

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 either one (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.

If you don't provide this attribute, we'll default to sending everything to the screen in a reasonable debugging format.


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.


Please report any bugs or feature requests to, or through the web interface at

Or come bother us in #moose on


Ash Berlin <>

Based on work by Chris Prather <>

Thanks to Brandon Black <> for showing me a much nicer way to configure things.


Some development sponsored by Takkle Inc.

Copyright (c) 2007, Ash Berlin <>. Some rights reserved.

Copyright (c) 2007, Chris Prather <>. 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.