aspose file tools*
The moose likes Struts and the fly likes Logging strategy Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Logging strategy" Watch "Logging strategy" New topic
Author

Logging strategy

JW Li
Ranch Hand

Joined: Mar 11, 2003
Posts: 33
Hi, what's a better logging strategy for struts2? In Struts 1, I used to create my own LogService using JDK logging as Struts Plug In, which got initialized when application starts. What my log service did is to archive the past application logs and create new logger&handler for different type of logs for my application. In Struts2's XML file, I didn't find corresponding plugIn place to initialize my own application-wise service at startup, and struts-plugIn.xml seems to talk about a different type of plugIn than my old Struts1 plugIn, or is it? Struts2's ActionSupport has a Log static member using Apache commons, is it a better way to handle logging? What's a better strategy of doing logging in Struts2 application, which will not only archive past logs at startup, but also differentiate a different type of logs to different log files. Thanks!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Personally I'd recommend using something like Log4J, along with its various file-based log appenders.

Dave
JW Li
Ranch Hand

Joined: Mar 11, 2003
Posts: 33
Thanks for your reply. But how could we take advantage of the commons.logging.LOG static member in ActionSupport? I think it exists there for a reason... Reading commons.logging documentation, I know the LogFactory will search for different configuration (such as log4J or JDK), but it does not go into details on how to configure for each so that LOG static member in the AcitionSupport class could be helpful (such as writing log to a file, very common requirement for an application, currently without any configuration, my struts2 application log goes to the stdout). Could you give a little bit instruction and analysis on this? In your book, is it covered? Thanks!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

The book does not go into detail about configuring every possible logging implementation. I'm not overly-familiar with the member you're referring to; I generally just declare a static Log instance in each of my actions and follow standard Log4J configuration conventions depending on the application's particular logging needs.

Dave
JW Li
Ranch Hand

Joined: Mar 11, 2003
Posts: 33
Thanks! BTW, the member I was talking about is a static member LOG (protected static Log) in com.opensymphony.xwork2.ActionSupport class.
The API could be found at http://struts.apache.org/2.0.11.2/struts2-core/apidocs/index.html

Thanks again for your reply!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That looks like it's just Commons Loggins Log instance, which would use whatever underlying logging implementation the application is configured to use. It's handy, but in general I'd imagine more-specific logs would be used, allowing for a more fine-grained logging configuration.

Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Logging strategy
 
Similar Threads
Error in building an application using Struts2
migration to Struts2
struts2 action-method-validation.xml not working?
Struts2 cookies
Intergration of Struts2 and EJB3.0 using struts2-ejb3-plugin