logo

Java logging 101

Java logging 101, overview of Java logging frameworks: Log4j, Logback, Apache Commons Logging, Java util logging (JUL) and SLF4J.

What is logging about and what is it good for? Logging is essential for debugging or maintaining your application. You must know what is going on in your application, especially when an error occures. How can you do that? Using logging.

You can type System.out.println() or exception.printStackTrace() and print your logging code into standard output. Or you can create some class and print your logging code into some file. Or you can use some logging framework.

There are many different logging frameworks. Log4j, Logback, Apache Commons Logging or Java util logging (JUL) to name few. Nowadays is mostly used Log4j.

Because there are many different logging frameworks, which one is best for your application? It's hard to say. But if you tie your code with one particular logging framework, then in the future if you get into a situation that you would want to change your logging framework, you would have to go to your code and change it. It would be nice if something would shield you from particular logging framework. And that something is framework slf4j (Simple Logging Facade for Java). It's not a logging framework, but a facade, that shields your code from particular logging framework. So if you ever want to change that logging framework, you won't have to change your code.


comments powered by Disqus

rss

Free online Java web application examples

Want to develop whole web applications which use database, security and more? See my github account, where are lot's of example projects:
github

Search