Exception and error safe logging

Hello, For a project I'm working on we would like to be able to attempt recovery after the occurrence exceptions and some errors, and are investigating methods of integrating the use of logback into this strategy. In the case of exceptions, does logback make any guarantee about what will/won't be thrown from the message logging methods? Is there anything like a 'safe' logging API that will not throw? Secondly we want to catch OOM errors that may occur in a call to logback. The simplest (but tedious) approach would be to wrap the calls in a try-catch block. Alternatively we are considering proxying the logger and wrapping the calls to the real logger in a try catch within the proxy. Can anyone forsee any issues with doing this? Does any kind of functionality like this already exist? Thanks in advance, Adam

On 24/08/2011 4:14 PM, Adam Fitzgerald wrote:
Hello,
For a project I'm working on we would like to be able to attempt recovery after the occurrence exceptions and some errors, and are investigating methods of integrating the use of logback into this strategy. In the case of exceptions, does logback make any guarantee about what will/won't be thrown from the message logging methods? Is there anything like a 'safe' logging API that will not throw?
Logback will never throw exceptions visible at the application layer.
Secondly we want to catch OOM errors that may occur in a call to logback. The simplest (but tedious) approach would be to wrap the calls in a try-catch block. Alternatively we are considering proxying the logger and wrapping the calls to the real logger in a try catch within the proxy. Can anyone forsee any issues with doing this? Does any kind of functionality like this already exist?
That includes OOM.
Thanks in advance, Adam -- QOS.ch, main sponsor of cal10n, logback and slf4j open source projects, is looking to hire talented software developers. For further details, see http://logback.qos.ch/job.html

Checking up on this, the AppenderBase and UnsynchronizedAppenderBase classes catch all instances java.lang.Exception and derivatives but not java.land.Error. At present time, you would need to handle OutOfMemoryError on your own. Sorry for the bs in my previous message. On 24/08/2011 5:53 PM, Ceki Gülcü wrote:
On 24/08/2011 4:14 PM, Adam Fitzgerald wrote:
Hello,
For a project I'm working on we would like to be able to attempt recovery after the occurrence exceptions and some errors, and are investigating methods of integrating the use of logback into this strategy. In the case of exceptions, does logback make any guarantee about what will/won't be thrown from the message logging methods? Is there anything like a 'safe' logging API that will not throw?
Logback will never throw exceptions visible at the application layer.
Secondly we want to catch OOM errors that may occur in a call to logback. The simplest (but tedious) approach would be to wrap the calls in a try-catch block. Alternatively we are considering proxying the logger and wrapping the calls to the real logger in a try catch within the proxy. Can anyone forsee any issues with doing this? Does any kind of functionality like this already exist?
That includes OOM.
Thanks in advance, Adam
-- QOS.ch, main sponsor of cal10n, logback and slf4j open source projects, is looking to hire talented software developers. For further details, see http://logback.qos.ch/job.html

Hello, I got a problem when trying to deploy an application into Tomcat i got this exception : org.slf4j.helpers.NOPLogger cannot be cast to ch.qos.logback.classic.Logger and the line in my code is : ch.qos.logback.classic.Logger applicationLogger = (Logger) org.slf4j.LoggerFactory.getLogger("my.logger.name"); any idea ? Thanks
Date: Wed, 24 Aug 2011 18:00:25 +0200 From: ceki@qos.ch To: logback-user@qos.ch Subject: Re: [logback-user] Exception and error safe logging
Checking up on this, the AppenderBase and UnsynchronizedAppenderBase classes catch all instances java.lang.Exception and derivatives but not java.land.Error.
At present time, you would need to handle OutOfMemoryError on your own.
Sorry for the bs in my previous message.
On 24/08/2011 5:53 PM, Ceki Gülcü wrote:
On 24/08/2011 4:14 PM, Adam Fitzgerald wrote:
Hello,
For a project I'm working on we would like to be able to attempt recovery after the occurrence exceptions and some errors, and are investigating methods of integrating the use of logback into this strategy. In the case of exceptions, does logback make any guarantee about what will/won't be thrown from the message logging methods? Is there anything like a 'safe' logging API that will not throw?
Logback will never throw exceptions visible at the application layer.
Secondly we want to catch OOM errors that may occur in a call to logback. The simplest (but tedious) approach would be to wrap the calls in a try-catch block. Alternatively we are considering proxying the logger and wrapping the calls to the real logger in a try catch within the proxy. Can anyone forsee any issues with doing this? Does any kind of functionality like this already exist?
That includes OOM.
Thanks in advance, Adam
-- QOS.ch, main sponsor of cal10n, logback and slf4j open source projects, is looking to hire talented software developers. For further details, see http://logback.qos.ch/job.html _______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user

