tags:

views:

1573

answers:

8

I've evaluated Log4j and Commons Logging, along with Java's built-in logging, however frankly all of these frameworks seem over-engineered, and over-complicated, requiring excessive configuration just to achieve basic functionality.

Is anyone aware of a simple, yet flexible open source Java logging framework?

Update: In response to a question below, I'd say that my priority is simplicity. I'm no Java lightweight, but I find the log4j config file to be rather confusing and unintuitive. Also, something that allows easy runtime configuration of the logging framework would be valuable.

+4  A: 

Simple Logging Facade for Java (SLF4J) (http://www.slf4j.org/)

or the built-in logging API available starting with Java 1.4 (http://java.sun.com/j2se/1.4.2/docs/guide/util/logging/overview.html)

Michael
A: 

Java Logging?????

or

Wrap log4j and simplify the APIs.....

l_39217_l
Question mentions that built-in logging has been evaluated.
Simon Steele
+4  A: 

IMHO, log4j is one of the simplest frameworks. You need one configuration file in the classpath, and that must contain just 5 lines (the default logger rules):

log4j.properties:

log4j.rootLogger=WARN, FILE
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=xxx.log
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d{ISO8601} %-5p %c %x - %m%n
mfx
Sad thing with log4j is that you don't get any logging with the default configuration. I second Andreas' suggestion on using SLF4J. This gives you the opportunity to switch at a later time without changing a lot of code.
Asgeir S. Nilsen
+1  A: 

You may find this article to be of interest:

http://java.sys-con.com/node/44698

In particular, it shows how to configure Java Logging to intercept the System.out and System.err streams on a Thread-by-Thread basis. That will allow you to convert all your existing output to a fancy logging system, but without the hassle of adding a LoggerOutputStream to the top of every class.

64BitBob
A: 

I think that @mfx has the right of it up above -- Log4J is already pretty lightweight, requiring only a very slender configuration file.

Your requirements up above aren't too clear, though; can you edit your question to clarify what you mean by "simple, yet flexible"? Simplicity and flexibility do tend to stand in opposition to each other; which one is your higher priority?

Jim Kiley
+2  A: 

Java has Logger class and you can simply use it.
But Apache Log 4j is a standard logging framework for java developers.

amadamala
+1  A: 

I would always prefer a Logging facade instead of the framework directly. Advantages: - change the underlying logging framework by configuration - combine your program code with other 3rd party libs an use a common implementation

Like Michael, I recommend the slf4j Libraries because there is no magic about finding the right implementation. It's also very easy to understand and you can combine it even with an own implementation. Another advantage of slf4j is, that the jars are already osgi ready, which makes it very interesting for me.

I am in no way associated with slf4j, just a big fan of it. ;)

Roland Schneider
+12  A: 

I would recommend using SLF4J and its slf4j-simple implementation. SLF4J supports switching the logging framework at runtime and that way you can start with zero configuration logging to the console.

Later on when your project grows to the point where you need fine-grained logging you can switch over to using Log4J, JDK logging or maybe Logback.

Andreas Holstenson
One nice thing about LogBack is also the Eclipse console plugin (http://logback.qos.ch/consolePlugin.html). I for one is sick and tired of grepping and other nasty stuff to get the important messages to stand out.
Asgeir S. Nilsen