title: Make Logback write to the console locally, but to log file on server
body: <p>In a web application built with Maven 3, is there a way to have Logback use either a <code>ConsoleAppender</code> or a <code>RollingFileAppender</code> depending where/how the application is running?</p>
  
  <p>In production the .war file is deployed on Tomcat 7. Locally I'm running the Jetty Maven plugin for testing purposes during development.</p>
  
  <p>I would like to have the logging work like this:</p>
  
  <ul>
  <li>When I run <code>mvn jetty:run</code> locally: Use <code>ConsoleAppender</code></li>
  <li>When <code>*.war</code> file is deployed on production (Tomcat 7): Use <code>RollingFileAppender</code></li>
  </ul>
  
  <p>During local development it just seems very comfortable to have all log output on the console. In production I would instead prefer to log to a file: <code>CATALINA_BASE/logs/myApp.log</code>.</p>
  
  <p>Obviously you could just use both a <code>ConsoleAppender</code> and a <code>RollingFileAppender</code> in <code>logback.xml</code>. But to me it seems unnecessarily redundant to have all log output on production written to <code>STDOUT</code> AND into a log file. Also, from the Tomcat documentation it sounds like logging to STDOUT on production is a bad practice in general.</p>
  
  <p>I couldn't find any nice solutions on the web. Is there a good solution for this?</p>
  
  <p>Here's my current <code>logback.xml</code> which always logs to <code>STDOUT</code> and to the desired log file:</p>
  
  <pre class="lang-xml prettyprint-override"><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;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;appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"&gt;
          &lt;file&gt;${catalina.base}/logs/myApp.log&lt;/file&gt;
          &lt;rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"&gt;
              &lt;fileNamePattern&gt;${catalina.base}/logs/myApp.%d{yyyy-MM-dd}.log&lt;/fileNamePattern&gt;
              &lt;maxHistory&gt;30&lt;/maxHistory&gt;
          &lt;/rollingPolicy&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="com.myDomain.myApp" level="DEBUG" /&gt;
  
      &lt;root level="DEBUG"&gt;
          &lt;appender-ref ref="STDOUT" /&gt;
          &lt;appender-ref ref="FILE" /&gt;
      &lt;/root&gt;
  &lt;/configuration&gt;
  </code></pre>