Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Best practices to do logging within a JSF application?

 
Kamila Rutkowski
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kamila Rutkowski
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic