Currently to add standard prefix to log in our Play application, I override LoggerLike trait with additional functions
trait MyLogger extends LoggerLike {
...
def error(message: => String, error: => Throwable)(implicit myObject: MyObject) {
if (super.isErrorEnabled) logWithPrefix(encounterAware, super.error, message, error)
}
private def logWithPrefix(myObject: MyObject, log: (=> String) => Unit, message: => String) = {
log(s"A:${myObject.A} ${message}")
}
...
}
And use it like this:
new Logger(LoggerFactory.getLogger(this.getClass.getSimpleName)) with MyLogger
I expect this to affect only log entries which have implicit myObject in context, and leave all old references valid, but all my logs start referencing new method.
I don't want to change the name of the method or provide default value for implicit.
How do I need to declare error method, to get desired behavior?