One of the oft-repeated complaints about Struts is that it doesn't emit a great deal of logging. This is actually not true, there's more being emitted than meets the eye.

Struts uses Jakarta Commons Logging (JCL) for its logging functions. JCL of course uses an underlying logging implementation to do the real work, something like Log4J or J2EE logging typically. While it is possible to configure the underlying logging implementation to see more Struts messages, there is a quick-and-dirty way that is of great interest during debugging, especially when you are experiencing a webapp that just won't start up properly.

Simply create two text files in your webapp's WEB-INF/classes folder named commons-logging.properties and simplelog.properties.

In commons-logging.properties, put the following content:

org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog

In simplelog.properties, put the following content:

org.apache.commons.logging.simplelog.defaultlog=debug

Now start your webapp and you will see probably more logging messages than you would ever want! I use this in Tomcat all the time where I start Tomcat with startup.bat, so I see everything scrolling by in the console window. Things like struts-config parse errors will become quite apparent with this.

You can set the logging level a little higher, to error perhaps, which still gives a lot of useful messages, but not quite as many.

Note that at least in Tomcat, you will see *A TON* of messages because Tomcat itself will now show its logging messages too. Like I said, it's probably *more* than you'll actually want!

But, you'll never complain about Struts not giving enough error messages again (smile)

If this gives you too much information, however, it is also possible to fine tune the sources for debug or trace level output, instead of setting the default logging level for *all* loggers. This is based on a typical convention in software that uses Commons Logging, in that a particular class "com.mycompany.mypackage.Foo" will use a logger of exactly the same name, and each uniquely named logger can have its own logging level. For example, to set the logging level for *only* Struts framework classes (all the classnames begin with org.apache.struts), you could add a line like this:

org.apache.commons.logging.simplelog.log.org.apache.struts=info

You can set logging levels for as many different loggers as you wish, to have fine grained control over which logging messages you are really interested in.

  • No labels