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 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.

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.

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.

Note: If you are using a class consuming this one as a role, and plan on reinstantiating that class, its probably a good idea to set this to 1 to avoid errors.


MooseX::LogDispatch::Levels, Log::Dispatch::Configurator, Log::Dispatch::Config, Log::Dispatch.


The old with Logger(...) style has been deprecated in favour of just using one of two roles and making the config much more flexible. As of version 1.2000 of this module, attempting to use it will make your code die.


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

Or come bother us in #moose on


Ash Berlin <> v1.2000 fixes by Mike Whitaker <>

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.