Skip Menu |

This queue is for tickets about the Log-Log4perl CPAN distribution.

Report information
The Basics
Id: 77801
Status: resolved
Priority: 0/
Queue: Log-Log4perl

People
Owner: Nobody in particular
Requestors: FGA [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.37
Fixed in: (no value)



Subject: Feature: converting log levels to integers in PatternLayout
Hi, I'm currently using Log::Log4perl in a large-ish application, and I've defined a DBI appender. It all works nicely except that I'd like to run queries like "show me all logging events on this application originating from this module of priority WARNING *or higher*". Using the %p placeholder allows me to store the priority in a column, but as a string. This can be worked around on SQL engines that support some form of ENUM, but I'd rather just store integers. Is such a thing possible with Log::Log4perl and did I just miss it? If not, I was thinking of writing a patch to allow %p{integer} or something like that. Is that of interest to you?
On Wed Jun 13 12:55:27 2012, FGA wrote: Show quoted text
> This can be worked around on SQL engines that support > some form of ENUM, but I'd rather just store integers. Is such a thing > possible with Log::Log4perl and did I just miss it?
You could use a custom cspec as explained in the Log::Log4perl::Layout::PatternLayout documentation: use Log::Log4perl qw(:easy); use Log::Log4perl::Level; Log::Log4perl::Layout::PatternLayout::add_global_cspec( 'Z', sub { my( $layout, $message, $category, $level, $caller_level ) = @_; return Log::Log4perl::Level::to_priority( $level ) }); Log::Log4perl->easy_init({ level => $DEBUG, layout => "%Z %m%n" }); DEBUG "debug message"; INFO "info message";