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

NAME

Dancer2::Logger::Log4perl - Dancer2 logger interface for Log4perl.

VERSION

version 0.07

SYNOPSIS

In your config.yml:

   logger: log4perl
   log: core
   engines:
      logger:
         log4perl:
            config_file: log4perl.conf
            category: "My Super Awesome App"

In your log4perl.conf:

   log4perl.rootLogger              = DEBUG, LOG1
   log4perl.appender.LOG1           = Log::Log4perl::Appender::File
   log4perl.appender.LOG1.filename  = /var/log/mylog.log
   log4perl.appender.LOG1.mode      = append
   log4perl.appender.LOG1.layout    = Log::Log4perl::Layout::PatternLayout
   log4perl.appender.LOG1.layout.ConversionPattern = %d %p %m %n

DESCRIPTION

This class is an interface between Dancer2's logging engine abstraction layer and the Log::Log4perl library. In order to use it, you have to set the logger engine to log4perl.

Dancer2's core level messages are passed to Log4perl as level trace but will not be passed unless Dancer2's log config is core.

log should be set a lower priority than the lowest priority as set in your Log4perl configuration. If it isn't, the log messages will not be passed to Log4perl.

CONFIGURATION

If you don't specify config_file then Log4perl will easy init with the appropriate log level, as specified by Dancer2.

config_file

You can specify the log4perl configuration file using the config_file option:

   logger: log4perl
   engines:
      logger:
         log4perl:
            config_file: log4perl.conf
config_watch_interval

You can optionally specify the watch interval, either in seconds or as 'HUP':

   logger: log4perl
   engines:
      logger:
         log4perl:
            config_file: log4perl.conf
            config_watch_interval: 30
category

Log::Log4perl creates a single instance of itself for each category of logger you create in your application; to that end, this setting lets you specify the category for your Dancer2 application. If no category is provided, your application name will be used by default.

LOG FORMATTING

You can use Dancer2's built in log formatting functionality (via the log_format config option), use a log layout specified in Log4perl, or a combination of the two. If you plan to use Log4perl to control all the formatting, we recommend you use the following log format:

   logger: log4perl
   engines:
      logger:
         log4perl:
            config_file: log4perl.conf
            log_format: "%m"

This ensures that only the log message itself is passed to Log4perl.

CREDITS

This was originally developed by Ryan Larscheidt and Jon Miner at the University of Wisconsin. The initial version of this was built upon their final version. I cannot thank them enough for their work on this - it not only solved my needs at $work, but also plugs a hole in our ecosystem.

AUTHOR

Jason A. Crome <cpan@jason.cromedome.dev>

COPYRIGHT AND LICENSE

This software is copyright (c) 2023 by Jason A. Crome.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.