我的play
应用程序具有一个定义为trait
的组件,如下所示:它是数据库连接的接口。
trait CassandraRepositoryComponents {
def environment: Environment
def configuration: Configuration
def applicationLifecycle: ApplicationLifecycle
val utilities:HelperMethods
val cassandraConnectionService = CassandraConnectionManagementService()
val myLogger = LoggerFactory.getLogger(this.getClass.getName)
...
}
AppComponent
类实现了特征。
class AppComponents (context: Context) extends BuiltInComponentsFromContext(context)
with CassandraRepositoryComponents /
..
}
可以分别控制AppComponent
和CassandraRepositoryComponents
的日志记录。目前,CassandraRepositoryComponents
采用AppComponent
的日志记录配置,可能是因为主类是AppComponent
。那么代码val myLogger = LoggerFactory.getLogger(this.getClass.getName)
获得了AppComponent
类名吗?我怎样才能做到这一点?可能是我需要将CassandraRepositoryComponents
从trait
更改为其他内容。那会是什么?
更新
我试图为CassandraRepositoryComponents
val cassandraRepositoryComponentsLogger = LoggerFactory.getLogger("CassandraRepositoryComponents")
但是即使在logback.xml
中启用了所有级别,我也看不到日志记录。
<logger name="cassandraRepositoryComponentsLogger" level="ALL" additivity="false"> <appender-ref ref="STDOUT"/> </logger>
在CassandraRepositoryComponents
的一种方法中,我正在使用记录器和println
,但只能看到println
消息。
println(s"database will connect with keyspace ${keyspaceName}") //SHOWS
cassandraRepositoryComponentsLogger.debug(s"debugger - database will connect with keyspace ${keyspaceName}") //DOESN'T SHOW
答案 0 :(得分:0)
您应在LoggerFactory.getLogger(...)
和<logger name="..."
中使用相同的名称。