Note that there are some explanatory texts on larger screens.

plurals
  1. POLogback with Spring MVC doesn't work
    primarykey
    data
    text
    <p>I developed a webapp with Spring MVC and build it with maven. I want to improve logging using logback sl4j logging framework, but I'm completely new to it. I modifide my pom.xml this way:</p> <pre><code>&lt;!-- Spring 3 dependencies --&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-context&lt;/artifactId&gt; &lt;version&gt;${spring.version}&lt;/version&gt; &lt;exclusions&gt; &lt;!--Exclude Commons Logging in favor of SLF4j--&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; &lt;!-- Logging --&gt; &lt;dependency&gt; &lt;groupId&gt;org.slf4j&lt;/groupId&gt; &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt; &lt;version&gt;1.6.1&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;ch.qos.logback&lt;/groupId&gt; &lt;artifactId&gt;logback-classic&lt;/artifactId&gt; &lt;version&gt;${logback.version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;ch.qos.logback&lt;/groupId&gt; &lt;artifactId&gt;logback-core&lt;/artifactId&gt; &lt;version&gt;${logback.version}&lt;/version&gt; &lt;/dependency&gt; </code></pre> <p>and then added the following lines to my custom exception DatabaseException:</p> <pre><code> private final static Logger logger = (Logger) LoggerFactory.getLogger(DatabaseException.class); </code></pre> <p>...</p> <pre><code>public DatabaseException(Throwable cause) { super(cause); logger.log(Level.WARNING, cause.getMessage()); } </code></pre> <p>then I added under classpath logback.xml configuration file.</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;configuration&gt; &lt;appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"&gt; &lt;!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder by default --&gt; &lt;encoder&gt; &lt;pattern&gt;%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n&lt;/pattern&gt; &lt;/encoder&gt; &lt;/appender&gt; &lt;logger name='org.springframework'&gt; &lt;level value='INFO' /&gt; &lt;/logger&gt; &lt;root level="debug"&gt; &lt;appender-ref ref="STDOUT" /&gt; &lt;/root&gt; &lt;/configuration&gt; </code></pre> <p>So when I rise this exception I would logback to print to stdout some message BUT nothing. When I deploy and run the app with tomcat it prints only container logs [talledContainer]-INFO ... etc etc and there is no trace of my logger and I don't figure out why, can you help me?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload