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

PERL VERSION SUPPORT

44       This module has a long-term perl support period.  That means it will
45       not require a version of perl released fewer than five years ago.
46
47       Although it may work on older versions of perl, no guarantee is made
48       that the minimum required version will not be increased.  The version
49       may be increased for any reason, and there is no promise that patches
50       will be accepted to lower the minimum required perl.
51

METHODS

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

LOGGER PREFIX

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

METHODS FOR SUBCLASSING

227   string_flogger
228       This method returns the thing on which flog will be called to format
229       log messages.  By default, it just returns "String::Flogger"
230
231   env_prefix
232       This method should return a string used as a prefix to find environment
233       variables that affect the logger's behavior.  For example, if this
234       method returns "XYZZY" then when checking the environment for a default
235       value for the "debug" parameter, Log::Dispatchouli will first check
236       "XYZZY_DEBUG", then "DISPATCHOULI_DEBUG".
237
238       By default, this method returns "()", which means no extra environment
239       variable is checked.
240
241   env_value
242         my $value = $logger->env_value('DEBUG');
243
244       This method returns the value for the environment variable suffix
245       given.  For example, the example given, calling with "DEBUG" will check
246       "DISPATCHOULI_DEBUG".
247

METHODS FOR TESTING

249   new_tester
250         my $logger = Log::Dispatchouli->new_tester( \%arg );
251
252       This returns a new logger that logs only "to_self".  It's useful in
253       testing.  If no "ident" arg is provided, one will be generated.
254       "log_pid" is off by default, but can be overridden.
255
256       "\%arg" is optional.
257
258   events
259       This method returns the arrayref of events logged to an array in memory
260       (in the logger).  If the logger is not logging "to_self" this raises an
261       exception.
262
263   clear_events
264       This method empties the current sequence of events logged into an array
265       in memory.  If the logger is not logging "to_self" this raises an
266       exception.
267

METHODS FOR PROXY LOGGERS

269   proxy
270         my $proxy_logger = $logger->proxy( \%arg );
271
272       This method returns a new proxy logger -- an instance of
273       Log::Dispatchouli::Proxy -- which will log through the given logger,
274       but which may have some settings localized.
275
276       %arg is optional.  It may contain the following entries:
277
278       proxy_prefix
279           This is a prefix that will be applied to anything the proxy logger
280           logs, and cannot be changed.
281
282       debug
283           This can be set to true or false to change the proxy's "am I in
284           debug mode?"  setting.  It can be changed or cleared later on the
285           proxy.
286
287   parent
288   logger
289       These methods return the logger itself.  (They're more useful when
290       called on proxy loggers.)
291

METHODS FOR API COMPATIBILITY

293       To provide compatibility with some other loggers, most specifically
294       Log::Contextual, the following methods are provided.  You should not
295       use these methods without a good reason, and you should never subclass
296       them.  Instead, subclass the methods they call.
297
298       is_debug
299           This method calls "get_debug".
300
301       is_info
302       is_fatal
303           These methods return true.
304
305       info
306       fatal
307       debug
308           These methods redispatch to "log", "log_fatal", and "log_debug"
309           respectively.
310

SEE ALSO

312       •   Log::Dispatch
313
314       •   String::Flogger
315

AUTHOR

317       Ricardo SIGNES <rjbs@semiotic.systems>
318

CONTRIBUTORS

320       •   Christopher J. Madsen <perl@cjmweb.net>
321
322       •   Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
323
324       •   Dan Book <grinnz@gmail.com>
325
326       •   George Hartzell <hartzell@alerce.com>
327
328       •   Jon Stuart <jon@fastmailteam.com>
329
330       •   Matt Phillips <mattp@cpan.org>
331
332       •   Olivier Mengué <dolmen@cpan.org>
333
334       •   Randy Stauner <randy@magnificent-tears.com>
335
336       •   Ricardo Signes <rjbs@users.noreply.github.com>
337
338       •   Sawyer X <xsawyerx@cpan.org>
339
341       This software is copyright (c) 2021 by Ricardo SIGNES.
342
343       This is free software; you can redistribute it and/or modify it under
344       the same terms as the Perl 5 programming language system itself.
345
346
347
348perl v5.34.0                      2021-07-22              Log::Dispatchouli(3)
Impressum