Search code examples
javaspringspring-bootlogginglogback

Spring boot - How to get framework logging for WARN and application logging to DEBUG


I am using Spring Boot with Logback for logging. Currently, we have root logger set to DEBUG and then we have app package logger like com.abc.xyz set to DEBUG.

Now, what's happening is all frameworks - Hibernate, Spring etc. are printing their DEBUG logs. What we want that all framework should print only WARN and below logs, so below are 2 options which I am thinking:

Option 1: Set the ROOT logger to WARN. However I am not sure what are its implications and even not sure whether it will help in achieving what I am looking for or not.

Option 2: Create specific loggers like org.springframework and org.hibernate and set them to WARN.

My questions:

  • Which of the above approach is best way to have all framework logging to WARN level?
  • If I set the ROOT logger to WARN then will it help? And what will be its other implications?
  • Is it fine to set ROOT logger to WARN? Can it potentially cause to loose some application logging?

Solution

  • In Spring Boot, ERROR, WARN and INFO levels are always printed as default for both the root logger and all dependencies.

    If you wish to print additional logs, you need to specify that in your application.properties:

    logging.level.org.hibernate=DEBUG
    logging.level.com.abc.xyz=DEBUG
    

    If you set your ROOT logger to WARN, you will only see warning and error messages (unless you override this setting for different package).

    I would suggest leaving the default settings for all Spring-related dependencies since this will allow you to see all info, warning and error messages. If you really need to see just warning and error messages, set the root logger to WARN.

    Then, you can specify any other classes to log to DEBUG in your properties.