英文:
I cannot get logback to reference a generated git.properties file after I've built and deployed my service, what am I doing wrong?
问题
我在Maven中有以下的插件设置:
<plugins>
<!-- This will add a git.properties file in the resources folder with commit information we can reference-->
<plugin>
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
<version>6.0.0</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
</configuration>
</plugin>
</plugins>
我的 logback-spring.xml
如下所示:
<configuration>
<springProperty scope="context" name="applicationVersion" source="project.version" defaultValue="unknown" />
<springProfile name="!dev">
<springProperty scope="context" name="gitCommitId" source="git.commit.id.abbrev" defaultValue="unknown" />
</springProfile>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
</configuration>
applicationVersion
正如预期地出现在日志中,但这是从 application.properties
文件中引用的。
git.properties
文件生成并放置在以下位置:
target/my-service-7.0-SNAPSHOT/WEB-INF/classes/git.properties
target/classes/git.properties
如预期,当我运行开发配置时,gitCommitId
不会出现在日志中,但当我部署它时,它会出现在日志中,其默认值为 "unknown"。
我做错了什么?
英文:
I have the following plugin setup in maven:
<plugins>
<!-- This will add a git.properties file in the resources folder with commit information we can reference-->
<plugin>
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
<version>6.0.0</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
</configuration>
</plugin>
My logback-spring.xml
looks like this:
<configuration>
<springProperty scope="context" name="applicationVersion" source="project.version" defaultValue="unknown" />
<springProfile name="!dev">
<springProperty scope="context" name="gitCommitId" source="git.commit.id.abbrev" defaultValue="unknown" />
</springProfile>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
</configuration>
The applicationVersion
appears in the logs as expected, but this is referenced from the application.properties
file.
The git.properties
file is generated and placed in the following locations:
target/my-service-7.0-SNAPSHOT/WEB-INF/classes/git.properties
target/classes/git.properties
As expected, gitCommitId
doesn't appear when I'm running the dev profile, but when I deploy it, it appears in the logs with the default value "unknown".
What am I doing wrong?
答案1
得分: 0
我改变了这个策略,不再尝试直接访问 git.properties
,而是将其导入到 application.properties
,然后像其他属性一样,可以被 logback 访问。
解决方案请参见此处:https://stackoverflow.com/a/76686438/571875
英文:
I changed my strategy for this, instead of trying to access git.properties
directly, I now import it into application.properties
instead, then it is accessible to logback as the other properties are.
See here for the solution: https://stackoverflow.com/a/76686438/571875
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论