1Log::Dispatchouli(3)  User Contributed Perl Documentation Log::Dispatchouli(3)
2
3
4

NAME

6       Log::Dispatchouli - a simple wrapper around Log::Dispatch
7

VERSION

9       version 2.016
10

SYNOPSIS

12         my $logger = Log::Dispatchouli->new({
13           ident     => 'stuff-purger',
14           facility  => 'daemon',
15           to_stdout => $opt->{print},
16           debug     => $opt->{verbose}
17         });
18
19         $logger->log([ "There are %s items left to purge...", $stuff_left ]);
20
21         $logger->log_debug("this is extra often-ignored debugging log");
22
23         $logger->log_fatal("Now we will die!!");
24

DESCRIPTION

26       Log::Dispatchouli is a thin layer above Log::Dispatch and meant to make
27       it dead simple to add logging to a program without having to think much
28       about categories, facilities, levels, or things like that.  It is meant
29       to make logging just configurable enough that you can find the logs you
30       want and just easy enough that you will actually log things.
31
32       Log::Dispatchouli can log to syslog (if you specify a facility),
33       standard error or standard output, to a file, or to an array in memory.
34       That last one is mostly useful for testing.
35
36       In addition to providing as simple a way to get a handle for logging
37       operations, Log::Dispatchouli uses String::Flogger to process the
38       things to be logged, meaning you can easily log data structures.
39       Basically: strings are logged as is, arrayrefs are taken as (sprintf
40       format, args), and subroutines are called only if needed.  For more
41       information read the String::Flogger docs.
42

METHODS