Hello Mohammed, What does SLF4J print on the console. Does it mention defaulting to the nop-implementation? On 25/08/2011 3:21 PM, BAKHTI Mohammed wrote:
Hello,
I got a problem when trying to deploy an application into Tomcat
i got this exception : org.slf4j.helpers.NOPLogger cannot be cast to ch.qos.logback.classic.Logger
and the line in my code is : ch.qos.logback.classic.Logger applicationLogger = (Logger) org.slf4j.LoggerFactory.getLogger("my.logger.name");
any idea ?
Thanks
-- QOS.ch, main sponsor of cal10n, logback and slf4j open source projects, is looking to hire talented software developers. For further details, see http://logback.qos.ch/job.html

Hi Ceki, That's exactelly what it says : my architecture is like this : Tomcat container ------> axis2 war container ---> My service .AAR . The logback jars are in my .AAR Thanks for help
Date: Thu, 25 Aug 2011 15:45:17 +0200 From: ceki@qos.ch To: logback-user@qos.ch Subject: Re: [logback-user] org.slf4j.helpers.NOPLogger cannot be cast to ch.qos.logback.classic.Logger
Hello Mohammed,
What does SLF4J print on the console. Does it mention defaulting to the nop-implementation?
On 25/08/2011 3:21 PM, BAKHTI Mohammed wrote:
Hello,
I got a problem when trying to deploy an application into Tomcat
i got this exception : org.slf4j.helpers.NOPLogger cannot be cast to ch.qos.logback.classic.Logger
and the line in my code is : ch.qos.logback.classic.Logger applicationLogger = (Logger) org.slf4j.LoggerFactory.getLogger("my.logger.name");
any idea ?
Thanks
-- QOS.ch, main sponsor of cal10n, logback and slf4j open source projects, is looking to hire talented software developers. For further details, see http://logback.qos.ch/job.html _______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user

Where is slf4j-api.jar located? On 25/08/2011 4:21 PM, BAKHTI Mohammed wrote:
Hi Ceki,
That's exactelly what it says :
my architecture is like this :
Tomcat container ------> axis2 war container ---> My service .AAR .
The logback jars are in my .AAR
Thanks for help
Date: Thu, 25 Aug 2011 15:45:17 +0200 From: ceki@qos.ch To: logback-user@qos.ch Subject: Re: [logback-user] org.slf4j.helpers.NOPLogger cannot be cast to ch.qos.logback.classic.Logger
Hello Mohammed,
What does SLF4J print on the console. Does it mention defaulting to the nop-implementation?
On 25/08/2011 3:21 PM, BAKHTI Mohammed wrote:
Hello,
I got a problem when trying to deploy an application into Tomcat
i got this exception : org.slf4j.helpers.NOPLogger cannot be cast to ch.qos.logback.classic.Logger
and the line in my code is : ch.qos.logback.classic.Logger applicationLogger = (Logger) org.slf4j.LoggerFactory.getLogger("my.logger.name");
any idea ?
Thanks
-- QOS.ch, main sponsor of cal10n, logback and slf4j open source projects, is looking to hire talented software developers. For further details, see http://logback.qos.ch/job.html

Hello, I have an api (jar) where i configure logback appenders and loggers (in code) and add some other functions (mytraceAction()...) which will be used by all my other projects the idea is to give all projects an api so they have just to getInstance() and log (the functions added are for access and actions trace over JMS appender) Everything is working well the question is about the other API which use : log4j jcl ... how can i got their log and treat them in my api ? is it possible ? i tried to use jcl-over-slf4j ... but when they are in my libs i just don't see any other logs then those who use my api (means no spring, hibernate ... logs ) thanks

