本文介绍了Logback配置-如何包括Spring Application Version的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于分析目的,我想在所有日志条目中记录应用程序版本(理想情况下,我想通过编辑logback-spring.xml文件而不是编写任何Java代码来做到这一点.)

For analysis purposes, I want to log the application version in all log entries (ideally I would want to do this by editing the logback-spring.xml file instead of writing any Java code).

我已经成功记录了spring应用程序名称.

I'm am already logging spring application name successfully.

请注意示例示例启动日志消息,其中显示了正确的应用程序版本.

Note example startup up log message that shows correct application version.

根据我的年级版本-我是否以正确的实现版本更新清单文件.为了实现Spring构建执行器,我还设置了info.build.version = $ {version}.

As per my grade build -- am I updating the manifest file with the correct implementation-version. For Spring build actuator purposes I'm also setting info.build.version=${version}.

请参见下面的示例-我不确定要放入的内容是???正确记录应用程序版本.我尝试了许多键,包括:info.build.version,application.version,spring.application.version等.

See below example -- I'm not sure what to put in ??? to correctly log the application version. I'm tried a number of keys including: info.build.version, application.version, spring.application.version, etc ..

 <springProperty name="APP_NAME" source="spring.application.name"/>

 <springProperty name="APP_VERSION" source="???"/>

 <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
     <encoder>
         <pattern> version=${APP_VERISON} site=${APP_NAME}  %msg%n </pattern>
     </encoder>
 </appender>

推荐答案

根据文档

对于 Maven ,您可以使用资源过滤自动扩展Maven项目中的属性.如果使用 spring-boot-starter-parent ,则可以通过@ .. @占位符

For Maven you can automatically expand properties from the Maven project using resource filtering. If you use spring-boot-starter-parent you can then refer to your Maven ‘project properties’ via @..@ placeholders

您可以在您的application.properties文件中添加maven项目属性,例如

You can add maven project properties in your application.properties file such as

[email protected]@

对于 Gradle ,您需要通过配置Java插件的processResources

For Gradle you need to expand properties from the Gradle project by configuring the Java plugin’s processResources

processResources {
    filesMatching('application.properties') {
        expand(project.properties)
    }
}

可以通过占位符访问.

app.name=${name}
app.description=${description}
app.version=${version}

您可以使用这些属性在logback.xml中添加

You can use these properties to add in logback.xml

谢谢

这篇关于Logback配置-如何包括Spring Application Version的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 00:57