Play Framework: registration time
I'm using the Play Framework, but like many other things, I haven't come across defining logging patterns that add a timestamp to the log. For services that handle many Akka requests / messages per minute, this makes the log almost useless. For example, we use Playlogger a little like this:
Logger.error("could not fulfil request", someException)
This is how the documentation goes. The documentation states that you can define your own logging headers, for example:
val exceptionLogger = Logger("exception")
// and then
exceptionLogger.error("while handling some/request", someException)
The log entries resulting from the above do not contain any type of time stamp;
[error] exception - while handling some/request ...
There is no mention of time. Now the workaround (not the prettiest one) is something like:
def exceptionLogger = {
val dt = new DateTime
Logger(s"$dt exception")
}
What kind of work does it do, but I'm not sure. Is there a better way to format the default write behavior for the default?
source to share
Play uses Logback, you can customize the log format in conf/logback.xml
.
Logs in log/application.log
will have a default date stamp, STDOUT will not. Add %date
to the template in the STDOUT application.
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date %coloredLevel %logger{15} - %message%n%xException{10}</pattern>
</encoder>
</appender>
source to share