The logback docs cover redirecting log4j to slf4j. Are you saying you've written you own slf4j backend? David On 26 Aug 2011, at 15:29, BAKHTI Mohammed <onlymed@hotmail.com> wrote:
Hello,
I have an api (jar) where i configure logback appenders and loggers (in code) and add some other functions (mytraceAction()...) which will be used by all my other projects
the idea is to give all projects an api so they have just to getInstance() and log (the functions added are for access and actions trace over JMS appender)
Everything is working well the question is about the other API which use : log4j jcl ... how can i got their log and treat them in my api ? is it possible ?
i tried to use jcl-over-slf4j ... but when they are in my libs i just don't see any other logs then those who use my api (means no spring, hibernate ... logs )
thanks
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user

Hello David, I'm not writting SLF4J i'm just using logback in programmatically configuration way. The idea is to have a logger configured inside an API which will be used by all the other applications, so i have created just some classes (with apprenders...) which implements logger and call super.debug.... and add my other functions ( with specific behaviors : ie mytrace will send entry data to an activemq...) . in this class i configure all the appenders and attach them to the root logger . this way if an application is using a file logback.xml it will be ignored (actually the configuration will be rewrited by my api) As those classes uses Appender and other stuff that are not implemented (not yet) in log4j-over-slf4j so can't be used So now to get log4j logs to be redirected to my API i use a something like : create a class which extends log4j appender, transfrom the log4j LoggingEvent to logback LoggingEvent and then call doAppend of my API Log4j config : log4j.rootLogger=INFO, out # Log level for each package #Redirect all log4j calls to my api log4j.appender.out=com.company.api.tool.Log4JWrapper Is there any other way more clean to do that ? Thanks
CC: logback-user@qos.ch From: nabble@diroussel.xsmail.com Date: Sat, 27 Aug 2011 20:14:54 +0100 To: logback-user@qos.ch Subject: Re: [logback-user] How to redirect log4j and other to logback ?
The logback docs cover redirecting log4j to slf4j.
Are you saying you've written you own slf4j backend?
David
On 26 Aug 2011, at 15:29, BAKHTI Mohammed <onlymed@hotmail.com> wrote:
Hello,
I have an api (jar) where i configure logback appenders and loggers (in code) and add some other functions (mytraceAction()...) which will be used by all my other projects
the idea is to give all projects an api so they have just to getInstance() and log (the functions added are for access and actions trace over JMS appender)
Everything is working well the question is about the other API which use : log4j jcl ... how can i got their log and treat them in my api ? is it possible ?
i tried to use jcl-over-slf4j ... but when they are in my libs i just don't see any other logs then those who use my api (means no spring, hibernate ... logs )
thanks
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user

Thanks for the quick reply! What are the chances of this being changed (or a change being accepted) to catch errors as well? My understanding is that there is logic being done from the Logger logging methods, before the Appenders are invoked. Would it make more sense for us to wrap these methods, to give as strong a 'guarantee' as possible that we will not throw? Thanks again, Adam On Wed, Aug 24, 2011 at 12:00 PM, Ceki Gülcü <ceki@qos.ch> wrote:
Checking up on this, the AppenderBase and UnsynchronizedAppenderBase classes catch all instances java.lang.Exception and derivatives but not java.land.Error.
At present time, you would need to handle OutOfMemoryError on your own.
Sorry for the bs in my previous message.
On 24/08/2011 5:53 PM, Ceki Gülcü wrote:
On 24/08/2011 4:14 PM, Adam Fitzgerald wrote:
Hello,
For a project I'm working on we would like to be able to attempt recovery after the occurrence exceptions and some errors, and are investigating methods of integrating the use of logback into this strategy. In the case of exceptions, does logback make any guarantee about what will/won't be thrown from the message logging methods? Is there anything like a 'safe' logging API that will not throw?
Logback will never throw exceptions visible at the application layer.
Secondly we want to catch OOM errors that may occur in a call to logback. The simplest (but tedious) approach would be to wrap the calls in a try-catch block. Alternatively we are considering proxying the logger and wrapping the calls to the real logger in a try catch within the proxy. Can anyone forsee any issues with doing this? Does any kind of functionality like this already exist?
That includes OOM.
Thanks in advance, Adam
-- QOS.ch, main sponsor of cal10n, logback and slf4j open source projects, is looking to hire talented software developers. For further details, see http://logback.qos.ch/job.html _______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user
participants (4)
-
Adam Fitzgerald
-
BAKHTI Mohammed
-
Ceki Gülcü
-
David Roussel