Spring/Gradle:向 application.yml 添加自定义日志记录模式可删除日志突出显示
我正在使用 Gradle 开发 Spring Boot 应用程序。我可能会在这里提供很多不必要的背景信息,但我不确定我的问题出在哪里。
我有一个 SLF4j 记录器,它解析为 org.slf4j.impl.Log4jLoggerAdapter。我正在尝试更改控制台日志的日志模式布局。默认模式如下所示:
2022-03-02 17:42:48.892 [ INFO] 19296 --- [ main] ggestions.jvm.JVMLatestVersionSuggestion
在控制台输出中,级别、时间戳和类路径全部突出显示。但是,我真的不喜欢这种格式,并且想覆盖它。
我已将以下内容添加到我的 application.yml
中:
logging.pattern.console: '%d [%t] %-5level %logger{36} - %m%n'< /code>
这给了我我想要的布局,但是突出显示消失并且都是默认颜色。我见过添加 %highlight
的建议,但它无法正确显示 - 它只是在输出中显示为单词 %highlight
,如下所示:
2022-03-02 17:50:09,525 [main] %highlight(INFO ) com.indeed.common.boot.suggestions.jvm.JVMLatestVersionSuggestion
logger 仍在解析为 org.slf4j.impl.Log4jLoggerAdapter。我的猜测是,这是因为 Log4j 不支持突出显示,但我不清楚是什么让它首先工作。可以拿回来吗?
(注意:这是工作代码,我没有能力将 Slf4j 实现更改为 Log4j2)
I'm working in a Spring Boot Application using Gradle. I'm probably going to be giving a lot of unnecessary context here, but I'm not sure where my problem is.
I have an SLF4j logger that's resolving to a org.slf4j.impl.Log4jLoggerAdapter
. I'm trying to change the log pattern layout for the console logs. The default pattern looks like:
2022-03-02 17:42:48.892 [ INFO] 19296 --- [ main] ggestions.jvm.JVMLatestVersionSuggestion
In the console output, the level, timestamp, and class path are all highlighted. However, I really don't like the format, and would like to overwrite it.
I've added the following to my application.yml
:
logging.pattern.console: '%d [%t] %-5level %logger{36} - %m%n'
Which is giving me the layout that I want, but the highlighting disappears and it's all default color. I've seen advice to add %highlight
, but that doesn't correctly display - it just shows up as the word %highlight
in the output, like so:
2022-03-02 17:50:09,525 [main] %highlight(INFO ) com.indeed.common.boot.suggestions.jvm.JVMLatestVersionSuggestion
The logger is still resolving to org.slf4j.impl.Log4jLoggerAdapter
. My guess is that it's because Log4j doesn't support highlighting, but then I'm not clear what was making it work in the first place. Is it possible to get it back?
(note: this is work code, and I don't have the ability to change the Slf4j implementation to Log4j2)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论