jenkins - Jenkins 管道中未使用自定义记录器
问题描述
下面的 Groovy 类中的方法由我不知道的其他一些管道脚本类调用。所有 println 语句都已被 logger.info 替换。
class ConfigurationPluginInitBase implements Plugin<Project> {
private static final Logger logger = LoggerFactory.getLogger(ConfigurationPluginInitBase.class)
.
.
.
protected void configureDependenciesResolution(Project project) {
.
.
.
logger.info("Configuring Dependencies Resolution")
logger.info('Does the buildInfo.json exist? {}' , file.exists())
logger.info('The list of dependencies should be rewritten: {}' ,rewriteDependency)
/*Added this as there was no other way to see what happened to the logger instance*/
println 'Is the logger instance created at all???' + logger
.
.
.
logger.info('List: {}' , listToUpdate)
}
}
log4j2-test.properties
status = error
name = PropertiesConfig
filters = threshold
filter.threshold.type = ThresholdFilter
filter.threshold.level = debug
appenders = console
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c:- %m%n
loggers = console
logger.console.name = ConsoleLog
logger.console.level = debug
logger.console.additivity = false
logger.console.appenderRef.console.ref = STDOUT
rootLogger.level = info
rootLogger.appenderRef.stdout.ref = STDOUT
Jenkins 作业控制台上的输出(仅相关部分如下所示):
.
.
.
.
Download http://artifactory.net:8081/artifactory/Migration_R148_VR/tools.gradle.plugin/BuildPublishReleasePlugin/v4.0.0.37af2ff/ivy-v4.0.0.37af2ff.xml
Download http://artifactory.net:8081/artifactory/Migration_R148_VR/tools.gradle.plugin/BuildPublishReleasePlugin/v4.0.0.37af2ff/BuildPublishReleasePlugin-v4.0.0.37af2ff.jar
//Printed way before the actual logger statements, when the above artifact is //downloaded from Artifactory for further testing in the pipeline
Is the logger instance created at all???org.gradle.internal.logging.slf4j.OutputEventListenerBackedLogger@efbec93c
apache-commons:commons-collections:null
apache-commons:commons-lang:null
DAP_Framework:DAP_FrameworkExt:null
esapi:esapi:null
opensaml:opensaml:null
openws:openws:null
slf4j:slf4j:null
spring-framework:spring-framework:null
TDE_Ark_Framework:TDE_Ark_Framework:null
TDE_Ark_Infrastructure:TDE_Ark_Infrastructure_CLI:null
velocity:velocity:null
wurfl:wurfl:null
xmlsec:xmlsec:null
xmltooling:xmltooling:null.
.
.
.
[Ripple AlfaClient] Configuring Dependencies Resolution
[Ripple AlfaClient] Does the buildInfo.json exist? true
[Ripple AlfaClient] The list of dependencies should be rewritten: DAP_Framework:DAP_Framework_CLI:1.2.2-integration.adcb14d
[Ripple AlfaClient] List: [DAP_Framework:DAP_Framework_CLI:1.2.2-integration.adcb14d]
.
.
.
- 我配置的记录器可能没有被调用
- 运行时实例是OutputEventListenerBackedLogger
- 即使我对记录器语句进行了更改,它们也不会反映在输出中,但我添加的新 println 会反映。这令人困惑,即有些变化会得到反映,而有些则不会!
我提到了Gradle 日志记录页面和类似这样的线程,但 我不清楚根本原因。
注意:我是 Jenkins 管道、Gradle 和 Groovy 的新手 :)
解决方案
我假设您想使用 Gradle 的日志系统作为 Gradle 插件的日志输出?
在这种情况下,我建议以不同的方式创建/获取记录器实例。像这样使用project.logger.info(…)
或创建一个新的Logger
:
private static final Logger logger = Logging.getLogger(ConfigurationPluginInitBase.class)
话虽如此,您的日志消息当前可能未显示的原因可能是 Gradle 的默认日志级别是LIFECYCLE
- 但您似乎只登录到INFO
. --info
您可以尝试使用查看消息的选项运行 Gradle 。
推荐阅读
- scala - 从祖先创建子类实例
- javascript - 在类中使用 TypeORM 未找到连接默认值
- angular - 从 angularcli 中的 HTTP Get 请求检索的数组范围
- r - 如何配置 nlme 以提供与 lme 相同的结果
- c# - 提供 4 位长的序列号失败
- android - OneSignal.init 尚未被调用。将订阅操作移动到等待任务队列
- reactjs - 在 Nginx Docker 容器中运行 React 应用程序的问题
- python - 如何再次将其转换为元组键值列表?
- ios - iOS 操作扩展未打开我的主应用程序
- angular - 如何使用 Ionic 4 项目将 Angular 版本更新为 8