This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence 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 all forums
this forum made possible by our volunteer staff, including ...
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Suggest for Logging solution  RSS feed

Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • 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
  • 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:

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!