logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pedro Costa" <pedro.co...@link.pt>
Subject RE: Logger.error
Date Fri, 03 Feb 2006 14:32:54 GMT
Good answer. You're totally right. Thanks.

-----Original Message-----
From: Tobias Mantsch [mailto:t.mantsch@durato.de] 
Sent: sexta-feira, 3 de Fevereiro de 2006 14:20
To: Log4J Users List
Subject: AW: Logger.error

It is correct to write it the way you wrote. As an alternative you could
also write something like the following:

try {
	//something
} catch (Exception e) {
	logger.error("Exception in <yourMethodName>", e);
}

The logger provides a method to log a message of type String and a
Throwable, so you don't have to concatenate the strings in the log-message.

But I would definitely not alter the constructor of PortletException so that
it handles the logging itself. Especially in your example there would be no
benefit from it, as there still would be the possibility of a IOException to
be thrown and thus you would still have to catch this one and log it. 
As a second side effect you would limit the usability of PortletException as
it would always depend on log4j. So I would consider it not very good design
to let the Exception execute the logging.

Regards
________________________________

Tobias Mantsch

durato Ltd.
Allensteiner Str. 79
56566 Neuwied

Tel.: 02631 / 952980-11
Fax: 02631 / 952980-99
t.mantsch@durato.de | www.durato.de 
________________________________

-----Urspr√ľngliche Nachricht-----
Von: Venkatray Kamath [mailto:Venkatray.Kamath@tavant.com] 
Gesendet: Freitag, 3. Februar 2006 13:48
An: 'Log4J Users List'
Betreff: RE: Logger.error

U could log the application exceptions as soon as exception object instance
is created ie in your case the constructor of PortletException can invoke
logger.error(); so that u don't depend on the client to log the exception.

-----Original Message-----
From: Pedro Costa [mailto:pedro.costa@link.pt]
Sent: Friday, February 03, 2006 6:15 PM
To: log4j-user@logging.apache.org
Subject: Logger.error

The Logger.error is a good method to print java exceptions?

If so, if I catch two java exceptions, for example:

                try {
                                //something
                        } catch (PortletException e) {
                                logger.error("Exception was: " + e);
                        } catch (IOException e) {
                                logger.error("Exception was: " + e);
},

Is it correct to change this snippet into something like this?

                        try {
                                //something
                        } catch (Exception e) {
                                logger.error("Exception was: " + e);
}
-----------------
PSC



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message