Reputation: 2996
I've been using the Play Framework but like many things, I haven't come across in defining logging templates that add a timestamp to the log. For services that handle many requests/Akka messages per minute, this renders the logging almost useless. For example, we use the Play logger a bit like this;
Logger.error("could not fulfil request", someException)
Which is how the documentation goes. The documentation does specify, that it is possible to define your own logging headers like;
val exceptionLogger = Logger("exception")
// and then
exceptionLogger.error("while handling some/request", someException)
The log entries resulting from the above don't contain a timestamp of any sort;
[error] exception - while handling some/request ...
There's no mention of the time whatsoever. Now, a workaround (not the prettiest) is something like;
def exceptionLogger = {
val dt = new DateTime
Logger(s"$dt exception")
}
Which does the job, but I'm not convinced. Is there a better way to format Play's default logging behaviour?
Upvotes: 3
Views: 1183
Reputation: 7257
Play uses Logback, you can configure the log format in conf/logback.xml
.
The logs in log/application.log
will have a date stamp by default by STDOUT will not. Add %date
to the pattern in the STDOUT appender.
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date %coloredLevel %logger{15} - %message%n%xException{10}</pattern>
</encoder>
</appender>
Upvotes: 7