For method entry and exits, use the syntax below:
For exception logging, use the syntax below and y ou can put any detailed description required and don’t forget to use SEVERE or a least WARN:
General comment:
It will help save some memory during normal operation as it avoids filling the String pool with objects which will not be used.
There is no need to do so with SEVERE, INFO and WARN as they are enabled by default.
LOGGER.entering(CLASSNAME, METHOD_NAME);LOGGER.exiting(CLASSNAME, METHOD_NAME);instead of:
LOGGER.logp(Level.INFO,CLASSNAME, METHODNAME,"entering");
LOGGER.log(Level.SEVERE,"Exception caused by "+e.getMessage(), e);
instead of:
e.printStackTrace();
One of the worst things is to log a critical Exception as a trace level (e.g. Level.FINEST), as no one will see it right away and it can hide coding bugs during the development cycle till it is too late.
It is recommended to surround all level with an if statement as shown in the two examples below:
if(LOGGER.isLoggable(WsLevel.FINE)){ LOGGER.logp(Level.FINE, CLASSNAME, METHOD_NAME, "Test1: "+test2);}if(LOGGER.isLoggable(WsLevel.FINEST)){ LOGGER.logp(Level.FINEST, CLASSNAME, METHOD_NAME, "Test2: "+test2);}
Instead of just
LOGGER.logp(Level.FINE, CLASSNAME, METHOD_NAME, "Test1: "+test1); LOGGER.logp(Level.FINEST, CLASSNAME, METHOD_NAME, "Test2: "+test2);
There is no need to do so with SEVERE, INFO and WARN as they are enabled by default.
No comments:
Post a Comment