Logback logs are not working. Log4j logs are not working. Steps to make logging work.

Logs are not working in application even jar is present in application is the very common problem faced by mostly every java developer .Steps to tackle and solve this problem is what i am going to share today.

Mostly problems come as :
1. Logs were working with previous version of server but not working after upgrade.
2. Log4j logs are not working.
3. Logback logs are not working. etc.

Steps to tackle these problems.

Step 1 : First check if respected jars are present in your application.
Jars for log4j : log4j-api.jar,log4j-core.jar
Jars for logback : logback-core.jar,logback-classic.jar,sl4j.jar

Step 2 : Now if logs are not still working then there is possibilty that your server have these jars with some other implementation.
For eg : Weblogic server have sl4j.jar with jcl logging. So inspite of having jar in your application logback logs will not work.
To solve this problem you can easily find out on google that how to reference application jar in weblogic or how to reference application jar in websphere etc.

If the problem still persist then you need to go to step-3;

Step 3 : Now the problem could be that jar are getting picked up from application but some other jar is also having the same package or server is still picking jars from it’s own directory. To find out that which jar server is picking up use below code in one class and try to call that method somehow to execute below code.

System.out.println(“printing class paths–>”+Logger.class.getProtectionDomain().getCodeSource().getLocation().toURI().toString());
System.out.println(“printing class paths–>”+LoggerFactory.class.getProtectionDomain().getCodeSource().getLocation().toURI().toString());
System.out.println(“printing class paths–>”+StaticLoggerBinder.class.getProtectionDomain().getCodeSource().getLocation().toURI().toString());
catch(Exception e){
System.out.println(“Error in printing class paths”);

Above code is for logback logs and the classes used in this code are classes used for logback logging so you can change according to your logging. What this code is doing that it is printing location of a particular class that from which jar and from which location this class is getting picked up at runtime.

After this you will get your answer that which jar you need to concentrate oor remove from your application to make your logging work.

Please add comments and share if you find it useful or point out mistakes if you find any.

Some other useful post are :

Set datasource spring bean properties dynamically if server is not available
MQ connection not closed and giving MQ Error-2009


7 thoughts on “Logback logs are not working. Log4j logs are not working. Steps to make logging work.

  1. Pingback: JPA Hibernate Sequence generator generating odd ID value and IntegrityConstraintVolation exception is coming | Blogger's Views

  2. Pingback: HTML to PDF conversion in JAVA | HTML to PDF example in JAVA | Techno Tailor

  3. Pingback: Top 10 spring interview questions and their answers. Spring basic concepts. | Techno Tailor

  4. Pingback: Are Payment banks a competitive threat or addon to the traditional banking. | Techno Tailor

  5. Pingback: Interview question on same name entity twice in Jpa/Hibernate | Techno Tailor

  6. Pingback: Interview questions on concept of code on interface rather then class | Techno Tailor

  7. Pingback: Concept of AOP (Aspect oriented programming) every spring programmer use without knowing about it . | Techno Tailor

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s