O'Reilly logo

Jakarta Struts Cookbook by Bill Siggelkow

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

13.2. Configuring Struts Logging

Problem

You need to set the severity level and details of the log messages generated by internal Struts components.

Solution

Configure Struts logging to use Log4J as its logging implementation:

  1. Download the Log4J jar file from http://jakarta.apache.org/log4j.

  2. Copy the jar file to your application's WEB-INF/lib folder.

  3. Set the log level and log destination (referred to as an appender) for all Struts packages (org.apache.struts), as shown in Example 13-1 (log4j.properties). Place this file in your application's WEB-INF/classes folder.

Example 13-1. Configuring Log4J for Struts packages

# The output information consists of relative time, log level, thread # name, logger name, nested diagnostic context and the message in that # order. # For the general syntax of property based configuration files see the # documentation of org.apache.log4j.PropertyConfigurator. log4j.rootLogger=WARN,Console log4j.logger.org.apache.struts=DEBUG,Console,File log4j.appender.Console=org.apache.log4j.ConsoleAppender log4j.appender.Console.layout=org.apache.log4j.PatternLayout log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p %c - %m%n # File is set to be a FileAppender which outputs to struts-debug.log log4j.appender.File=org.apache.log4j.FileAppender log4j.appender.File.file=struts-log.log # File uses PatternLayout. log4j.appender.File.layout=org.apache.log4j.PatternLayout # The conversion pattern uses format specifiers. You might want to # change the pattern an watch ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required