How to integrate SLF4J logging with Spring 4?
<p>Couldn't find any good answer why slf4j logging not working with spring 4. Thanks to <a href="https://springframework.guru/using-log4j-2-spring-boot/" rel="nofollow">this post</a> I've made particularly all work, but the author didn't mention that:</p>

<blockquote>
  <p>The mandatory logging dependency in Spring is the Jakarta Commons Logging API (JCL)</p>
</blockquote>

<p>(<a href="http://docs.spring.io/spring/docs/4.1.x/spring-framework-reference/htmlsingle/" rel="nofollow">http://docs.spring.io/spring/docs/4.1.x/spring-framework-reference/htmlsingle/</a>).</p>

<p>It means that if we want slf4j to work <strong>WE MUST EXCLUDE</strong> <strong>commons-logging</strong> from our classpath (or pom.xml if using maven). While using maven spring-core automatically picks commons-logging. (I understood this when executed the command "mvn dependency:tree").</p>

<p>STEPS TO REPRODUCE:</p>

<ol>
<li><p>Exclude commons-logging from spring-core</p>

<pre><code>&lt;dependency&gt;
    &lt;groupId&gt;org.springframework&lt;/groupId&gt;
    &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
    &lt;version&gt;${spring.version}&lt;/version&gt;
    &lt;exclusions&gt;
        &lt;exclusion&gt;
            &lt;groupId&gt;commons-logging&lt;/groupId&gt;
            &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
        &lt;/exclusion&gt;
    &lt;/exclusions&gt;
&lt;/dependency&gt;
</code></pre></li>
<li><p>Add to the pom.xml next dependencies:</p>

<pre><code>&lt;dependency&gt;
    &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
    &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
    &lt;version&gt;1.7.19&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
    &lt;artifactId&gt;log4j-slf4j-impl&lt;/artifactId&gt;
    &lt;version&gt;2.5&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
    &lt;artifactId&gt;log4j-api&lt;/artifactId&gt;
    &lt;version&gt;2.5&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
    &lt;artifactId&gt;log4j-core&lt;/artifactId&gt;
    &lt;version&gt;2.5&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
    &lt;artifactId&gt;jcl-over-slf4j&lt;/artifactId&gt;
    &lt;version&gt;1.7.19&lt;/version&gt;
&lt;/dependency&gt;
</code></pre></li>
<li><p>Create log4j2.xml file like this (if you want log4j2 logging through slf4j).</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;Configuration status="WARN"&gt;
&lt;Appenders&gt;
&lt;Console name="CONSOLE" target="SYSTEM_OUT"&gt;
    &lt;PatternLayout
        pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" /&gt;
&lt;/Console&gt;
&lt;/Appenders&gt;
&lt;Loggers&gt;
&lt;Root level="error"&gt;
    &lt;AppenderRef ref="CONSOLE" /&gt;
&lt;/Root&gt;
&lt;logger level="info" additivity="false" name="org.springframework.security"&gt;
    &lt;AppenderRef ref="CONSOLE" /&gt;
&lt;/logger&gt;
&lt;logger level="info" additivity="false" name="org.springframework.web"&gt;
    &lt;AppenderRef ref="CONSOLE" /&gt;
&lt;/logger&gt;
&lt;logger level="warn" additivity="false" name="controllers"&gt;
    &lt;AppenderRef ref="CONSOLE" /&gt;
&lt;/logger&gt;
&lt;/Loggers&gt;
&lt;/Configuration&gt;
</code></pre></li>
<li><p>write log messages in your classes:</p>

<pre><code>private final Logger logger =LoggerFactory.getLogger(this.getClass());
logger.debug("This is a debug message");
logger.info("This is an info message");
</code></pre></li>
</ol>