Search code examples
javaspring-bootlogback

springboot ignore logback.xml in classpath


im trying to simplify a multi module maven project and want to define logback configuration in application.properties instead of using logback.xml . i remove logback.xml from the resources but its still find one . its happens because some dependencies have also their own logback.xml inside the jar. i guess adding logback.xml to the jar of the dependencies is bad idea in first place, but since this is the situation, im trying to ignore all logback.xml without changing the dependencies. is there any way to do it ?


Solution

  • Indeed, Spring boot provides a default logback configuration.
    So even without declaring your logback.xml in the classpath you will have a default logback configuration.
    But it doesn't mean that you cannot override this configuration of course :

    Spring Boot picks up the native configuration from its default location for the system (such as classpath:logback.xml for Logback), but you can set the location of the config file by using the "logging.config" property.

    Note that logback.xml is not mandatory in logback. But if you don't provide it a default configuration will be used by logback (console output).
    Spring has to cope with that constraint and so favors a minimal configuration like logback does itself.

    So in your case, if you want to define logback configuration in application.properties, add in it some predefined properties and refer the minimum of information in logback.xml.