Log::ger::Manual::Tutorial::600_Format - Format plugins
version 0.028.005
Log::ger::Manual::Tutorial::610_Format_Block
Log::ger::Manual::Tutorial::690_WritingAFormatPlugin
Log::ger is flexible; it allows you to customize what arguments you want to pass to the logger routines and how to format them into string (if at all).
The default behaviour of Log::ger is the sprintf-style formatting:
log_warn "single argument, string as-is"; log_warn("more than 1 argument, first arg is sprintf format, rest are arguments: %s %d", [data => {structure=>1}], 1234);
Aside from sprintf, data structure arguments are also dumped (using Data::Dmp if available, or Data::Dumper otherwise). Undef arguments are rendered as <undef>.
<undef>
This default behavior is chosen because back when I was using Log::Any, I find that 90-95% of the time I'm using the sprintf methods (warnf, debugf, and so on).
warnf
debugf
Format plugins can change how logger routines process/format the arguments. For example, the Log::ger::Format::Block format plugin causes your logger routines to accept a block as the first argument, and the rest of the arguments will be passed to that block. The block will only be executed if message is to be produced.
log_debug { require Some::Object; my $obj = Some::Object->new; "Object is ".$obj->as_string }; log_info { do_heavy_calculation(@_) }, "arg", "more arg";
This style is suitable if you often do something calculation-heavy to produce the log message. Another logging framework that uses this style is Log::Contextual.
To use this style:
package My::App; use Log::ger::Format 'Block'; use Log::ger; log_warn { ... };
When imported, format plugins only affect the calling package.
Search CPAN for the other available Log::ger::Format::* modules.
Log::ger::Format::*
perlancar <perlancar@cpan.org>
This software is copyright (c) 2019, 2018, 2017 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Log::ger::Manual, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Log::ger::Manual
CPAN shell
perl -MCPAN -e shell install Log::ger::Manual
For more information on module installation, please visit the detailed CPAN module installation guide.