Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play framework 2.5 logs `?` question marks instead of line numbers

I have a play framework app with all standard configurations. I modify logback.xml like this:

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
        <pattern>%coloredLevel %logger{15} %L - %message%n%xException{10} </pattern>
    </encoder>
</appender>

I tried instead of %L put there %line, %class, etc. - all to the same result, it outputs ? in the log message, like this:

[info] application ? - Checking cart...

I also tried to follow the accepted answer to this question: Scala Play framework: logger pattern for displaying file and line
and put val logger = Logger(this.getClass) inside my class. Still same result. Is there any way to fix it? Logback version specified in build.sbt is 2.11.

like image 328
Vasily802 Avatar asked Jan 14 '17 01:01

Vasily802


2 Answers

I add includeCallerData and work

   <appender  name="ASYNCSTDOUT" class="ch.qos.logback.classic.AsyncAppender">
        <appender-ref ref="STDOUT"/>
        <includeCallerData>true</includeCallerData>
    </appender>
like image 168
Sajad Bahmani Avatar answered Oct 18 '22 03:10

Sajad Bahmani


Using %L as in your question works perfectly for me in both Play 2.4 and Play 2.5 (exact versions: 2.4.6 and 2.5.12).

I note however that I do not explicitly state any desired version of logback in either application's build.sbt.

This results in (for the Play 2.5 app):

+-com.typesafe.play:play-logback_2.11:2.5.12 [S]
| +-ch.qos.logback:logback-classic:1.1.7
| | +-ch.qos.logback:logback-core:1.1.7
| | +-org.slf4j:slf4j-api:1.7.20 (evicted by: 1.7.21)
| | +-org.slf4j:slf4j-api:1.7.21

(dependency tree via the sbt-dependency-graph plugin)

If you're seeing a different logback version, try removing any explicit dependency declaration, so that you see the same library versions in your dependency tree.

Hope it helps.

like image 1
millhouse Avatar answered Oct 18 '22 02:10

millhouse