Step 1 :
create file log4j.properties in $project_home/src/
log4j.appender.portlet = org.apache.log4j.FileAppender
# log file will be in tomcat/logs/
log4j.appender.portlet.File = ${catalina.home}/logs/privatemessage.log
log4j.appender.portlet.Append = false
log4j.appender.portlet.layout = org.apache.log4j.PatternLayout
log4j.appender.portlet.layout.ConversionPattern = %d{ABSOLUTE} [%t] %-5p %-30.30c{2} %x - %m %n
# only log errors
log4j.rootCategory=WARN, portlet
# log trace messages from this package and sub packages
log4j.logger.com.cisco.project=TRACE
Step 2 :
add these lines to web.xml
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
Step 3 :
Use logger in your java classes, before add log4j library to your project classpath
// add imports
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
// define
private static Log logger = LogFactory.getLog(PostLogin.class);
// use this way
logger.trace(" Begin PostLoginHook.... ");
if ( logger.isDebugEnabled() ) {
logger.debug("inside method");
}
Comments