Dancer2::Logger::Log4perl - Dancer2 logger interface for Log4perl.
version 0.07
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
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.
logger
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.
core
trace
log
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.
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
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
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.
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:
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.
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.
$work
Jason A. Crome <cpan@jason.cromedome.dev>
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.
To install Dancer2::Logger::Log4perl, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dancer2::Logger::Log4perl
CPAN shell
perl -MCPAN -e shell install Dancer2::Logger::Log4perl
For more information on module installation, please visit the detailed CPAN module installation guide.