Jenkins管道中未使用自定义记录器 [英] Custom logger not being used in Jenkins pipeline
问题描述
来自Groovy类下面的方法由其他我不知道的其他管道脚本类调用. 所有println语句已被logger.info取代.
The methods from the below Groovy class are invoked by some other pipeline script classes about which I don't know. All the println statements have been replaced by 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
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作业控制台上的输出(下面仅显示相关部分):
The output(only relevant part shown below) on the Jenkins job console:
.
.
.
.
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]
.
.
.
- 我配置的记录器可能未调用
- 运行时实例为
- The logger that I have configured is probably not invoked
- The run-time instance is of OutputEventListenerBackedLogger
- Even if I make changes to the logger statements, they don't reflect in the output but the new println that I have added does. This is confusing i.e some changes get reflected while some don't!
我提到了 Gradle日志页面和诸如此和
I referred to the Gradle logging page and threads like this and this but I am unclear about the root cause.
注意:我是Jenkins管道,Gradle和Groovy的新手:)
Note: I am new to Jenkins pipeline, Gradle and Groovy :)
推荐答案
我假设您想将Gradle的日志记录系统用于Gradle插件的日志输出?
I assume you would like to use Gradle’s logging system for your log output from a Gradle plugin?
在那种情况下,我建议以不同的方式创建/获取记录器实例.使用
project.logger.info(…)
或In that case I would suggest to create/get the logger instance differently. Either use
project.logger.info(…)
or create a newLogger
like so:private static final Logger logger = Logging.getLogger(ConfigurationPluginInitBase.class)
话虽如此,您的日志消息当前可能不显示的原因可能是Gradle的默认日志级别为
LIFECYCLE
–但是您似乎只登录了INFO
.您可以尝试使用--info
选项运行Gradle来查看消息.Having said that, the reason why your log messages might not show up currently could be that Gradle’s default log level is
LIFECYCLE
– but you seem to only be logging toINFO
. You can try running Gradle with the--info
option to see your messages.这篇关于Jenkins管道中未使用自定义记录器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!