NAME

Log::ger::Manual::Tutorial::400_Output - Logging outputs

VERSION

version 0.040.000

DESCRIPTION

PRODUCING AND CONSUMING

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.

CHOOSING AN OUTPUT

There are a variety of output modules you can choose in Log::ger, for example:

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

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);

or:

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.

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2022, 2020, 2019, 2018, 2017 by perlancar <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.