我使用Logback和Slf4j进行日志记录,配置是以src/main/resources下的logback.groovy形式出现的,它的工作方式总是很有魅力。
我正要将我的日志配置升级到可用的最新版本,却偶然发现了这个令人不快的问题。
依赖项ch.qos.logback:logback-classic:1.2.9显示了一个警告:
Failed to instantiate [ch.qos.logback.classic.LoggerContext]
Reported exception:
ch.qos.logback.core.LogbackException: Unexpected filename extension of file [file:/[myproj]/build/resources/main/logback.groovy]. Should be either .groovy or .xml
at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:67)
at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:140)
at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84)
...我检查了上一个工作版本的ch.qos.logback.classic.util.ContextInitializer.configureByResource()代码1.2.8和1.2.9。
// 1.2.8
public void configureByResource(URL url) throws JoranException {
if (url == null) {
throw new IllegalArgumentException("URL argument cannot be null");
}
final String urlString = url.toString();
if (urlString.endsWith("groovy")) {
if (EnvUtil.isGroovyAvailable()) {
// avoid directly referring to GafferConfigurator so as to avoid
// loading groovy.lang.GroovyObject . See also http://jira.qos.ch/browse/LBCLASSIC-214
GafferUtil.runGafferConfiguratorOn(loggerContext, this, url);
} else {
StatusManager sm = loggerContext.getStatusManager();
sm.add(new ErrorStatus("Groovy classes are not available on the class path. ABORTING INITIALIZATION.", loggerContext));
}
} else if (urlString.endsWith("xml")) {
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(loggerContext);
configurator.doConfigure(url);
} else {
throw new LogbackException("Unexpected filename extension of file [" + url.toString() + "]. Should be either .groovy or .xml");
}
}
// 1.2.9
public void configureByResource(URL url) throws JoranException {
if (url == null) {
throw new IllegalArgumentException("URL argument cannot be null");
}
final String urlString = url.toString();
if (urlString.endsWith("xml")) {
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(loggerContext);
configurator.doConfigure(url);
} else {
throw new LogbackException("Unexpected filename extension of file [" + url.toString() + "]. Should be either .groovy or .xml");
}
}因此,警告可能是错误的,但代码更改是显而易见的: groovy支持被删除,尽管在-warning中没有提供“反推荐”的参考文献。
为什么groovy支持被删除了?
为什么没有引入"logback-groovy“包来提供支持?
项目的GitHub上没有“问题”一节,这很奇怪.
发布于 2022-11-15 12:30:37
检查点4在此:
https://logback.qos.ch/news.html#1.2.9
这是对CVE-2021-42550的回应
删除了Groovy配置支持。由于日志记录非常普遍,使用Groovy的配置可能过于强大,因此出于安全考虑,不太可能恢复此功能。
https://stackoverflow.com/questions/74445304
复制相似问题