File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes Best practices to do logging within a JSF application? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Best practices to do logging within a JSF application?" Watch "Best practices to do logging within a JSF application?" New topic
Author

Best practices to do logging within a JSF application?

Kamila Rutkowski
Ranch Hand

Joined: Sep 22, 2009
Posts: 37
Hi,
I'm searching for a good solution to do logging in my JSF application using Java Logging API.
Could anyone please provide me a tutorial or paper about the best practice?
How can I create a Java class and use it within my DAO and JSF managed beans to log events within a file? (What are the best practices?)
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

JSF apps can use any of the popular product APIs such as log4j, java.util.log, etc. Or. if you prefer, the logging frameworks such as the apache commons logging facility that permits components using different logging products to be controlled as a unity.

I actually have a shortcut in my IDE to generate my most common logging definition:


I use this in both JSF backing beans and the Spring-managed data services and DAOs.

I do have one app that goes one step further and maintains an auditable event log as one of the application's database tables. It's a fairly blatant rip-off of the kind of things you get from things like the Windows Event Viewer: timestamp, systemID, subsystemID, user ID, severity level, message text and parameters. I just set up a utility class with a static logging method in it and injected a JPA data persistence functionality into that.


Customer surveys are for companies who didn't pay proper attention to begin with.
Kamila Rutkowski
Ranch Hand

Joined: Sep 22, 2009
Posts: 37
Thanks so very much. Could you please provide me a tutorial or sample app about this approach?

Tim Holloway wrote:JSF apps can use any of the popular product APIs such as log4j, java.util.log, etc. Or. if you prefer, the logging frameworks such as the apache commons logging facility that permits components using different logging products to be controlled as a unity.

I actually have a shortcut in my IDE to generate my most common logging definition:


I use this in both JSF backing beans and the Spring-managed data services and DAOs.

I do have one app that goes one step further and maintains an auditable event log as one of the application's database tables. It's a fairly blatant rip-off of the kind of things you get from things like the Windows Event Viewer: timestamp, systemID, subsystemID, user ID, severity level, message text and parameters. I just set up a utility class with a static logging method in it and injected a JPA data persistence functionality into that.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

Which approach do you mean? The regular logging I do just like anyone else would in any other app, once I've got a logging object using the sample statement I displayed.

For logging events to a file, I just define a database table, map it to the ORM, and have a logging utility class with an eventlog method where I pass in the information I want recorded. All the logging class does is timestamp it and write the log record to the database. It's probably no more than half a page of code, using my standard Spring JPA ORM wiring.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Best practices to do logging within a JSF application?
 
Similar Threads
New to log4j - need some advice
Exception handling
I am looking for logging best practices, do you have any advice?
JSF best practices
how to initialize a backing bean before a page loads