Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams
  • logback.xml : present under *src/main/resources/
  • logback-test.xml : present under *src/test/resources/
  • Which one will load? logback.xml or logback-test.xml ?

    I was reading the documentation of logback and it says, first it looks for logback-test.xml and then logback.xml .

    So is it like logback-test.xml file will take a priority over logback.xml if we deploy the application?

    Thanks!

    Saurabh

    From the docs :

    Let us begin by discussing the initialization steps that logback follows to try to configure itself:

  • Logback tries to find a file called logback-test.xml in the classpath.

  • If no such file is found, logback tries to find a file called logback.groovy in the classpath.

  • If no such file is found, it checks for the file logback.xml in the classpath..

  • If no such file is found, service-provider loading facility (introduced in JDK 1.6) is used to resolve the implementation of com.qos.logback.classic.spi.Configurator interface by looking up the file META-INF\services\ch.qos.logback.classic.spi.Configurator in the class path. Its contents should specify the fully qualified class name of the desired Configurator implementation.

  • If none of the above succeeds, logback configures itself automatically using the BasicConfigurator which will cause logging output to be directed to the console.

    The last step is meant as last-ditch effort to provide a default (but very basic) logging functionality in the absence of a configuration file.

    So, the answer to this question ...

    Which takes priority: logback.xml or logback-test.xml?

    ... is logback-test.xml .

    However, this question ...

    So is it like logback-test.xml file will take a priority over logback.xml if we deploy the application?

    ... slightly complicates matters. If you deploy both logback-test.xml and logback.xml then logback-test.xml wil take priority but it is not common to deploy logback-test.xml . Indeed, given the locations supplied in your question logback-test.xml will not, by default, be deployed since it is in the test tree ( src/test/resources ).

    Again, from the docs :

    If you are using Maven and if you place the logback-test.xml under the src/test/resources folder, Maven will ensure that it won't be included in the artifact produced. Thus, you can use a different configuration file, namely logback-test.xml during testing, and another file, namely, logback.xml, in production.

    So, in summary; by default logback-test.xml will not be deployed so logback.xml will be used in your deployed system but logback-test.xml will take priority over logback.xml when running your test cases.

    @glytching: My logback-text.xml is not able to pick up the application.yml entries from src/test/resources. Any idea why? The entries are as below. These entries are being fetched from application.yml in test/resources. But getting UNDEFINED. Am I reading the right classpath <property resource="application-default.yml" /> <springProperty scope="context" name="max_log_file_size" source="max_log_size" /> <springProperty scope="context" name="base_log_path" source="base_log" /> raikumardipak Sep 3, 2020 at 13:03

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question . Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers .

  •