Jose D. Jurado
Jose D. Jurado

Reputation: 274

Play Logback only show class 'play.Logger$ALogger'

I use the next Logback pattern into Play! Framework application:

%d -[%level][%lo{0}][%class][%F:%L][%method]: %msg%n%ex{full}

but always show as %class:

[play.Logger$ALogger] or [play.api.LoggerLike$class]

instead of the real class that use the logger.

The full logger.xml file content is the next:

<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${application.home}/logs/application.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <!-- daily rollover -->
        <fileNamePattern>${application.home}/logs/application.%d{yyyy-MM-dd}.log</fileNamePattern>

        <!-- keep 30 days' worth of history -->
        <maxHistory>30</maxHistory>
    </rollingPolicy>
    <encoder>
        <pattern>%d -[%level][%lo{0}][%class][%F:%L][%method]: %msg%n%ex{full}</pattern>
        <!--  <pattern> %d{HH:mm:ss.SSS} [%thread] %-5level %class{0} - %msg%n</pattern> -->
        <outputPatternAsHeader>true</outputPatternAsHeader>
    </encoder>
</appender>

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


<logger name="play" level="INFO" />
<logger name="application" level="DEBUG" />

<root level="ERROR">
    <appender-ref ref="STDOUT" />
    <appender-ref ref="FILE" />
</root>

and several output examples are:

2014-01-30 14:57:57,671 -[DEBUG][application][play.Logger$ALogger][Logger.java:332][debug]: DBClient:: isAlive: true

2014-01-30 14:57:57,695 -[INFO][application][play.Logger$ALogger][Logger.java:361][info]: Applicaton started.

2014-01-30 14:57:57,699 -[INFO][play][play.api.LoggerLike$class][Logger.scala:90][info]: Application started (Dev)

Thanks!

Upvotes: 2

Views: 798

Answers (3)

sebastianr
sebastianr

Reputation: 667

Not sure if you found the answer to your question but I found the following that does the trick:

Play.Logger.underlying().debug("Your debug message"); 

Of course you still have to make sure to provide a custom conf/logger.xml file (as you did) to replace Play's default one (see Play docs on Logging) and include in the pattern element, the %class conversion specifier in the appender (Logback Docs).

Some things to consider before you move forward:

  • I don't know if this could negatively impact any aspect of your app such as portability, etc.
  • Also note that you would have to replace your calls to Play.Logger with Play.Logger.underlying() or create a wrapper class around Play.Logger. Depending on the size of your project this can be unacceptable.

Hope this helps

Source

Upvotes: 2

0fnt
0fnt

Reputation: 8671

Please see: https://github.com/playframework/playframework/issues/1669

Briefly: The way logback does the classname, filename and linename computation is by 'throwing an exception' and finding a particular frame in the stacktrace. But by using play's API and not direct logback API, the frame thusly indexed belongs to play code.

Upvotes: 1

johanandren
johanandren

Reputation: 11479

The inner class Logger.ALogger is the play code that actually calls the logback logger so that is expected.

Not sure if it is possible to override so that it logback would have access to the class that calls the class that uses the logger. I guess the option if you really want output the calling class is to use logback directly in your code.

Upvotes: 1

Related Questions