Question

I'm using Logback 1.0.13 on a Scala/Play 2.2.0 app. Existing config looks like:

  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <file>${application.home}/logs/application.log</file>
    <encoder>
     <pattern>%date [%level][%logger{1}][%thread{1}] %message%xException%n</pattern>
    </encoder>
  </appender>

I'm looking if there's a way to configure it so exception traceback lines have a customized separator. Instead of

play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [default]]
at play.api.Configuration$.play$api$Configuration$$configError(Configuration.scala:92) ~[play_2.10-2.2.0.jar:2.2.0]
at play.api.Configuration.reportError(Configuration.scala:570) ~[play_2.10-2.2.0.jar:2.2.0]
at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:252) ~[play-jdbc_2.10-2.2.0.jar:2.2.0]

I'd like to put some chars in front of each line like this:

play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [default]]
>>> at play.api.Configuration$.play$api$Configuration$$configError(Configuration.scala:92) ~[play_2.10-2.2.0.jar:2.2.0]
>>> at play.api.Configuration.reportError(Configuration.scala:570) ~[play_2.10-2.2.0.jar:2.2.0]
>>> at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:252) ~[play-jdbc_2.10-2.2.0.jar:2.2.0]
Was it helpful?

Solution

I figured out something like this works:

       <pattern>%date [%level][%logger{1}][%thread{1}] 
         %message%replace(%xException){"\n", "\\n"}%nopex%n</pattern>  

The %replace mechanism works on a stacktrace text. You also need %nopex to prevent the raw stacktrace from showing up again; otherwise Logback "helpfully" notices you omitted the trace and includes it for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top