Skip Menu |

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

Report information
The Basics
Id: 84289
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.40
Fixed in: (no value)



Subject: Lowering logging threshold "down to" value
Hi, I have a web application that's using L4P for logging. Sometimes an extra worker may be created for a background task, and that background task needs to have a decreased logging threshold to capture more detailed output. I can do something like $logger->level($INFO) to set it up, but if I'm in my development environment, the initial logging threshold may be $DEBUG, so in that case I'm actually increasing the logging threshold... Similarly, in order to keep the same code between the development and production environments, I can't just do ->dec_level or ->more_logging, since I don't know what level I'm starting at. It sounds like I should be able to hack something around min($desired_numeric_level, $current_numeric_level), but the docs say "The numerical values assigned to these constants are purely virtual, only used by Log::Log4perl internally and can change at any time, so please don't make any assumptions." Should I go ahead and make assumptions anyway? Can I assume at least that logging levels will remain consistently ordered?
On Fri Mar 29 11:37:06 2013, FGA wrote: Show quoted text
> I can do something like $logger->level($INFO) to set it up, but if I'm > in my development environment, the initial logging threshold may be > $DEBUG, so in that case I'm actually increasing the logging > threshold...
Yeah, you need to check first if it's appropriate to set the level to that level by comparing the logger's actual level to the desired level: use strict; use Log::Log4perl qw(:easy); Log::Log4perl->easy_init($INFO); my $logger = get_logger(); my $desired_level = $INFO; if( Log::Log4perl::Level::isGreaterOrEqual( $logger->level(), $desired_level ) ) { print "Just fine\n"; } else { print "Needs to change\n"; $logger->level( $desired_level ); } The isGreaterOrEqual function wasn't documented yet, I've just added it: https://github.com/mschilli/log4perl/commit/52f4f55f6acc9daefe887752948aca34ce50b8e2 Hope that helps! -- Mike
On Fri, 29 Mar 2013 22:27:08 -0400, MSCHILLI wrote: Show quoted text
> The isGreaterOrEqual function wasn't documented yet, I've just added > it: > https://github.com/mschilli/log4perl/commit/52f4f55f6acc9daefe887752948aca34ce50b8e2 > > Hope that helps! -- Mike
OK, so that was the trick. Thanks again for your help!
Somehow this bug got reopened, even though I kept the status to "resolved (unchanged)". Closing again.