[Scala 2.5] Custom logback layout

266 views
Skip to first unread message

Hubert Świetlicki

unread,
Apr 15, 2016, 9:17:47 AM4/15/16
to play-framework
Hello!


How can I use custom layout class for Logback? I created a new layout class:

package core.models.logger

import ch.qos.logback.classic.html.HTMLLayout

class AccessLoggingLayout extends HTMLLayout {}

and defined an appender in logback,xml:

<appender name="ACCESSFILE" class="ch.qos.logback.core.FileAppender">
 
<file>${application.home:-.}/logs/access.html</file>
 
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
   
<layout class="core.models.logger.AccessLoggingLayout">
     
<pattern>%date{ISO8601}%level%message</pattern>
   
</layout>
 
</encoder>
</appender>

When I try to run my application, the AccessLoggingLayout class is not found by the class loader. Can you help me with this issue?

Hubert

Will Sargent

unread,
Apr 15, 2016, 3:15:42 PM4/15/16
to play-fr...@googlegroups.com
You need to declare AccessLoggingLayout in the classpath, well before the rest of the application gets loaded.  I think you may want to define it in a different project and then have as libraryDependencies inside build.sbt.

See the LoggerConfigurator and PlayLogback module in Play for more details.

Will.

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/b04fcbd4-e67d-4652-9ce0-e5ff3107e121%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hubert Świetlicki

unread,
Apr 19, 2016, 4:29:50 AM4/19/16
to play-framework
I did what you proposed, Will. New project (https://github.com/huberts/play-logback-layout), and additional dependency in my build.sbt file:

libraryDepenedencies += "com.github.huberts" % "play-logback-layout" % "1.1" from "https://github.com/huberts/play-logback-layout/releases/download/1.1/play-logback-layout_2.11-1.1.jar"

It is a working solution, thanks for your help! Although, I still think it should be possible to define my custom layout inside my application code.

BTW: As you can see, I used the GitHub Releasing Tool for resolving my dependency. Can anyone help me with making a SBT resolver for this? This fixed syntax is a little bit rigid for me.

Will Sargent

unread,
Apr 19, 2016, 12:46:09 PM4/19/16
to play-fr...@googlegroups.com
If you use "sbt publishLocal" then it should push only to your local .ivy2 directory.

Reply all
Reply to author
Forward
0 new messages