Title: What is the safest logging framework for a web application using existing libraries?
Tags: java;logging;frameworks
Question: I need to decide on a logging framework for a new web application running in containers (Tomcat, JBoss...). This application references java libraries using different logging frameworks.

My reading indicates that some logging frameworks do not work well in container because of classloader issues. I am also reading that this is not an issue anymore. The situation is confusing. What is the status?

It seems like using SLF4J and redirecting to Log4J + using bridges to SLF4J for referenced Java libraries (when necessary) is the safe solution.

Which logging framework should I use for my web application and remain on the safe side?

Comment: Can you use the logging framework which comes with the container or the logging framework which come with Java?

Comment: Given your requirements I would use SLF4J but I have only used Apache Karaf lately. ;)

Comment: The application can be deployed in different containers. Otherwise, I have no restrictions except those mentioned in the question.

Here is the accepted answer: After digging the subject deeper, I can conclude the following:


The classloader issues are mostly reported around the Jakarta Common Logging (JCL) interface.
In order to tackle the multiple logging frameworks used in different Java libraries, a logging interface such as SLF4J or JCL is necessary.
SLF4J is a safe solution for web applications running in containers. It is preferable to accessing the logger provided by the container regarding portability issues.


I have summarized my findings in a blog post.

Comment for this answer: Sounds about right. One caveat is that some libraries may be using JBoss Logging, which is yet another logging facade - Hibernate 4 is a notable example. JBoss Logging tries to autodetect a logging provider; if you are using log4j or Logback, it will find and use those. However, if you are using SLF4J and some other provider (eg Gossip, AVSL), then JBoss Logging won't find it, and will use java.util.logging.

Here is another answer: You can (and should) deploy your own logging libraries with your web application. There is no guarantee what logging system will be supported on a server, nor how it will be configured. By providing your own, you can tailor it to your applications needs. 

So unless you get to specify and manage the application server, ship what you want to use with your application.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2012:00:10/16/12', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<java><logging><frameworks>', 'Title': 'What is the safest logging framework for a web application using existing libraries?', 'ViewCount': 663, 'id': 12913616, 'user_AboutMe': '<p>You can contact me via my LinkedIn <a href="http://www.linkedin.com/in/jerome-verstrynge" rel="nofollow noreferrer">profile</a>. </p>\n', 'user_AccountId': 246686.0, 'user_DisplayName': 'Jérôme Verstrynge', 'user_Reputation': 55864.0, 'user_Views': 4960.0, 'user_id': 520957.0}}