Sunday, July 11, 2010

Log statements in JSP

Hi,
Sometimes it is helpful have log statements in JSPS. Unfortunately if we have lot of business logic embedded in JSP’s. It is better to have log statements.

To add log statement in JSP
• Import logger
o <%@page import="org.apache.log4j.Logger"%>
• Provide the logger name, FQN name of the JSP
o private static final Logger logger = Logger.getLogger("portlet.ext.watching_portlet.view.jsp");
• Add the log statements as mentioned in the guide lines
o logger.warn("Unable to find thread associated to subscription");

Best practice:

Please don’t rely on toString method to get the exception stack trace.
Poor: logger.warn("Unable to find thread associated to subscription"+e);
Good: logger.warn("Unable to find thread associated to subscription",e);//exception stack trace will be logged, even if api doesn’t override the toString method

Changing JSP Editor font Eclipse:

By default JSP editor uses text editor for font settings . Change the setting by

Window->preferences->general-appearance->colors and fonts-Basic->Text font

Followers