Logback: control stack formatting of exception stacks

I am using Logback 1.0.13 in a Scala / Play 2.2.0 application. The existing config is as follows:

<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 am looking for if there is a way to configure it, since the exception trace lines have a custom separator. Instead

 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 would like to put some characters before 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] 
+6
source share
1 answer

I realized that this works:

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

The% replacement mechanism works with stacktrace text. You also need% nopex to prevent the appearance of rawtatrace again; otherwise Logback "helpfully" notices that you have omitted the trace and enabled it for yourself.

+9
source

All Articles