2

I'm on Scala 2.12.x Play 2.7.x and as part of my Application Controllers I'm using the logger like this (or equivalently by doing with play.api.Logging):

val logger = play.api.Logger(this.getClass)

and the configuration conf/logback.xml is shown below. The issue is that Application-Controllers' logger.debug(...) statements are not being output in the logs. I assumed that the application was set to DEBUG see one of the lasts entries <logger name="application" level="DEBUG" /> but there is obviously something wrong as the DEBUG statements are not being output?

<!-- https://www.playframework.com/documentation/latest/SettingsLogger -->
<configuration>

    <conversionRule conversionWord="coloredLevel" converterClass="play.api.libs.logback.ColoredLevel" />

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

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

    <appender name="ASYNCFILE" class="ch.qos.logback.classic.AsyncAppender">
        <appender-ref ref="FILE" />
    </appender>

    <appender name="ASYNCSTDOUT" class="ch.qos.logback.classic.AsyncAppender">
        <appender-ref ref="STDOUT" />
    </appender>

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

    <root level="WARN">
        <appender-ref ref="ASYNCFILE" />
        <appender-ref ref="ASYNCSTDOUT" />
    </root>

</configuration>

PS: I know I can enable DEBUG for everything but then it is too much information I don't need, I'd like to see what's happening with my Controllers' logging.

SkyWalker
  • 13,729
  • 18
  • 91
  • 187

1 Answers1

1

The logger instantiated with play.api.Logger(this.getClass) inside a class like so

package controller

class HomeController extends ... {
  val logger = play.api.Logger(this.getClass)
  logger.debug("msg")  
}

is not the application logger, but a distinct logger named

controller.HomeController

Thus to specify its log level add the following config to logback.xml

<logger name="controllers" level="DEBUG" />

This makes DEBUG the log level of all classes under controllers package.

Note application logger seems to be deprecated according to docs:

There is also a play.api.Logger singleton object that allows you to access a logger named application, but its use is deprecated in Play 2.7.0 and above. You should declare your own logger instances...

If the messages are still not logging try changing from async appender to synchronous ones like so:

<root level="WARN">
  <appender-ref ref="FILE" />
  <appender-ref ref="STDOUT" />
</root>
Mario Galic
  • 47,285
  • 6
  • 56
  • 98
  • Hi Mario, thank you yes I knew that, the OP was more about how to enable the Application to DEBUG without getting logging from everywhere else. I will update the Question to reflect this more clearly. – SkyWalker Jun 11 '19 at 07:01
  • Wow great! will test it :) what's this entry `` for then? I assumed everything under `app` .. I tried that too and didn't work `` – SkyWalker Jun 11 '19 at 08:30
  • 1
    `application` logger is deprecated but not yet removed, so we can still get access to it like so: `val logger = Logger("application")` – Mario Galic Jun 11 '19 at 08:31
  • Ahhhhhh missed that migration entry :D – SkyWalker Jun 11 '19 at 08:32