Re: [log4perl-devel] [unclassified] Re: log and exit in one function call. How ?

2008-06-07 Thread Mike Schilli
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
[EMAIL PROTECTED]

> 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
> > [EMAIL PROTECTED]
>

-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
___
log4perl-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/log4perl-devel


Re: [log4perl-devel] [unclassified] Re: log and exit in one function call. How ?

2008-06-07 Thread Kristis Makris
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!


signature.asc
Description: This is a digitally signed message part
-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php___
log4perl-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/log4perl-devel