1MooseX::LogDispatch(3)User Contributed Perl DocumentationMooseX::LogDispatch(3)
2
3
4
6 MooseX::LogDispatch - A Logging Role for Moose
7
9 This document describes MooseX::LogDispatch version 1.1000
10
12 package MyApp;
13 use Moose;
14 with 'MooseX::LogDispatch';
15 # or
16 # with 'MooseX::LogDispatch::Levels'
17
18 # This is optional. Will log to screen if not provided
19 has log_dispatch_conf => (
20 is => 'ro',
21 lazy => 1,
22 default => sub {
23 my $self = shift;
24 My::Configurator->new( # <- you write this class!
25 file => $self->log_file,
26 debug => $self->debug,
27 );
28
29 }
30 );
31
32 # This is the same as the old FileBased config parameter to the role. If you
33 # prefer you could name the attribute 'config_filename' instead.
34 has log_dispatch_conf => (
35 is => 'ro',
36 lazy => 1,
37 default => "/path/to/my/logger.conf"
38 );
39
40 # Here's another variant, using a Log::Dispatch::Configurator-style
41 # hashref to configure things without an explicit subclass
42 has log_dispatch_conf => (
43 is => 'ro',
44 isa => 'HashRef',
45 lazy => 1,
46 required => 1,
47 default => sub {
48 my $self = shift;
49 return $self->debug ?
50 {
51 class => 'Log::Dispatch::Screen',
52 min_level => 'debug',
53 stderr => 1,
54 format => '[%p] %m at %F line %L%n',
55 }
56 : {
57 class => 'Log::Dispatch::Syslog',
58 min_level => 'info',
59 facility => 'daemon',
60 ident => $self->daemon_name,
61 format => '[%p] %m',
62 };
63 },
64 );
65
66
67 sub foo {
68 my ($self) = @_;
69 $self->logger->debug("started foo");
70 ....
71 $self->logger->debug('ending foo');
72 }
73
75 Log::Dispatch role for use with your Moose classes.
76
78 logger
79 This is the main Log::Dispatch::Config object that does all the work.
80 It has methods for each of the log levels, such as "debug" or "error".
81
82 log_dispatch_conf
83 This is an optional attribute you can give to your class. If you
84 define it as a hashref value, that will be interpreted in the style of
85 the configuration hashrefs documented in Log::Dispatch::Config
86 documents where they show examples of using a PLUGGABLE CONFIGURATOR
87 for pluggable configuration.
88
89 You can also gain greater flexibility by defining your own complete
90 Log::Dispatch::Configurator subclass and having your
91 "log_dispatch_config" attribute be an instance of this class.
92
93 If this attribute has a value of a string, it will be taken to by the
94 path to a config file for Log::Dispatch::Configurator::AppConfig.
95
96 By lazy-loading this attribute ("lazy => 1"), you can have the
97 configuration determined at runtime. This is nice if you want to
98 change your log format and/or destination at runtime based on things
99 like MooseX::Getopt / MooseX::Daemonize parameters.
100
101 If you don't provide this attribute, we'll default to sending
102 everything to the screen in a reasonable debugging format.
103
104 use_logger_singleton
105 If this attribute has a true value, and Log::Dispatch::Config has a
106 configured log instance, this will be used in preference to anything
107 set via "log_dispatch_config".
108
109 The main use for this attribute is when you want to use this module in
110 another library module - i.e. the consumer of this role is not the end
111 user. Setting this attribute to true makes it much easier for the end
112 user to configure logging.
113
114 Note: If you are using a class consuming this one as a role, and plan
115 on reinstantiating that class, its probably a good idea to set this to
116 1 to avoid errors.
117
119 MooseX::LogDispatch::Levels, Log::Dispatch::Configurator,
120 Log::Dispatch::Config, Log::Dispatch.
121
123 The old "with Logger(...)" style has been deprecated in favour of just
124 using one of two roles and making the config much more flexible. As of
125 version 1.2000 of this module, attempting to use it will make your code
126 die.
127
129 Please report any bugs or feature requests to
130 "bug-moosex-logdispatch@rt.cpan.org", or through the web interface at
131 <http://rt.cpan.org>.
132
133 Or come bother us in "#moose" on "irc.perl.org".
134
136 Ash Berlin "<ash@cpan.org>" v1.2000 fixes by Mike Whitaker
137 "<penfold@cpan.org>"
138
139 Based on work by Chris Prather "<perigrin@cpan.org>"
140
141 Thanks to Brandon Black "<blblack@gmail.com>" for showing me a much
142 nicer way to configure things.
143
145 Some development sponsored by Takkle Inc.
146
147 Copyright (c) 2007, Ash Berlin "<ash@cpan.org>". Some rights reserved.
148
149 Copyright (c) 2007, Chris Prather "<perigrin@cpan.org>". Some rights
150 reserved.
151
152 This module is free software; you can redistribute it and/or modify it
153 under the same terms as Perl itself. See perlartistic.
154
155
156
157perl v5.28.0 2010-04-18 MooseX::LogDispatch(3)