【发布时间】:2012-12-03 14:15:00
【问题描述】:
我正在使用 Grails 2.1.1 进行开发,现在我想将 Logback (http://logback.qos.ch) 集成为默认的日志框架,因为它应该提供一些更好的日志功能,并且还可以通过 Groovy 进行配置.
由于 Logback 1.0.7(最新)仅适用于 slf4j 1.6.6 我想升级 Grails 依赖项。 Grails 2.1.1 使用slf4j 1.6.2。如何正确执行此操作?
我尝试了以下方法:在BuildConfig.groovy 中,我排除了grails-plugin-log4j 和slf4j-api
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
excludes "grails-plugin-log4j", "slf4j-api"
}
...
}
我尝试将slf4j-api 1.6.6 加载到compile build 和runtime 以及其他必要的库中
grails.project.dependency.resolution = {
...
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
compile "org.slf4j:slf4j-api:1.6.6"
build "org.slf4j:slf4j-api:1.6.6",
"ch.qos.logback:logback-core:1.0.7",
"ch.qos.logback:logback-classic:1.0.7"
runtime "org.slf4j:slf4j-api:1.6.6",
"org.slf4j:log4j-over-slf4j:1.6.6", // logback dependency for classic module, as seen on http://logback.qos.ch/dependencies.html
"ch.qos.logback:logback-core:1.0.7",
"ch.qos.logback:logback-classic:1.0.7"
}
...
}
现在,如果我想从 Grails 命令行(grails compile 或 grails clean)执行任何操作,它会抱怨它无法执行脚本,因为它找不到 LoggerFactory 类:
| Loading Grails 2.1.1
| Configuring classpath
| Error Error executing script Compile: org/slf4j/LoggerFactory (NOTE: Stack trace has been filtered. Use --verbose to see entire trace.)
java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:156)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:272)
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.<clinit>(PathMatchingResourcePatternResolver.java:169)
| Error Error executing script Compile: org/slf4j/LoggerFactory
如何正确升级底层slf4j-api?
如果我不首先排除 slf4j-api,我会在调用 grails dependency-report 时与标记为驱逐的“旧”1.6.2 api 发生冲突...
另外,我希望有一个用于 Logback 的外部配置文件。我将如何实施它?使用 Log4j,我刚刚在 conf/spring/resources.groovy 文件中声明了一个 log4jConfigurer bean - 如何使用 Logback 完成?
有没有人使用 Logback 记录 Grails 2.1.1 的经验,可以就这个问题给我任何建议吗?
【问题讨论】: