Question: I have some questions about logging, more specifically about setting it up and making sure it works.

The project I'm doing will use [Wicket](http://wicket.apache.org/), [Spring](http://www.springsource.org/) and [Hibernate](http://www.hibernate.org/). I know that Wicket and Hibernate uses Simple Logging Facade for Java ([SL4J](http://www.slf4j.org/)) and that Spring is using the [logging component from Apache Commons](http://commons.apache.org/logging/).

Will they co-exist happily?
I thought I would use [log4j](http://logging.apache.org/log4j/1.2/index.html) together with both SL4J and the logging component from Apache commons, do you think that's a good idea?

Can I set up them all to output logging data into a common file?
Or should I use separate files?
Or should I store the logging messages in the database? (I'd rather not, as I find grepping etc on text files quite convenient.)

For Spring I guess I need some kind of configuration file for the Apache Commons logging component as well where I direct it to use log4j?

When I've set these up I guess to see that everything works I set the logging level to INFO as it's fairly certain that all three of the frameworks output some information in that mode? Or is there an even better way to make sure?

And my last question. In the project I'm starting, do you recommend that I use SL4J for my own logging purposes? (I thought I would use log4j directly, but that was before I learned a little bit more about logging and a lot of respectable libraries seem to choose the path of a bridge/facade for their logging needs. And if it gets us flexibility without added cost there's no reason not to do it that way.)

I'm looking forward to hearing more from you about how you are doing your logging. It's a new area for me which I'm eager to improve myself in.

Answer: 
Well SLF4J is just a facade, like commons logging, which means they still need something else to work. They permit library authors to not force users into having multiple logging library and configuration. Log4j and logback are regular logging libs.

See [here](https://stackoverflow.com/questions/354837/whats-up-with-logging-in-java) for more info.

SLF4J has a [commons logging bridge](http://www.slf4j.org/legacy.html) that you can use to replace the commons logging library. I think the schema there explain the situation very well.

Now, you just need to use slf4j-logj12.jar to have commons logging and slf4j use log4j (or anything else you chose; btw, logback doesn't need an additional library to be used with slf4j) as a backing engine.

You application will thus have

* jcl104-over-slf4j.jar (to bridge jakarta commons logging to slf4j)
* slf4j.jar (for hibernate and others to use slf4j)
* slf4j-logj12.jar (for slf4j to use log4j as a backend)
* log4j.jar (for your application to use. all config will also be done here)
Here is how to redirect everything to SLF4J:

* remove `commons-logging.jar` from your classpath. If you are using Maven and have trouble getting rid of commons-logging, see [this](http://day-to-day-stuff.blogspot.com/2007/07/no-more-commons-logging.html).
* put `jcl-over-slf4j.jar` in your classpath (it comes in the SLF4J distribution). This is a drop-in replacement that mimics JCL's classes, but calls SLF4J internally. This will take care of Spring, and any other framework that uses JCL.

Connect SLF4J to your favorite backend (Log4J, Logback...) by putting `slf4j-xxx.jar` in the classpath. Configure the backend to log all categories to one file, and you're done.

As for using SLF4J in your application, it is not strictly necessary. Libraries like JCL and SLF4J were originally designed for people who write libraries and do no want to lock their clients into a particular logging framework.

PS: by the way, JCL = Jakarta Commons Logging