1MooseX::LazyLogDispatchU(s3e)r Contributed Perl DocumentaMtoioosneX::LazyLogDispatch(3)
2
3
4

NAME

6       MooseX::LazyLogDispatch - A Logging Role for Moose
7

VERSION

9       This document describes MooseX::LazyLogDispatch version 0.01
10

SYNOPSIS

12           package MyApp;
13           use Moose;
14
15           with MooseX::LazyLogDispatch;
16           # or alternately, use this role instead to give your
17           # class the logger methods "debug", "warning", etc...
18           # with MooseX::LazyLogDispatch::Levels;
19
20           # This part optional
21           #  without it you get some default logging to the screen
22           has log_dispatch_conf => (
23              is => 'ro',
24              isa => 'Log::Dispatch::Configurator',
25              lazy => 1,
26              required => 1,
27              default => sub {
28                  my $self = shift;
29                  My::Configurator->new( # <- you write this class!
30                      file => $self->log_file,
31                      debug => $self->debug,
32                  );
33              },
34           );
35
36           # Here's another variant, using a Log::Dispatch::Configurator-style
37           #  hashref to configure things without an explicit subclass
38           has log_dispatch_conf => (
39              is => 'ro',
40              isa => 'HashRef',
41              lazy => 1,
42              required => 1,
43              default => sub {
44                  my $self = shift;
45                  return $self->debug
46                      ? {
47                          class     => 'Log::Dispatch::Screen',
48                          min_level => 'debug',
49                          stderr    => 1,
50                          format    => '[%p] %m at %F line %L%n',
51                      }
52                      : {
53                          class     => 'Log::Dispatch::Syslog',
54                          min_level => 'info',
55                          facility  => 'daemon',
56                          ident     => $self->daemon_name,
57                          format    => '[%p] %m',
58                      };
59              },
60           );
61
62           sub foo {
63               my ($self) = @_;
64               $self->logger->debug("started foo");
65               ....
66               $self->logger->debug('ending foo');
67           }
68

DESCRIPTION

70       Log::Dispatch role for use with your Moose classes.
71

INTERFACE

73   logger
74       This method is provided by this role, and it is an Log::Dispatch
75       instance, which you can call level-names on, as in the debug examples
76       in the synopsis.
77
78       If you want the level-names as direct methods in your class, you should
79       use the MooseX::LazyLogDispatch::Levels role instead.
80
81   log_dispatch_config
82       This is an optional attribute you can give to your class.  If you
83       define it as a hashref value, that will be interpreted in the style of
84       the configuration hashrefs documented in Log::Dispatch::Config
85       documents when they show examples of using Log::Dispatch::Configurator
86       for pluggable configuration.
87
88       You can also gain greater flexibility by defining your own complete
89       Log::Dispatch::Configurator subclass and having your
90       "log_dispatch_config" attribute be an instance of this class.
91
92       By lazy-loading either one ("lazy =" 1>), you can have the
93       configuration determined at runtime.  This is nice if you want to
94       change your log format and/or destination at runtime based on things
95       like MooseX::Getopt / MooseX::Daemonize parameters.
96
97       If you don't provide this attribute, we'll default to sending
98       everything to the screen in a reasonable debugging format.
99

SEE ALSO

101       MooseX::LazyLogDispatch::Levels MooseX::LogDispatch
102       Log::Dispatch::Configurator Log::Dispatch::Config Log::Dispatch
103

AUTHOR

105       Brandon Black "<blblack@gmail.com>"
106
107       Based in part on MooseX::LogDispatch by Ash Berlin "<ash@cpan.org>" and
108       "<perigrin@cpan.org>"
109

LICENCE

111       This module is free software; you can redistribute it and/or modify it
112       under the same terms as Perl itself. See perlartistic.
113
114
115
116perl v5.12.0                      2007-12-21        MooseX::LazyLogDispatch(3)
Impressum