0
votes

I have the following configuration in logback.xml:

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

And log with the following statement

Logger.info("This is a message")

However the log prints ? instead of the class name:

[info] application - ? - This is a message

What is wrong?

1
What does it print if you replace %class{36} with %class{0} ?meucaa
You can also use %C or %class if you do not want to reduce the number of characters of your class name.meucaa
I tried %C, %class and %class{0} and have same problemps0604
Fetching the caller class can be slow according to the documentation, at the time this line is printed, the class name is not resolved yet.meucaa

1 Answers

1
votes

Because when using the Logger api like this, you get a default logger, which does not know the class.

You need to use Logger like this:

val log = Logger(this.getClass)
log.info("This is a message")

See for more information the Play documentation on logging.