Log::ger::Manual::Tutorial::400_Output - Logging outputs
version 0.033.000
Log::ger::Manual::Tutorial::410_Output_Screen
Log::ger::Manual::Tutorial::420_Output_File
Log::ger::Manual::Tutorial::421_Output_SimpleFile
Log::ger::Manual::Tutorial::422_Output_FileWriteRotate
Log::ger::Manual::Tutorial::430_Output_Syslog
Log::ger::Manual::Tutorial::470_Output_DirwriteRotate
Log::ger::Manual::Tutorial::481_Output_Composite
Log::ger::Manual::Tutorial::490_WritingAnOutputPlugin
The act of logging:
log_info("This is just an informational message"); log_warn("This is a warning, you have been warned");
is called producing the log. By default the messages don't go anywhere so you do not see them. When an application is run, logging output(s) (and level) are set up; only then the messages will be shown, either to the terminal (screen), file, or some other destination. The act of taking a log message and showing it through some output is called consuming the log.
There are a variety of output modules you can choose in Log::ger, for example:
Log::ger::Output::Screen
Log::ger::Output::File
Log::ger::Output::Syslog
Search CPAN for more Log::ger::Output::* modules. And when you don't find one suitable for your needs, it's easy to write your own (see 490_WritingAnOutputPlugin).
Log::ger::Output::*
To select an output:
use Log::ger::Output 'Screen'; # note: NOT 'use Log::ger::Output::Screen'!
or:
use Log::ger::Output; Log::ger::Output->set('Screen');
To pass configuration parameters to an output module:
use Log::ger::Output File => (path => '/tmp/app.log', lazy => 1);
use Log::ger::Output; Log::ger::Output->set(File => (path => '/tmp/app.log', lazy => 1));
If you want to output to two or more destinations, you can use Log::ger::Output::Composite which multiplexes the message to multiple outputs:
use Log::ger::Output Composite => ( outputs => { Screen => {}, File => { conf => {path=>'/tmp/app.log', lazy=>1} }, }, );
Apart from multiplexing output, Composite can also set per-output level, per-category level, and per-output per-category level. We will cover Composite in subsequent tutorial post.
perlancar <perlancar@cpan.org>
This software is copyright (c) 2020, 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.