Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Suggest for Logging solution

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've worked with logging in Java years ago, but now I wanted a better solution. At that time I worked with java.util.logging and read about Log4j, and now I see there's Jakarta Commons Logging too. I'd be very thankful if somebody more experienced could suggest me which to choose.

My main needs are:

1) Easy to use. During development, if I wanna quickly test the content of an object, instead of using System.out I can just use logger.finer("test01 "+object.toString())
2) Easy to configure. By my own code (and not some xml or property file I must put in a very specific folder), I set its OutputStream to some txt file I created, or just route its logs to stdout if I'm inside Eclipse, or just shut lower levels out, or route higher levels logs to 1 file and lower levels logs to another file.
3) Be able to format its output. Once in production, I'd like to use XML to format logs (in case someday I need to prepare some report based on these logs, it will be easy to read and process them), and use XSL to format it into XHTML for easy viewing.

When I read about Log4j years ago I didn't like it, because it didn't seem to have any better feature than java.util.logging, but I don't know how it is now. I'll read about Jakarta Logging to see if it's worthy.
 
Hikari Shidou
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After reading about these frameworks, I decided java.util.logging is really the best and simplest solution.

I just used a XML file with configs for setting up logger. From this file I can set it to print in stdout or to a file, and set its format to XMLFormatter or a custom simpler format:



That's working pretty well for stdout logging. Each line gets larger than SimpleFormatter, but now I easily see that each log is in 1 line. If the log has a throwable, it also prints that throwable, with the advantage of it printing full stack trace, without those boring "more" texts when stack is too big.

An example of the result:


 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic