首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么logback.groovy会被丢弃在1.2.9+中呢?

为什么logback.groovy会被丢弃在1.2.9+中呢?
EN

Stack Overflow用户
提问于 2022-11-15 12:03:41
回答 1查看 31关注 0票数 0

我使用Logback和Slf4j进行日志记录,配置是以src/main/resources下的logback.groovy形式出现的,它的工作方式总是很有魅力。

我正要将我的日志配置升级到可用的最新版本,却偶然发现了这个令人不快的问题。

依赖项ch.qos.logback:logback-classic:1.2.9显示了一个警告:

代码语言:javascript
复制
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.81.2.9

代码语言:javascript
复制
// 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上没有“问题”一节,这很奇怪.

EN

回答 1

Stack Overflow用户

发布于 2022-11-15 12:30:37

检查点4在此:

https://logback.qos.ch/news.html#1.2.9

这是对CVE-2021-42550的回应

删除了Groovy配置支持。由于日志记录非常普遍,使用Groovy的配置可能过于强大,因此出于安全考虑,不太可能恢复此功能。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74445304

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档