简体   繁体   中英

How can I log in Play Framework using Scala?

I have updated Play Framework up to 2.7 and I got following warning:

method info in object Logger is deprecated (since 2.7.0): Create an instance of via Logger(...) and use the same-named method. Or use SLF4J directly.

So my questions are:

  • Should I create an instance of Logger and pass it to each component when I want to use it?

PS:

In project not based on Play Framework, I used to use scala-logging that is a wrapper for SLF4J. Can this be a solution?

Play 2.7 provides a trait for Scala similar to scala-logging. It creates a val which you can use it in you class/object:

import play.api.Logging

class MyClass extends Logging {
  // `logger` is automaticaly defined by the `Logging` trait:
  logger.info("hello!")
}

So there is another way to log in Play now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM