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]
Logback is one of the most widely used logging frameworks in the Java Community. It's a replacement for its predecessor, Log4j. Logback offers a faster implementation, provides more options for configuration, and more flexibility in archiving old log files.
GitHub - qos-ch/logback: The reliable, generic, fast and flexible logging framework for Java.
In a Spring Boot application, you can put the Logback. xml file in the resources folder. If your Logback. xml file is outside the classpath, you need to point to its location using the Logback.
so just write %t on your configuration file in logback. xml reference document : Link and find Outputs the ID of the thread that generated the logging event. [%t] prints thread name not thread id with logback.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With