From: Kristis M. <kri...@as...> - 2008-06-04 05:35:55
|
Hello, I'm trying to use log4perl to log a message and immediately die. I got the impression that something like: $logger->error_die( "my error message" ); should be enough, but instead calling this function reports the error message twice. I essentially need log4perl to do something like: $logger->error ("my error message"); die; or preferably: $logger->error ("my error message"); die $error_number; How can I do that ? I've tried logdie, logwarn, error_warn, logcroak, logconfess without success. I either get duplicate error messages printed, not dying, or a combination of the two. I must be missing something obvious. Can someone help please ? Thanks, Kristis |
From: Mike S. <m...@pe...> - 2008-06-05 06:40:48
|
On Tue, 3 Jun 2008, Kristis Makris wrote: > How can I do that ? I've tried logdie, logwarn, error_warn, logcroak, > logconfess without success. I either get duplicate error messages > printed, not dying, or a combination of the two. If you want the error message only once, check the section "Suppressing 'duplicate' LOGDIE messages": http://log4perl.sourceforge.net/d/Log/Log4perl.html#a722d -- Mike Mike Schilli m...@pe... |
From: Kristis M. <kri...@as...> - 2008-06-05 16:00:59
|
Hey Mike, thanks again for your help. Would it make sense to have another interface that allows one to specify the exit value ? Doing the following e.g. $Log::Log4perl::LOGEXIT_CODE = 113; $logger->logdie( "my message" ); Is still two lines of code instead of one. I was hoping for the possibility that a function like: $logger->logdie ( "my message", 113 ); existed, or could be added in log4perl. I mean, I don't see how what is suggested for suppressing duplicate logdie messages is any different, or more efficient, than: $logger->error( "my message" ) && exit 113; In particular, I'm trying to "format" messages before I emit them through the logger. This requires me to always call something like: $logger->error ( my_special_function_that_formats_the_message ( $error_value, "my message") ); and I'm trying to avoid calling $logger->error ( my_special_function_that_formats_the_message ( $error_value, "my message") ) && exit $error_value; This all looks and feel dirty. I'm essentially constructing parts of the ConversionPattern (perhaps there's a better way to do this). Would it be a good idea for log4perl to provide a way for both allowing multiple arguments supplied to the ConversionPattern, and also supplying an (optional) error code ? It is natural that error log messages also contain an error value. I'd like to construct the message in the ConversionPattern to include the error code, and also exit with that error code. On Wed, 2008-06-04 at 23:40 -0700, Mike Schilli wrote: > On Tue, 3 Jun 2008, Kristis Makris wrote: > > > How can I do that ? I've tried logdie, logwarn, error_warn, logcroak, > > logconfess without success. I either get duplicate error messages > > printed, not dying, or a combination of the two. > > If you want the error message only once, check the section "Suppressing > 'duplicate' LOGDIE messages": > > http://log4perl.sourceforge.net/d/Log/Log4perl.html#a722d > > -- Mike > > Mike Schilli > m...@pe... |
From: Mike S. <m...@pe...> - 2008-06-07 20:18:08
|
On Thu, 5 Jun 2008, Kristis Makris wrote: > Would it make sense to have another interface that allows one to > specify the exit value ? Doing the following e.g. > $Log::Log4perl::LOGEXIT_CODE = 113; > $logger->logdie( "my message" ); > Is still two lines of code instead of one. I was hoping for the > possibility that a function like: > $logger->logdie ( "my message", 113 ); That won't work, as passing multiple arguments to any logger function has a different meaning already: http://log4perl.sourceforge.net/d/Log/Log4perl/Appender.html#30d43 > In particular, I'm trying to "format" messages before I emit them > through the logger. This requires me to always call something like: > $logger->error ( my_special_function_that_formats_the_message > ( $error_value, "my message") ); > and I'm trying to avoid calling > $logger->error ( my_special_function_that_formats_the_message > ( $error_value, "my message") ) && exit $error_value; > This all looks and feel dirty. I'd rather use MDC and a PatternLayout for that: http://log4perl.sourceforge.net/d/Log/Log4perl.html#4b5b3 If you'd rather like a two-argument function that takes a message and an error code, you can write a wrapper library around Log4perl that does exactly that, just increase $Log::Log4perl::caller_depth: http://log4perl.sourceforge.net/d/Log/Log4perl.html#6acb7 -- Mike Mike Schilli m...@pe... > I'm essentially constructing parts of the ConversionPattern (perhaps > there's a better way to do this). Would it be a good idea for log4perl > to provide a way for both allowing multiple arguments supplied to the > ConversionPattern, and also supplying an (optional) error code ? It is > natural that error log messages also contain an error value. I'd like to > construct the message in the ConversionPattern to include the error > code, and also exit with that error code. > > > On Wed, 2008-06-04 at 23:40 -0700, Mike Schilli wrote: > > On Tue, 3 Jun 2008, Kristis Makris wrote: > > > > > How can I do that ? I've tried logdie, logwarn, error_warn, logcroak, > > > logconfess without success. I either get duplicate error messages > > > printed, not dying, or a combination of the two. > > > > If you want the error message only once, check the section "Suppressing > > 'duplicate' LOGDIE messages": > > > > http://log4perl.sourceforge.net/d/Log/Log4perl.html#a722d > > > > -- Mike > > > > Mike Schilli > > m...@pe... > |
From: Kristis M. <kri...@as...> - 2008-06-07 21:13:58
|
On Sat, 2008-06-07 at 13:18 -0700, Mike Schilli wrote: > If you'd rather like a two-argument function that takes a message and an > error code, you can write a wrapper library around Log4perl that does > exactly that, just increase $Log::Log4perl::caller_depth: > > http://log4perl.sourceforge.net/d/Log/Log4perl.html#6acb7 Oh, that's precisely what I want. Many thanks Mike. This is great! |