NAME
MooseX::Role::Loggable - Extensive, yet simple, logging role using Log::Dispatchouli
VERSION
version 0.007
SYNOPSIS
package My::Object;
use Moose;
with 'MooseX::Role::Loggable';
sub do_this {
my $self = shift;
$self->set_prefix('[do_this] ');
$self->log_debug('starting...');
...
$self->log_debug('more stuff');
$self->clear_prefix;
}
DESCRIPTION
This is a role to provide logging ability to whoever consumes it using Log::Dispatchouli. Once you consume this role, you have the attributes and methods documented below.
You can propagate your logging definitions to another object that uses MooseX::Role::Loggable using the log_fields
attribute as such:
package Parent;
use Any::Moose;
use MooseX::Role::Loggable; # picking Mouse or Moose
has child => (
is => 'ro',
isa => 'Child',
lazy_build => 1,
);
sub _build_child {
my $self = shift;
return Child->new( $self->log_fields );
}
This module uses Any::Moose so you can use it with Moose or Mouse.
ATTRIBUTES
debug
A boolean for whether you're in debugging mode or not.
Default: no.
Read-only.
logger_facility
The facility the logger would use. This is useful for syslog.
Default: local6.
logger_ident
The ident the logger would use. This is useful for syslog.
Default: MooseX::Role::Loggable.
Read-only.
log_to_file
A boolean that determines if the logger would log to a file.
Default location of the file is in /tmp.
Default: no.
Read-only.
log_to_stdout
A boolean that determines if the logger would log to STDOUT.
Default: no.
log_to_stderr
A boolean that determines if the logger would log to STDERR.
Default: no.
log_file
The leaf name for the log file.
Default: undef
log_path
The path for the log file.
Default: undef
log_pid
Whether to append the PID to the log filename.
Default: yes
log_fail_fatal
Whether failure to log is fatal.
Default: yes
log_muted
Whether only fatals are logged.
Default: no
log_quiet_fatal
From Log::Dispatchouli: 'stderr' or 'stdout' or an arrayref of zero, one, or both fatal log messages will not be logged to these.
Default: stderr
log_fields
A hash of the fields definining how logging is being done.
This is very useful when you want to propagate your logging onwards to another object which uses MooseX::Role::Loggable.
It will return the following attributes and their values in a hash: debug
, debug
, logger_facility
, logger_ident
, log_to_file
, log_to_stdout
, log_to_stderr
, log_file
, log_path
, log_pid
, log_fail_fatal
, log_muted
, log_quiet_fatal
.
logger
A Log::Dispatchouli object.
METHODS
All methods here are imported from Log::Dispatchouli. You can read its documentation to understand them better.
log
Log a message.
log_debug
Log a message only if in debug mode.
log_fatal
Log a message and die.
set_debug
Set the debug flag.
clear_debug
Clear the debug flag.
set_prefix
Set a prefix for all next messages.
clear_prefix
Clears the prefix for all next messages.
set_muted
Sets the mute property, which makes only fatal messages logged.
clear_muted
Clears the mute property.
AUTHOR
Sawyer X <xsawyerx@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Sawyer X.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.