title: Spring boot logging when logback and log4j2 both in classpath
body: <p>In my spring boot project , I have configured the logging via log4j2 using following dependency</p>
  <pre><code>&lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
           &lt;exclusions&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-starter-logging&lt;/artifactId&gt;
              &lt;/exclusion&gt;
           &lt;/exclusions&gt;
      &lt;/dependency&gt;
  </code></pre>
  <p>I have added log4j2 and slf4j jar explicitly. I am also using jxls which uses logback. So its included as a transient dependency.</p>
  <p>On startup spring tries to configure logging using LoggingSystem</p>
  <pre><code>public static LoggingSystem get(ClassLoader classLoader) {
          String loggingSystem = System.getProperty(SYSTEM_PROPERTY);
          if (StringUtils.hasLength(loggingSystem)) {
              if (NONE.equals(loggingSystem)) {
                  return new NoOpLoggingSystem();
              }
              return get(classLoader, loggingSystem);
          }
          return SYSTEMS.entrySet().stream().filter((entry) -&gt; ClassUtils.isPresent(entry.getKey(), classLoader))
                  .map((entry) -&gt; get(classLoader, entry.getValue())).findFirst()
                  .orElseThrow(() -&gt; new IllegalStateException(&quot;No suitable logging system located&quot;));
      }
  </code></pre>
  <p>Now since I have not explicitly set LoggingSystem it default picks logback from the SYSTEMS map.</p>
  <pre><code>static {
          Map&lt;String, String&gt; systems = new LinkedHashMap&lt;&gt;();
          systems.put(&quot;ch.qos.logback.core.Appender&quot;, &quot;org.springframework.boot.logging.logback.LogbackLoggingSystem&quot;);
          systems.put(&quot;org.apache.logging.log4j.core.impl.Log4jContextFactory&quot;,
                  &quot;org.springframework.boot.logging.log4j2.Log4J2LoggingSystem&quot;);
          systems.put(&quot;java.util.logging.LogManager&quot;, &quot;org.springframework.boot.logging.java.JavaLoggingSystem&quot;);
          SYSTEMS = Collections.unmodifiableMap(systems);
      }
  </code></pre>
  <p>The only way I found to make it choose log4j is to pass VM param like this
  <code>-Dorg.springframework.boot.logging.LoggingSystem=org.springframework.boot.logging.log4j2.Log4J2LoggingSystem”</code></p>
  <p>Even if I add this in application properties its not picked since logging is configured even before app context is loaded.</p>
  <p>So my questions is if I am using logback ( direct or transitively ) i have to pass this VM flag to ensure spring boot choose log4j2.</p>