Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-618

Multiple resource warning is not appropriate for logback-test.xml

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 0.9.14, 0.9.15, 0.9.16
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      When LBCLASSIC-85 was fixed, it also applied to logback-test.xml. Unfortunately, some IDEs (such as Eclipse) include the test classpath for all modules in a multi-module project – which means that it's nearly impossible to avoid having multiple logback-test.xml files on the classpath if one project depends on another when running tests in Eclipse. Every test in the project will therefore emit this warning when run from the IDE.

      Is it possible to have the ContextInitializer only emit this warning for logback.xml, and not logback-test.xml? This would avoid a spurious/unactionable warning for developers using Eclipse.

        Activity

        Hide
        noreply.ceki@qos.ch Ceki Gulcu added a comment -

        Olivier Chaumont writes:
        > Log4j load the first log4j.xml file find in the classpath,

        Logback also uses the first resource found on the class path. The only difference is that in addition it warns you that there are multiple resources on the class path (but still using the first).

        Regarding the definition of the logback configuration file name, please see [1] and [2].

        As for repository selection [3], logback comes with an equivalent concept. Please see [4].

        [1] http://logback.qos.ch/manual/configuration.html#configFileProperty
        [2] http://logback.qos.ch/manual/configuration.html#joranDirectly
        [3] http://code.google.com/p/log4j-contrib/
        [4] http://logback.qos.ch/manual/loggingSeparation.html

        Show
        noreply.ceki@qos.ch Ceki Gulcu added a comment - Olivier Chaumont writes: > Log4j load the first log4j.xml file find in the classpath, Logback also uses the first resource found on the class path. The only difference is that in addition it warns you that there are multiple resources on the class path (but still using the first). Regarding the definition of the logback configuration file name, please see [1] and [2] . As for repository selection [3] , logback comes with an equivalent concept. Please see [4] . [1] http://logback.qos.ch/manual/configuration.html#configFileProperty [2] http://logback.qos.ch/manual/configuration.html#joranDirectly [3] http://code.google.com/p/log4j-contrib/ [4] http://logback.qos.ch/manual/loggingSeparation.html
        Hide
        o.chaumont olivier chaumont added a comment -

        You're right, I do a mistake, I re-test it and logBack use the first ressource found on the class path.
        So i can use a logback-test.xml instead of logback.xml in the web application and it's work.

        But the specifying the location of the default configuration file as a system property [1] is a good solution for Eclipse.
        Thank you, we will use logback.

        Show
        o.chaumont olivier chaumont added a comment - You're right, I do a mistake, I re-test it and logBack use the first ressource found on the class path. So i can use a logback-test.xml instead of logback.xml in the web application and it's work. But the specifying the location of the default configuration file as a system property [1] is a good solution for Eclipse. Thank you, we will use logback.
        Hide
        holgerh Holger Hoffstätte added a comment -

        I understand the reason for the warning when a resource is found multiple times on the classpath, even though I disagree with it; what I don't understand is why the first resource is not picked by default and used - right now it seems that logback ignores them all. Maybe to "not do the wrong thing"?

        However trying to enforce the config file via system property works only in a trivial number of projects (or run configs) and is error-prone as it pushes additional responsibility of an otherwise correctly set up classpath onto users for no reason.

        Can we maybe turn the warning off for multiple logback-test.xml files? that seems to fit the intended use case best, for both eclipse and maven.

        Show
        holgerh Holger Hoffstätte added a comment - I understand the reason for the warning when a resource is found multiple times on the classpath, even though I disagree with it; what I don't understand is why the first resource is not picked by default and used - right now it seems that logback ignores them all. Maybe to "not do the wrong thing"? However trying to enforce the config file via system property works only in a trivial number of projects (or run configs) and is error-prone as it pushes additional responsibility of an otherwise correctly set up classpath onto users for no reason. Can we maybe turn the warning off for multiple logback-test.xml files? that seems to fit the intended use case best, for both eclipse and maven.
        Hide
        noreply.ceki@qos.ch Ceki Gulcu added a comment -

        Holger,

        But logback does use the first resource found on the list. It just complains that that are multiple resources witht he same name. Add an onConsoleStatusListener [1] to see what logback is doing. In other words just add the following in your config file:

        <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />

        In the absence of further input in the next 10 days, I will close this issue.

        [1] http://logback.qos.ch/manual/configuration.html#statusListener

        Show
        noreply.ceki@qos.ch Ceki Gulcu added a comment - Holger, But logback does use the first resource found on the list. It just complains that that are multiple resources witht he same name. Add an onConsoleStatusListener [1] to see what logback is doing. In other words just add the following in your config file: <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" /> In the absence of further input in the next 10 days, I will close this issue. [1] http://logback.qos.ch/manual/configuration.html#statusListener
        Hide
        holgerh Holger Hoffstätte added a comment -

        Ceki, thanks for looking into this.

        I just tried to verify the behaviour and you are indeed right: the first config file is used correctly after all. Sorry for complaining.

        I guess the additional INFO messages were too confusing - adding the config property "fixed" the problem for me at the time and I didn't look deper into it afterwards.
        This mattered most to me when running Junit tests in eclipse because I hate spurious Console output that doesn't tell me anything new. However with >50 workspace projects that reference each other and just as many run configurations manually adding the system properties is just very tedious.

        Maybe logback could use the first config, and only then log the warning but not as INFO but DEBUG. That way the selection process/"warning" would still be visible if the root level is DEBUG, but not annoy in more common cases where I only want to see logging from my custom packages.
        (I hope that makes sense).

        Show
        holgerh Holger Hoffstätte added a comment - Ceki, thanks for looking into this. I just tried to verify the behaviour and you are indeed right: the first config file is used correctly after all. Sorry for complaining. I guess the additional INFO messages were too confusing - adding the config property "fixed" the problem for me at the time and I didn't look deper into it afterwards. This mattered most to me when running Junit tests in eclipse because I hate spurious Console output that doesn't tell me anything new. However with >50 workspace projects that reference each other and just as many run configurations manually adding the system properties is just very tedious. Maybe logback could use the first config, and only then log the warning but not as INFO but DEBUG. That way the selection process/"warning" would still be visible if the root level is DEBUG, but not annoy in more common cases where I only want to see logging from my custom packages. (I hope that makes sense).

          People

          • Assignee:
            noreply.ceki@qos.ch Ceki Gulcu
            Reporter:
            jonv Jon Vincent
          • Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: