我正在写一个Groovy脚本,可以拉出Misc。git存储库中的文件中的信息,它使用JSonSlurper从JSON文件中提取数据,XmlSlurper从XML文件中提取数据。
一切都很正常,除了我所有的日志语句在运行过程中都会发出不必要的消息,这些消息看起来都是这样的:
Aug. 14, 2023 3:05:27 PM **org.codehaus.groovy.vmplugin.v8.IndyInterface fromCache**
INFO: --- actual log statement here ---
即,每条日志输出行都以这样的行作为前缀。我正在使用java.util. logg.Logger进行日志记录。
任何人知道这些陈述试图传达给我什么,以及如何避免这些恼人的输出?
**Addition:**基于第一个答案,我将其添加到我的代码中,但我仍然得到这些输出:
static { // silence the annoying groovy indy log output:
System.setProperty("groovy.indy.logging", "false")
}
即使通过-Dgroovy.indy.logging=false
在VM命令行上设置这个也没有帮助。有什么办法可以关闭这些日志语句吗?
**第二个补充:**这些日志语句是一个坚韧的cookie!我将建议的语句Logger.getLogger(org.codehaus.groovy.vmplugin.v8.IndyInterface.class.getName()).setLevel( Level.SEVERE )
添加到类的静态初始化器(即static { ... }
-如上所述),到对象示例初始化器(即,{ ... }
),在main()方法的开始,我用它来创建和执行解析,如下所示:
Logger.getLogger(org.codehaus.groovy.vmplugin.v8.IndyInterface.class.getName()).setLevel(Level.SEVERE)
def json = new JsonSlurper()
Logger.getLogger(org.codehaus.groovy.vmplugin.v8.IndyInterface.class.getName()).setLevel(Level.SEVERE)
rootNode = json.parse(new StringReader(content))
Logger.getLogger(org.codehaus.groovy.vmplugin.v8.IndyInterface.class.getName()).setLevel(Level.SEVERE)
and I am still getting得到these log日志outputs输出.现在我真的很困惑!
1条答案
按热度按时间p8h8hvxi1#
https://docs.groovy-lang.org/latest/html/api/org/codehaus/groovy/vmplugin/v8/IndyInterface.html
这个类通过使用布尔系统属性
groovy.indy.logging
来提供日志记录功能。删除此系统属性或将其设置为false应该可以解决您的问题。
https://github.com/apache/groovy/blob/master/src/main/java/org/codehaus/groovy/vmplugin/v8/IndyInterface.java#L126