44   new
45         my $logger = Log::Dispatchouli->new(\%arg);
46
47       This returns a new logger, a Log::Dispatchouli object.
48
49       Valid arguments are:
50
51         ident       - the name of the thing logging (mandatory)
52         to_self     - log to the logger object for testing; default: false
53         to_stdout   - log to STDOUT; default: false
54         to_stderr   - log to STDERR; default: false
55         facility    - to which syslog facility to send logs; default: none
56
57         to_file     - log to PROGRAM_NAME.YYYYMMDD in the log path; default: false
58         log_file    - a leaf name for the file to log to with to_file
59         log_path    - path in which to log to file; defaults to DISPATCHOULI_PATH
60                       environment variable or, failing that, to your system's tmpdir
61
62         file_format - this optional coderef is passed the message to be logged
63                       and returns the text to write out
64
65         log_pid     - if true, prefix all log entries with the pid; default: true
66         fail_fatal  - a boolean; if true, failure to log is fatal; default: true
67         muted       - a boolean; if true, only fatals are logged; default: false
68         debug       - a boolean; if true, log_debug method is not a no-op
69                       defaults to the truth of the DISPATCHOULI_DEBUG env var
70         quiet_fatal - 'stderr' or 'stdout' or an arrayref of zero, one, or both
71                       fatal log messages will not be logged to these
72                       (default: stderr)
73         config_id   - a name for this logger's config; rarely needed!
74
75       The log path is either /tmp or the value of the DISPATCHOULI_PATH env
76       var.
77
78       If the DISPATCHOULI_NOSYSLOG env var is true, we don't log to syslog.
79
80   log
81         $logger->log(@messages);
82
83         $logger->log(\%arg, @messages);
84
85       This method uses String::Flogger on the input, then unconditionally
86       logs the result.  Each message is flogged individually, then joined
87       with spaces.
88
89       If the first argument is a hashref, it will be used as extra arguments
90       to logging.  It may include a "prefix" entry to preprocess the message
91       by prepending a string (if the prefix is a string) or calling a
92       subroutine to generate a new message (if the prefix is a coderef).
93
94   log_fatal
95       This behaves like the "log" method, but will throw the logged string as
96       an exception after logging.
97
98       This method can also be called as "fatal", to match other popular
99       logging interfaces.  If you want to override this method, you must
100       override "log_fatal" and not "fatal".
101
102   log_debug
103       This behaves like the "log" method, but will only log (at the debug
104       level) if the logger object has its debug property set to true.
105
106       This method can also be called as "debug", to match other popular
107       logging interfaces.  If you want to override this method, you must
108       override "log_debug" and not "debug".
109
110   set_debug
111         $logger->set_debug($bool);
112
113       This sets the logger's debug property, which affects the behavior of
114       "log_debug".
115
116   get_debug
117       This gets the logger's debug property, which affects the behavior of
118       "log_debug".
119
120   clear_debug
121       This method does nothing, and is only useful for
122       Log::Dispatchouli::Proxy objects.  See Methods for Proxy Loggers,
123       below.
124
125   set_muted
126         $logger->set_muted($bool);
127
128       This sets the logger's muted property, which affects the behavior of
129       "log".
130
131   get_muted
132       This gets the logger's muted property, which affects the behavior of
133       "log".
134
135   clear_muted
136       This method does nothing, and is only useful for
137       Log::Dispatchouli::Proxy objects.  See Methods for Proxy Loggers,
138       below.
139
140   get_prefix
141         my $prefix = $logger->get_prefix;
142
143       This method returns the currently-set prefix for the logger, which may
144       be a string or code reference or undef.  See Logger Prefix.
145
146   set_prefix
147         $logger->set_prefix( $new_prefix );
148
149       This method changes the prefix.  See Logger Prefix.
150
151   clear_prefix
152       This method clears any set logger prefix.  (It can also be called as
153       "unset_prefix", but this is deprecated.  See Logger Prefix.
154
155   ident
156       This method returns the logger's ident.
157
158   config_id
159       This method returns the logger's configuration id, which defaults to
160       its ident.  This can be used to make two loggers equivalent in
161       Log::Dispatchouli::Global so that trying to reinitialize with a new
162       logger with the same "config_id" as the current logger will not throw
163       an exception, and will simply do no thing.
164
165   dispatcher
166       This returns the underlying Log::Dispatch object.  This is not the
167       method you're looking for.  Move along.
168

LOGGER PREFIX

170       Log messages may be prepended with information to set context.  This
171       can be set at a logger level or per log item.  The simplest example is:
172
173         my $logger = Log::Dispatchouli->new( ... );
174
175         $logger->set_prefix("Batch 123: ");
176
177         $logger->log("begun processing");
178
179         # ...
180
181         $logger->log("finished processing");
182
183       The above will log something like:
184
185         Batch 123: begun processing
186         Batch 123: finished processing
187
188       To pass a prefix per-message:
189
190         $logger->log({ prefix => 'Sub-Item 234: ' }, 'error!')
191
192         # Logs: Batch 123: Sub-Item 234: error!
193
194       If the prefix is a string, it is prepended to each line of the message.
195       If it is a coderef, it is called and passed the message to be logged.
196       The return value is logged instead.
197
198       Proxy loggers also have their own prefix settings, which accumulate.
199       So:
200
201         my $proxy = $logger->proxy({ proxy_prefix => 'Subsystem 12: ' });
202
203         $proxy->set_prefix('Page 9: ');
204
205         $proxy->log({ prefix => 'Paragraph 6: ' }, 'Done.');
206
207       ...will log...
208
209         Batch 123: Subsystem 12: Page 9: Paragraph 6: Done.
210

METHODS FOR SUBCLASSING

212   string_flogger
213       This method returns the thing on which flog will be called to format
214       log messages.  By default, it just returns "String::Flogger"
215
216   env_prefix
217       This method should return a string used as a prefix to find environment
218       variables that affect the logger's behavior.  For example, if this
219       method returns "XYZZY" then when checking the environment for a default
220       value for the "debug" parameter, Log::Dispatchouli will first check
221       "XYZZY_DEBUG", then "DISPATCHOULI_DEBUG".
222
223       By default, this method returns "()", which means no extra environment
224       variable is checked.
225
226   env_value
227         my $value = $logger->env_value('DEBUG');
228
229       This method returns the value for the environment variable suffix
230       given.  For example, the example given, calling with "DEBUG" will check
231       "DISPATCHOULI_DEBUG".
232

METHODS FOR TESTING

234   new_tester
235         my $logger = Log::Dispatchouli->new_tester( \%arg );
236
237       This returns a new logger that logs only "to_self".  It's useful in
238       testing.  If no "ident" arg is provided, one will be generated.
239       "log_pid" is off by default, but can be overridden.
240
241       "\%arg" is optional.
242
243   events
244       This method returns the arrayref of events logged to an array in memory
245       (in the logger).  If the logger is not logging "to_self" this raises an
246       exception.
247
248   clear_events
249       This method empties the current sequence of events logged into an array
250       in memory.  If the logger is not logging "to_self" this raises an
251       exception.
252

METHODS FOR PROXY LOGGERS

254   proxy
255         my $proxy_logger = $logger->proxy( \%arg );
256
257       This method returns a new proxy logger -- an instance of
258       Log::Dispatchouli::Proxy -- which will log through the given logger,
259       but which may have some settings localized.
260
261       %arg is optional.  It may contain the following entries:
262
263       proxy_prefix
264           This is a prefix that will be applied to anything the proxy logger
265           logs, and cannot be changed.
266
267       debug
268           This can be set to true or false to change the proxy's "am I in
269           debug mode?"  setting.  It can be changed or cleared later on the
270           proxy.
271
272   parent
273   logger
274       These methods return the logger itself.  (They're more useful when
275       called on proxy loggers.)
276

METHODS FOR API COMPATIBILITY

278       To provide compatibility with some other loggers, most specifically
279       Log::Contextual, the following methods are provided.  You should not
280       use these methods without a good reason, and you should never subclass
281       them.  Instead, subclass the methods they call.
282
283       is_debug
284           This method calls "get_debug".
285
286       is_info
287       is_fatal
288           These methods return true.
289
290       info
291       fatal
292       debug
293           These methods redispatch to "log", "log_fatal", and "log_debug"
294           respectively.
295

SEE ALSO

297       ·   Log::Dispatch
298
299       ·   String::Flogger
300

AUTHOR

302       Ricardo SIGNES <rjbs@cpan.org>
303

CONTRIBUTORS

305       ·   Christopher J. Madsen <perl@cjmweb.net>
306
307       ·   Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
308
309       ·   Dan Book <grinnz@gmail.com>
310
311       ·   George Hartzell <hartzell@alerce.com>
312
313       ·   Matt Phillips <mattp@cpan.org>
314
315       ·   Olivier Mengué <dolmen@cpan.org>
316
317       ·   Randy Stauner <randy@magnificent-tears.com>
318
319       ·   Sawyer X <xsawyerx@cpan.org>
320
322       This software is copyright (c) 2018 by Ricardo SIGNES.
323
324       This is free software; you can redistribute it and/or modify it under
325       the same terms as the Perl 5 programming language system itself.
326
327
328
329perl v5.28.0                      2018-02-21              Log::Dispatchouli(3)
Impressum