title: Logback config in tomcat
body: <p>I'm running two web applications in a Tomcat 7. </p>
  
  <p>The Tomcat has a <code>logback-access.xml</code>, which defines two appenders. </p>
  
  <p>I can see that it's being picked up when starting tomcat, and the appender config is parsed correctly.</p>
  
  <p>My question is, how do I let the webapp use the appenders defined in there?</p>
  
  <p>I tried putting <code>&lt;logger&gt;</code> and <code>&lt;root&gt;</code> elements in the <code>logback-access</code> file, but that generates an error: </p>
  
  <blockquote>
    <p>no applicable action for [logger], current ElementPath  is [[configuration][logger]]</p>
  </blockquote>
  
  <p>, and similar for <code>root</code> and <code>appender-ref</code>.</p>
  
  <p>I tried putting a <code>logback.xml</code> file in my war files, both <code>WEB-INF/classes</code> and just <code>WEB-INF</code>, but it doesn't seem to be picked up.</p>
  
  <p>So, how am I supposed to properly configure this?</p>
  
  <p>The <code>logback-access.xml</code> in Tomcat:</p>
  
  
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;configuration&gt;
      &lt;appender name="FILE" class="ch.qos.logback.core.FileAppender"&gt;
          &lt;append&gt;true&lt;/append&gt;
          &lt;file&gt;${catalina.base}/logs/my=app.log&lt;/file&gt;
          &lt;encoder&gt;
              &lt;pattern&gt;combined&lt;/pattern&gt;
          &lt;/encoder&gt;
      &lt;/appender&gt;
  
      &lt;appender name="STASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender"&gt;
          &lt;destination&gt;localhost:5044&lt;/destination&gt;
  
          &lt;encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder"&gt;
              &lt;providers&gt;
  &lt;!-- cut specific config --&gt;
              &lt;/providers&gt;
          &lt;/encoder&gt;
      &lt;/appender&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>The <code>logback.xml</code> in <code>WEB-INF/classes</code>:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;configuration&gt;
      &lt;logger name="my.package" level="DEBUG"/&gt;
      &lt;logger name="com.amazonaws" level="INFO"/&gt;
  &lt;!-- and several more loggers like this --&gt;
  
      &lt;root level="DEBUG"&gt;
          &lt;appender-ref ref="FILE"/&gt;
      &lt;/root&gt;
      &lt;root level="TRACE"&gt;
          &lt;appender-ref ref="STASH"/&gt;
      &lt;/root&gt;
  &lt;/configuration&gt;
  </code></pre>