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.
Joined: Jan 22, 2013
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.