Controlling Logging in Struts Based Applications

Written by Duncan Mills, Oracle Corporation
May 2004


Applications that are built in JDeveloper 10g using the Struts controller will, by default, automatically log informational messages to the OC4J console. An example of these messages is:

    INFO: Initializing, config='org.apache.struts.util.LocalStrings', returnNull=true
    27-May-2004 10:10:45 org.apache.struts.util.PropertyMessageResources <init>
    INFO: Initializing, config='org.apache.struts.action.ActionResources', returnNull=true
    27-May-2004 10:10:46 org.apache.struts.util.PropertyMessageResources <init>
   INFO: Initializing, config='view.ApplicationResources', returnNull=true

The messages provide useful progress information for the developer, however, when deploying the application you may want to suppress the feedback, and of course when debugging the application you may actually need more information from Struts. The Struts controller uses the Apache Commons-Logging framework to handle it's logging and diagnostic needs and this article describes how to configure that logging mechanism.

Configuring Commons-Logging

The basic configuration of logging will involve the creation of two simple properties files in the /WEB-INF/classes directory of your application.

  1. Create a file This is a plain text file which is used to define the logging class that is being used. In this case we'll use the SimpleLog logger, consult the Commons Logging page for more information about the possible alternatives.
  2. In the file add a single line to define the logger to use:
  3. Create a second properties file in WEB-INF/classes called (note that the name and content of this properties file depends on the logging class that you are using, so if you select a different logger you will have to change this step accordingly)
  4. In add the line:
    Setting the value to error here will restrict the reporting to the console to only report errors. The following other reporting levels are available:
    • trace
    • debug
    • info
    • warn
    • error
    • fatal

Once these properties files are configured and added to your project, the unwanted log messages will be suppressed

drmills v1.0

false ,,,,,,,,,,,,,,,