Steps to configure log4j in spring application
***********************************************
Step 1: log4j.properties - needs to place under class path
============================================
#loggging file details for Log4jProperties
log4j.rootCategory=DEBUG,fileAppender
log4j.appender.fileAppender=org.apache.log4j.RollingFileAppender
log4j.appender.fileAppender.File=${jboss.server.home.dir}/log/myAppLog.log
log4j.appender.fileAppender.Encoding=UTF-8
log4j.appender.fileAppender.layout.ConversionPattern=%-4d %-C : %M - %m%n
log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout
Step 2: Add jars to lib folder
=======================================
Step 3: web.xml - Log4jConfigListener configuration
=======================================
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
Step 4: Declare Member Log variable in java calss
======================================
private final Log logger = LogFactory.getLog(getClass());
Step 5: Following logger methods is used to log logger-messages
=================================================
logger.debug("Controller method");
logger.error("Controller method");
logger.warn("Controller method");
logger.info("Controller method");
Struts 2 Application Log4j Configuration:
*****************************************
Do steps 1, 2, 4, 5
***********************************************
Step 1: log4j.properties - needs to place under class path
============================================
#loggging file details for Log4jProperties
log4j.rootCategory=DEBUG,fileAppender
log4j.appender.fileAppender=org.apache.log4j.RollingFileAppender
log4j.appender.fileAppender.File=${jboss.server.home.dir}/log/myAppLog.log
log4j.appender.fileAppender.Encoding=UTF-8
log4j.appender.fileAppender.layout.ConversionPattern=%-4d %-C : %M - %m%n
log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout
Step 2: Add jars to lib folder
=======================================
Step 3: web.xml - Log4jConfigListener configuration
=======================================
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
Step 4: Declare Member Log variable in java calss
======================================
private final Log logger = LogFactory.getLog(getClass());
Step 5: Following logger methods is used to log logger-messages
=================================================
logger.debug("Controller method");
logger.error("Controller method");
logger.warn("Controller method");
logger.info("Controller method");
Struts 2 Application Log4j Configuration:
*****************************************
Do steps 1, 2, 4, 5
No comments:
Post a Comment