Logging in Struts with Log4j – Java Example

Log4j Struts

This example shows how to configure logging in Struts framework or struts2 application using Log4j.

Below Java code uses Logger instance for debug from apache log4j library configured using properties file.

Download Log4j: http://logging.apache.org/log4j/index.html

Log4j Appender:
Create a Log4j properties file (log4j.properties) and define the appender details (where to log and log file details). And put the log4j.properties into your project classpath.

log4j.properties

Struts Action Class:

Struts Custom Exception Handler:

Log4j Output File Sample- c:\\logging.log

Share This Post On: