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

Cannot enable packaging data using LoggerContext

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • 1.1.7
    • logback-classic

    Description

      The following code with no logback configuration on the classpath:

      import ch.qos.logback.classic.LoggerContext;
      import org.slf4j.LoggerFactory;
      
      import java.net.MalformedURLException;
      import java.net.URL;
      
      public class Main {
          public static void main(String[] args) {
              LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
              lc.setPackagingDataEnabled(true);
              try {
                  new URL("foo");
              } catch (MalformedURLException e) {
                  LoggerFactory.getLogger("com.example.Main").warn("An exception!", e);
              }
          }
      }
      

      does not print packaging data in the stacktrace (note that this is the way described in the documentation for packagingData).

      To get the packaging data you need to create a logback.xml with packagingData="true" (as in the documentation). With this file on the classpath, calling lc.setPackagingDataEnabled(false); has effect and disables packaging data. Setting false in XML and true in code does not show packaging data.

      Attachments

        Activity

          People

            logback-dev Logback dev list
            pkubowicz Piotr Kubowicz
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: