Struts is an open source framework useful in building web applications with Java Servlet and JavaServer Pages (JSP) technology, based on the Model-View-Controller (MVC) design paradigm.
Struts is copyrighted software available under a "free-to-use-license" by the Apache Software Foundation. The license appears at the head of every source code file.

The latest Struts version can be downloaded from:

Setup logging with Log4j using Struts 1.2.4 on Tomcat 4.1.3.


Operating system used
Windows XP Home Edition Version 5.1 SP 2

Software prerequisites
Log4j 1.2.9
Struts 1.2.4
Tomcat 4.1.3

  1. Download and unzip Log4j.

  2. In the unzipped log4j directory copy file C:\Tools\logging-log4j-1.2.9\dist\lib\log4j-1.2.9.jar to your Struts project: <my_project>\WEB-INF\lib\log4j-1.2.9.jar

  3. Create a file.
    As an example you can put the following lines in the file:

    log4j.rootLogger=ERROR, stdout
    log4j.appender.stdout.layout.ConversionPattern=[%5p] %d{mm:ss} (%F:%M:%L)%n%m%n%n

    Remark: The ConversionPattern creates the following message:

    [ERROR] 02:44 (com.mobilefish.DemoAction execute:95)
    This is my message.

  4. Put the file in the following location:


    Note: In some situations the can not be located by the application server. To find out if this is the case set the -Dlog4j.debug=true.

    In the quick guide "Loading the file" serveral solutions are mentioned how to solve this problem.

  5. Add the following lines in your Java code:

    package com.mobilefish;

    // Please note the following: Struts 1.2.4 uses commons-logging
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;

    public class DemoAction extends Action {

          private static Log log = LogFactory.getLog("com.mobilefish.DemoAction");

          public ActionForward execute(
             ActionMapping mapping,
             ActionForm form,
             HttpServletRequest request,
             HttpServletResponse response)
             throws Exception {

             log.debug("This is my debug message.");
   "This is my info message.");
             log.warn("This is my warn message.");
             log.error("This is my error message.");
             log.fatal("This is my fatal message.");


  6. Start the application server and run your web application.
    Because log4j.rootLogger=ERROR (see file), the following messages are displayed in the console:

    [ERROR] 23:35 (
    This is my error message.

    [FATAL] 23:35 (
    This is my fatal message.

    Note 1. Loggers can be assigned to the following ORDERD levels:

    Note 2. To enable all log messages:

    Be warned: the struts code and your web applications log messages are logged.

    Note 3. To disable all log messages: