title: play framework logback custom layout
body: <p>I am trying to use a custom layout class for play framework 2.0 logback logging.</p>
  
  <p>First, I defined a custom layout class in package utils:</p>
  
  <pre><code>package utils;
  
  public class MonitorLayoutForLogback extends LayoutBase&lt;ILoggingEvent&gt; {
  ...
  }
  </code></pre>
  
  <p>In my conf/logging.xml file, I put:</p>
  
  <pre><code>&lt;appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"&gt;
          &lt;encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"&gt;
              &lt;layout class="utils.MonitorLayoutForLogback"&gt;
                               &lt;param name="programName" value="uowVisualizer" /&gt;
                               &lt;param name="serviceGroup" value="shared" /&gt;
                               &lt;param name="serviceIdentifier" value="uowVisualizer" /&gt;
              &lt;/layout&gt;
          &lt;/encoder&gt;
      &lt;/appender&gt;
  </code></pre>
  
  <p>but when I run within play, e.g.,</p>
  
  <pre><code>play run
  </code></pre>
  
  <p>I see:</p>
  
  <pre><code>14:20:18,387 |-ERROR in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Could not create component [layout] of type [utils.MonitorLayoutForLogback] java.lang.ClassNotFoundException: utils.M
  onitorLayoutForLogback
      at java.lang.ClassNotFoundException: utils.MonitorLayoutForLogback
      at      at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
      at      at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
      at      at java.security.AccessController.doPrivileged(Native Method)
      at      at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
      at      at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
      at      at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
      at      at sbt.PlayCommands$$anonfun$53$$anonfun$55$$anon$2.loadClass(PlayCommands.scala:535)
      at      at ch.qos.logback.core.util.Loader.loadClass(Loader.java:124)
      at      at ch.qos.logback.core.joran.action.NestedComplexPropertyIA.begin(NestedComplexPropertyIA.java:100)
      at      at ch.qos.logback.core.joran.spi.Interpreter.callBeginAction(Interpreter.java:276)
      at      at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:148)
      at      at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:130)
      at      at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:50)
      at      at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:157)
      at      at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:143)
      at      at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:106)
      at      at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:56)
      at      at play.api.Logger$$anonfun$configure$8.apply(Logger.scala:248)
      at      at play.api.Logger$$anonfun$configure$8.apply(Logger.scala:247)
      at      at scala.Option.map(Option.scala:145)
      at      at play.api.Logger$.configure(Logger.scala:247)
      at      at play.api.Application$class.$init$(Application.scala:266)
  </code></pre>
  
  <p>So, play can't find the layout class I created. How do I put the layout class on the class path?</p>
  
  <p>Note that I also tried staging the project via,</p>
  
  <pre><code>play clean compile stage
  </code></pre>
  
  <p>and then started the project via</p>
  
  <pre><code>target/start
  </code></pre>
  
  <p>Starting the project from the packaged version, I don't see the above missing class error. However, I also never see any output, nor do I even see the class constructed. I added System.out.println statements to each constructor for this class as follows, to verify whether or not the class was being constructed:</p>
  
  <pre><code>    public MonitorLayoutForLogback() {
          System.out.println("MonitorLayoutForLogback Constructor without arguments");
      }
  
      public MonitorLayoutForLogback(String program) {
          System.out.println("MonitorLayoutForLogback Constructor with program "+program);
          _program = program;
      }
  
      public MonitorLayoutForLogback(String program, String sGroup, String sid) {
          System.out.println("MonitorLayoutForLogback Constructor with program "+program+" sGroup "+sGroup+" sid "+sid);
          _program = program;
          MonitoringInfo.setServiceGroup(sGroup);
          MonitoringInfo.setServiceIdentifier(sid);
      }
  </code></pre>
  
  <p>I'm a newbie to logback configuration, so I'm sure I'm missing something obvious. Thanks for the help.</p>