The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Log::ger::Output::Composite - Composite output

VERSION

version 0.018

SYNOPSIS

 use Log::ger::Output Composite => (
     outputs => {
         # single screen output
         Screen => {
             conf   => { use_color=>1 },                        # output config, optional.
             level  => 'info',                                  # set per-output level. optional.
             layout => [Pattern => {format=>'%d (%F:%L)> %m'}], # add per-output layout, optional.
         },
         # multiple file outputs
         File => [
             {
                 conf  => { path=>'/var/log/myapp.log' },
                 level => 'warn',
                 category_level => {                            # set per-category, per-output level. optional.
                     # don't log MyApp::Security messages to this file
                     'MyApp::Security' => 'off',
                     ...
                 },
             },
             {
                 conf => { path => '/var/log/myapp-security.log' },
                 level => 'warn',
                 category_level => {
                     # only MyApp::Security messages go to this file
                     'MyApp::Security' => 'warn',
                     ...
                 },
             },
         ],
     },
     category_level => {                                        # set per-category level. optional.
        'MyApp::SubModule1' => 'info',
        'MyApp::SubModule2' => 'debug',
        ...
     },
 );
 use Log::ger;

 log_warn "blah...";

DESCRIPTION

This is a Log::ger output that can multiplex output to several outputs and do filtering on the basis of per-category level, per-output level, or per-output per-category level. It can also apply per-output layout.

CONFIGURATION

outputs => hash

Hash. Specify outputs. Hash key is output name and and hash value is output specification.

Output name is the name of output module without the Log::ger::Output:: prefix, e.g. Screen or File.

Output specification is either a hashref or arrayref of hashrefs to specify multiple outputs per type (e.g. if you want to output to two File's). Known hashref keys for output specification:

  • conf => hashref

    Specify output configuration. Optional. See each output documentation for the list of available configuration parameters.

  • level => str|int|[min, max]

    Specify per-output level. Optional. If specified, logging will be done at this level instead of the general level. For example, if this is set to debug then debug messages and higher will be sent to output even though the general level is warn. Vice versa, if this is set to error then even though the general level is warn, warning messages won't be sent to this output; only error messages and higher will be sent.

    You can specify a single level (e.g. 1 or "trace") or a two-element array to specify minimum and maximum level (e.g. <["trace", "info"]>). If you accidentally mix up minimum and maximum, this module will helpfully fix it for you.

  • category_level => hash

    Specify per-output per-category level. Optional. Hash key is category name, value is level (which can be a string/numeric level or a two-element array containing minimum and maximum level).

  • layout => [Name => {conf1=>..., conf2=>..., ...}]

    Specify per-output layout. Optional. Value is two-element array containing layout name (without the Log::ger::Layout:: prefix, e.g. Pattern) and configuration hash. See each layout module documentation for the list of available configuration parameters.

    Note that if you also use a layout module outside of Composite configuration, e.g.:

     use Log::ger::Output Composite => (...);
     use Log::ger::Layout Pattern => (format => '...');

    then both layouts will be applied, the general layout will be applied before the per-output layout.

category_level => hash

Hash, optional. Specify per-category level. Hash key is category name, value is level (which can be a string/numeric level or a two-element array containing minimum and maximum level).

FAQS

Why doesn't re-setting log level using Log::ger::Util::set_level() work?

This output plugin sets its own levels and logs using a multilevel routine (which gets called for all levels). Re-setting log level dynamically via Log::ger::Util's set_level will not work as intended, which is fortunate or unfortunate depending on your need.

If you want to override all levels settings with a single value, you can use Log::ger::Output::Composite::set_level, for example:

 Log::ger::Util::set_level('trace'); # also set this too
 Log::ger::Output::Composite::set_level('trace');

This sets an internal level setting which is respected and has the highest precedence so all levels settings will use this instead. If previously you have:

 Log::ger::Output->set(Composite => (
     outputs => {
         File   => {conf=>{path=>'/foo'}, level=>'debug'},
         Screen => {level=>'info', category_level=>{MyApp=>'warn'}},
     },
     category_level => {
         'MyApp::SubModule1' => 'debug',
     },
 ));

then after the Log::ger::Output::Composite::set_level('trace'), all the above per-category and per-output levels will be set to trace.

ENVIRONMENT

LOG_LOG_GER_OUTPUT_COMPOSITE_CODE

Bool. If set to true will print the generated logger source code to stderr.

LOG_GER_OUTPUT_COMPOSITE_DEBUG

Bool. If set to true, will print some debugging messages to stderr.

SEE ALSO

Log::ger::App as an example on module that uses Log::ger::Output::Composite.

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2024, 2020, 2019, 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.