我正在尝试执行以下groovy代码,以获取应用程序中的活动记录器的名称:
import org.apache.logging.log4j.core.*
loggers = LoggerContext.getLoggers()
loggers.toArray().each {
println it
}
脚本因此错误而失败:
Script execution has failed [reason: groovy.lang.MissingMethodException: No signature of method: static org.apache.logging.log4j.core.LoggerContext.getLoggers() is applicable for argument types: () values: []
Possible solutions: getLoggers(), getLogger(java.lang.String), getLogger(java.lang.String, org.apache.logging.log4j.message.MessageFactory), hasLogger(java.lang.String), hasLogger(java.lang.String, java.lang.Class), hasLogger(java.lang.String, org.apache.logging.log4j.message.MessageFactory)]
我尝试用Collection<Logger>
定义loggers变量,但发生了同样的错误。
我做错了什么?
答案 0 :(得分:0)
没错,没有静态getLoggers()
。您需要先获得LoggerContext
实例:
loggers = LoggerContext.getContext().getLoggers()