How do I configure Logback to print out the class name

后端 未结 6 1073
渐次进展
渐次进展 2020-12-10 11:08

I\'m using Play 2.1. I\'m using the default logger play.api.Logger. I\'m confused about how it works.

In my scala code, a line in class \"com.myapp.tickets\" in th

6条回答
  •  盖世英雄少女心
    2020-12-10 12:06

    Since Play's Logger wraps the underlying SLF4J calls, the logger class is always "application":

    13:45:21 INFO  application: - Some message
    

    But there is an easy way round this.

    Create a trait:

    import play.api.Logger
    
    trait WithLogging {
       val logger: Logger = Logger(this.getClass())
    }
    

    And in your classes just mix in the trait:

    import WithLogging
    
    class Foobarr extends WithLogging {
       def doFoo = {
          logger.info("Im in foooo")
       }
    }
    

    Now this should be:

    13:45:21 INFO  models.Foobarr: - Im in foooo
    

提交回复
热议问题