• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Best practices to do logging within a JSF application?

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?)
 
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic