YAML 文件中可以进行字符串操作吗?
YAML 文件中可以进行字符串操作吗?
Spring Boot应用程序中的配置文件application.yml正在从pom文件读取版本作为
<properties>
<revision>10.10.11</revision>
</properties>
YAML文件
logging:
file:
name: @revision@/app.log
问题是,如何从修订值中删除点,即
“2011年10月10日”→“101011”
之类的
name: @[email protected]('.', '')/app.log
,这样就可以在不带点的文件夹上生成日志文件
Is String manipulation possible in YAML file??
The configuration file application.yml in a Spring Boot application is reading the version from the pom file as
<properties>
<revision>10.10.11</revision>
</properties>
The YAML file
logging:
file:
name: @revision@/app.log
The issue is, how to remove the dots from the revision value i.e.
"10.10.11" → “101011“
like
name: @[email protected]('.', '')/app.log
, so that a log file can be generated on a folder without dots
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于一般情况,您可以使用 SpEL< /a> 允许调用 Java 方法:
您需要外部引号来告诉 yml
#
不开始注释,并引用@revision@
以便它被 SpEL 解释为字符串。问题是它似乎不适用于
logging.file.name
因为它是由LoggingApplicationListener
&LogFile
似乎不解释 SpEL。通过 Spring Boot 配置来自定义它似乎并不容易,但是您可以定义自己的侦听器(可能基于上面的侦听器)来定义您自己的命名方案。
以下问题可能也有帮助: 在 Spring Boot Starter 中注册自定义日志附加程序< /a>
For the general case, you could use SpEL which allows to call Java methods:
You would need the outer quotes to tell yml that
#
does not start a comment, and to quote@revision@
so that it is interpreted as a String by SpEL.The problem is that it does not seem to work with
logging.file.name
because it is read byLoggingApplicationListener
&LogFile
which does not seem to interpret SpEL.It does not seem easy to customize this through Spring Boot configuration, but you could instead define your own listener (possibly based on the one above) to define your own naming scheme.
The following question might also help: register custom log appender in spring boot starter