.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.48) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Required to disable full justification in groff 1.23.0. .if n .ds AD l .\" ======================================================================== .\" .IX Title "Log::Dispatchouli 3" .TH Log::Dispatchouli 3 2026-10-25 "perl v5.44.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 6 \& my $logger = Log::Dispatchouli\->new({ \& ident => \*(Aqstuff\-purger\*(Aq, \& facility => \*(Aqdaemon\*(Aq, \& to_stdout => $opt\->{print}, \& debug => $opt\->{verbose} \& }); \& \& $logger\->log([ "There are %s items left to purge...", $stuff_left ]); \& \& $logger\->log_debug("this is extra often\-ignored debugging log"); \& \& $logger\->log_fatal("Now we will die!!"); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" Log::Dispatchouli is a thin layer above Log::Dispatch and meant to make it dead simple to add logging to a program without having to think much about categories, facilities, levels, or things like that. It is meant to make logging just configurable enough that you can find the logs you want and just easy enough that you will actually log things. .PP Log::Dispatchouli can log to syslog (if you specify a facility), standard error or standard output, to a file, or to an array in memory. That last one is mostly useful for testing. .PP In addition to providing as simple a way to get a handle for logging operations, Log::Dispatchouli uses String::Flogger to process the things to be logged, meaning you can easily log data structures. Basically: strings are logged as is, arrayrefs are taken as (sprintf format, args), and subroutines are called only if needed. For more information read the String::Flogger docs. .SH "LOGGER PREFIX" .IX Header "LOGGER PREFIX" Log messages may be prepended with information to set context. This can be set at a logger level or per log item. The simplest example is: .PP .Vb 1 \& my $logger = Log::Dispatchouli\->new( ... ); \& \& $logger\->set_prefix("Batch 123: "); \& \& $logger\->log("begun processing"); \& \& # ... \& \& $logger\->log("finished processing"); .Ve .PP The above will log something like: .PP .Vb 2 \& Batch 123: begun processing \& Batch 123: finished processing .Ve .PP To pass a prefix per\-message: .PP .Vb 1 \& $logger\->log({ prefix => \*(AqSub\-Item 234: \*(Aq }, \*(Aqerror!\*(Aq) \& \& # Logs: Batch 123: Sub\-Item 234: error! .Ve .PP If the prefix is a string, it is prepended to each line of the message. If it is a coderef, it is called and passed the message to be logged. The return value is logged instead. .PP Proxy loggers also have their own prefix settings, which accumulate. So: .PP .Vb 1 \& my $proxy = $logger\->proxy({ proxy_prefix => \*(AqSubsystem 12: \*(Aq }); \& \& $proxy\->set_prefix(\*(AqPage 9: \*(Aq); \& \& $proxy\->log({ prefix => \*(AqParagraph 6: \*(Aq }, \*(AqDone.\*(Aq); .Ve .PP \&...will log... .PP .Vb 1 \& Batch 123: Subsystem 12: Page 9: Paragraph 6: Done. .Ve .PP .Vb 1 \& my $logger = Log::Dispatchouli\->new(\e%arg); .Ve .PP This returns a new logger, a Log::Dispatchouli object. .PP Valid arguments are: .PP .Vb 5 \& ident \- the name of the thing logging (mandatory) \& to_self \- log to the logger object for testing; default: false \& to_stdout \- log to STDOUT; default: false \& to_stderr \- log to STDERR; default: false \& facility \- to which syslog facility to send logs; default: none \& \& to_file \- DEPRECATED: this option will be removed in 2025 \& log to PROGRAM_NAME.YYYYMMDD in the log path; default: false \& log_file \- a leaf name for the file to log to with to_file \& log_path \- path in which to log to file; defaults to DISPATCHOULI_PATH \& environment variable or, failing that, to your system\*(Aqs tmpdir \& \& file_format \- this optional coderef is passed the message to be logged \& and returns the text to write out \& \& log_pid \- if 1, prefix all log entries with the pid; default: true \& can also be a comma\-delimited list of log targets where pid is \& logged, like "stderr,syslog"; mostly useful for logging pid in \& syslog, but not on standard I/O \& fail_fatal \- a boolean; if true, failure to log is fatal; default: true \& muted \- a boolean; if true, only fatals are logged; default: false \& debug \- a boolean; if true, log_debug method is not a no\-op \& defaults to the truth of the DISPATCHOULI_DEBUG env var \& quiet_fatal \- \*(Aqstderr\*(Aq or \*(Aqstdout\*(Aq or an arrayref of zero, one, or both \& fatal log messages will not be logged to these \& (default: stderr) \& config_id \- a name for this logger\*(Aqs config; rarely needed! \& syslog_socket \- a value for Sys::Syslog\*(Aqs "socket" arg; default: "native" .Ve .PP The log path is either \fI/tmp\fR or the value of the \fIDISPATCHOULI_PATH\fR env var. .PP If the \fIDISPATCHOULI_NOSYSLOG\fR env var is true, we don\*(Aqt log to syslog. .PP These methods turn on logging to STDOUT or STDERR, respectively. If that logging has already been enabled, these methods do nothing. .PP There is not, yet, a \fIdisable\fR version of these methods. .PP .Vb 1 \& $logger\->log(@messages); \& \& $logger\->log(\e%arg, @messages); .Ve .PP This method uses String::Flogger on the input, then \fIunconditionally\fR logs the result. Each message is flogged individually, then joined with spaces. .PP If the first argument is a hashref, it will be used as extra arguments to logging. It may include a \f(CW\*(C`prefix\*(C'\fR entry to preprocess the message by prepending a string (if the prefix is a string) or calling a subroutine to generate a new message (if the prefix is a coderef). .PP This behaves like the \f(CW\*(C`log\*(C'\fR method, but will throw the logged string as an exception after logging. .PP This method can also be called as \f(CW\*(C`fatal\*(C'\fR, to match other popular logging interfaces. \fBIf you want to override this method, you must override \&\fR\f(CB\*(C`log_fatal\*(C'\fR\fB and not \fR\f(CB\*(C`fatal\*(C'\fR. .PP This behaves like the \f(CW\*(C`log\*(C'\fR method, but will only log (at the debug level) if the logger object has its debug property set to true. .PP This method can also be called as \f(CW\*(C`debug\*(C'\fR, to match other popular logging interfaces. \fBIf you want to override this method, you must override \&\fR\f(CB\*(C`log_debug\*(C'\fR\fB and not \fR\f(CB\*(C`debug\*(C'\fR. .PP This method is like \f(CW\*(C`log\*(C'\fR, but is used for structured logging instead of free form text. It\*(Aqs invoked like this: .PP .Vb 1 \& $logger\->log($event_type => $data_ref); .Ve .PP \&\f(CW$event_type\fR should be a simple string, probably a valid identifier, that identifies the kind of event being logged. It is suggested, but not required, that all events of the same type have the same kind of structured data in them. .PP \&\f(CW$data_ref\fR is a set of key/value pairs of data to log in this event. It can be an arrayref (in which case the ordering of pairs is preserved) or a hashref (in which case they are sorted by key). .PP The logged string will be in logfmt format, meaning a series of key=value pairs separated by spaces and following these rules: .PP When values are undef, they are represented as \f(CW\*(C`~\*(C'\fR. .PP When values are array references, the index/values are mapped over, so that: .PP .Vb 1 \& key => [ \*(Aqa\*(Aq, \*(Aqb\*(Aq ] .Ve .PP becomes .PP .Vb 1 \& key.0=a key.1=b .Ve .PP When values are hash references, the key/values are mapped, with keys sorted, so that: .PP .Vb 1 \& key => { b => 2, a => 1 } .Ve .PP becomes .PP .Vb 1 \& key.a=1 key.b=2 .Ve .PP This expansion is performed recursively. If a value itself recurses, appearances of a reference after the first time will be replaced with a string like \f(CW\*(C`&foo.bar\*(C'\fR, pointing to the first occurrence. \fIThis is not meant to be a robust serialization mechanism.\fR It\*(Aqs just here to help you be a little lazy. Don\*(Aqt push the limits. .PP If the value in \f(CW$data_ref\fR is a code reference, it will be called and its result logged. If its result is also a code reference, you get whatever garbage that code reference stringifies to. .PP If the value in \f(CW$data_ref\fR is a reference reference, then the referenced scalar will be passed to String::Flogger, and the resulting string will be used as the value to log. That string will be quoted as described above, if needed. .PP This method is just like \f(CW\*(C`log_event\*(C'\fR, but will log nothing unless the logger has its \f(CW\*(C`debug\*(C'\fR property set to true. .PP .Vb 1 \& $logger\->set_debug($bool); .Ve .PP This sets the logger\*(Aqs debug property, which affects the behavior of \&\f(CW\*(C`log_debug\*(C'\fR. .PP This gets the logger\*(Aqs debug property, which affects the behavior of \&\f(CW\*(C`log_debug\*(C'\fR. .PP This method does nothing, and is only useful for Log::Dispatchouli::Proxy objects. See Methods for Proxy Loggers, below. .PP .Vb 1 \& $logger\->set_muted($bool); .Ve .PP This sets the logger\*(Aqs muted property, which affects the behavior of \&\f(CW\*(C`log\*(C'\fR. .PP This gets the logger\*(Aqs muted property, which affects the behavior of \&\f(CW\*(C`log\*(C'\fR. .PP This method does nothing, and is only useful for Log::Dispatchouli::Proxy objects. See Methods for Proxy Loggers, below. .PP .Vb 1 \& my $prefix = $logger\->get_prefix; .Ve .PP This method returns the currently\-set prefix for the logger, which may be a string or code reference or undef. See Logger Prefix. .PP .Vb 1 \& $logger\->set_prefix( $new_prefix ); .Ve .PP This method changes the prefix. See Logger Prefix. .PP This method clears any set logger prefix. (It can also be called as \&\f(CW\*(C`unset_prefix\*(C'\fR, but this is deprecated. See Logger Prefix. .PP This method returns the logger\*(Aqs ident. .PP This method returns the logger\*(Aqs configuration id, which defaults to its ident. This can be used to make two loggers equivalent in Log::Dispatchouli::Global so that trying to reinitialize with a new logger with the same \f(CW\*(C`config_id\*(C'\fR as the current logger will not throw an exception, and will simply do no thing. .SH "METHODS FOR SUBCLASSING" .IX Header "METHODS FOR SUBCLASSING" .SS string_flogger .IX Subsection "string_flogger" This method returns the thing on which \fIflog\fR will be called to format log messages. By default, it just returns \f(CW\*(C`String::Flogger\*(C'\fR .SS env_prefix .IX Subsection "env_prefix" This method should return a string used as a prefix to find environment variables that affect the logger\*(Aqs behavior. For example, if this method returns \f(CW\*(C`XYZZY\*(C'\fR then when checking the environment for a default value for the \&\f(CW\*(C`debug\*(C'\fR parameter, Log::Dispatchouli will first check \f(CW\*(C`XYZZY_DEBUG\*(C'\fR, then \&\f(CW\*(C`DISPATCHOULI_DEBUG\*(C'\fR. .PP By default, this method returns \f(CW\*(C`()\*(C'\fR, which means no extra environment variable is checked. .SS env_value .IX Subsection "env_value" .Vb 1 \& my $value = $logger\->env_value(\*(AqDEBUG\*(Aq); .Ve .PP This method returns the value for the environment variable suffix given. For example, the example given, calling with \f(CW\*(C`DEBUG\*(C'\fR will check \&\f(CW\*(C`DISPATCHOULI_DEBUG\*(C'\fR. .PP .Vb 1 \& my $str = $logger\->flog_messages($m1, $m2, ...); .Ve .PP This returns the string that would have been logged if the given arguments had been passed to \f(CW\*(C`$logger\->log(...)\*(C'\fR, without regard for log level, debugging, or the like. .PP Unlike using the logger\*(Aqs string flogger, this will include any relevant prefix strings. .PP .Vb 1 \& my $str = $logger\->fmt_event($event_type => $data_ref); .Ve .PP This method is equivalent to \f(CW\*(C`flog_messages\*(C'\fR, but for an event. It returns the string format of the event, including all relevant prefixes. .SH "METHODS FOR TESTING" .IX Header "METHODS FOR TESTING" .SS new_tester .IX Subsection "new_tester" .Vb 1 \& my $logger = Log::Dispatchouli\->new_tester( \e%arg ); .Ve .PP This returns a new logger that logs only \f(CW\*(C`to_self\*(C'\fR. It\*(Aqs useful in testing. If no \f(CW\*(C`ident\*(C'\fR arg is provided, one will be generated. \f(CW\*(C`log_pid\*(C'\fR is off by default, but can be overridden. .PP \&\f(CW\*(C`\e%arg\*(C'\fR is optional. .SS events .IX Subsection "events" This method returns the arrayref of events logged to an array in memory (in the logger). If the logger is not logging \f(CW\*(C`to_self\*(C'\fR this raises an exception. .SS clear_events .IX Subsection "clear_events" This method empties the current sequence of events logged into an array in memory. If the logger is not logging \f(CW\*(C`to_self\*(C'\fR this raises an exception. .SH "METHODS FOR PROXY LOGGERS" .IX Header "METHODS FOR PROXY LOGGERS" .SS proxy .IX Subsection "proxy" .Vb 1 \& my $proxy_logger = $logger\->proxy( \e%arg ); .Ve .PP This method returns a new proxy logger \-\- an instance of Log::Dispatchouli::Proxy \-\- which will log through the given logger, but which may have some settings localized. .PP \&\f(CW%arg\fR is optional. It may contain the following entries: .SS parent .IX Subsection "parent" .SS logger .IX Subsection "logger" These methods return the logger itself. (They\*(Aqre more useful when called on proxy loggers.) .PP This returns the underlying Log::Dispatch object. This is not the method you\*(Aqre looking for. Move along. .PP This method is an experimental feature to allow you to pick an alternate dispatch class for stderr and stdio. By default, Log::Dispatch::Screen is used. \fBThis feature may go away at any time.\fR .SH "METHODS FOR API COMPATIBILITY" .IX Header "METHODS FOR API COMPATIBILITY" To provide compatibility with some other loggers, most specifically Log::Contextual, the following methods are provided. You should not use these methods without a good reason, and you should never subclass them. Instead, subclass the methods they call. .SH "SEE ALSO" .IX Header "SEE ALSO" .SH "POD ERRORS" .IX Header "POD ERRORS" Hey! \fBThe above document had some coding errors, which are explained below:\fR .IP "Around line 99:" 4 .IX Item "Around line 99:" Unknown directive: =method .IP "Around line 265:" 4 .IX Item "Around line 265:" Unknown directive: =method .IP "Around line 267:" 4 .IX Item "Around line 267:" Unknown directive: =method .IP "Around line 318:" 4 .IX Item "Around line 318:" Unknown directive: =method .IP "Around line 383:" 4 .IX Item "Around line 383:" Unknown directive: =method .IP "Around line 403:" 4 .IX Item "Around line 403:" Unknown directive: =method .IP "Around line 424:" 4 .IX Item "Around line 424:" Unknown directive: =method .IP "Around line 528:" 4 .IX Item "Around line 528:" Unknown directive: =method .IP "Around line 541:" 4 .IX Item "Around line 541:" Unknown directive: =method .IP "Around line 552:" 4 .IX Item "Around line 552:" Unknown directive: =method .IP "Around line 561:" 4 .IX Item "Around line 561:" Unknown directive: =method .IP "Around line 573:" 4 .IX Item "Around line 573:" Unknown directive: =method .IP "Around line 586:" 4 .IX Item "Around line 586:" Unknown directive: =method .IP "Around line 595:" 4 .IX Item "Around line 595:" Unknown directive: =method .IP "Around line 604:" 4 .IX Item "Around line 604:" Unknown directive: =method .IP "Around line 611:" 4 .IX Item "Around line 611:" Unknown directive: =method .IP "Around line 617:" 4 .IX Item "Around line 617:" Unknown directive: =method .IP "Around line 629:" 4 .IX Item "Around line 629:" Unknown directive: =method .IP "Around line 637:" 4 .IX Item "Around line 637:" Unknown directive: =method .IP "Around line 695:" 4 .IX Item "Around line 695:" Unknown directive: =method .IP "Around line 706:" 4 .IX Item "Around line 706:" Unknown directive: =method .IP "Around line 832:" 4 .IX Item "Around line 832:" Unknown directive: =method .IP "Around line 841:" 4 .IX Item "Around line 841:" Unknown directive: =method