Is there a way to do the following without having to manually define the logging methods e.g. def error
:
object FooBar {
lazy val log = LoggerFactory.getLogger("AndroidProxy")
def error(msg: String) = log.error(msg)
def my_method(): Unit = {
error("This is an error!")
}
}
replace
def error
withIf you want to log in many classes and not rewrite the logging method every time, you can create a trait
Then in the classes where you need logging you do...
It is usually a good idea to pass the msg parameter by name (using :=> String) so that the string argument is evaluated only if used.
Also, notice that getClass is now the name of the logger. Which is helpful because now the name of the logger is the name of the class extending the Logging trait and not a hardcoded name.