简体   繁体   English

问题安排SpringBoot控制台output日志

[英]Issue arranging SpringBoot console output log

Small question on how to re arrange a SpringBoot application output log please.关于如何重新安排一个SpringBoot应用的小问题 output log 请教。

It is well known, if no configuration change, the logs seen in console for a SpringBoot app looks like this:众所周知,如果不更改配置,在 SpringBoot 应用程序的控制台中看到的日志如下所示:

2023-01-30T21:21:06.076+08:00  INFO 5216 --- [           main] org.example.Main                         : Started Main in 3.544 seconds (process running for 4.151)
2023-01-30T21:21:06.078+08:00 DEBUG 5216 --- [           main] o.s.b.a.ApplicationAvailabilityBean      : Application availability state LivenessState changed to CORRECT

It is a timestamp -> log level -> PID -> --- -> thread -> the class是时间戳->日志级别->PID->--->线程->class

I just want to rearrange the order to something like:我只想将顺序重新排列为:

timestamp -> PID -> log level -> --- -> applicationName -> thread -> the class时间戳 -> PID -> 日志级别 -> --- -> applicationName -> 线程 -> class

Something like:就像是:

2023-01-30T21:21:06.076+08:00 5216  INFO --- [myappName][           main] org.example.Main                         : Started Main in 3.544 seconds (process running for 4.151)
2023-01-30T21:21:06.078+08:00 5216 DEBUG --- [myappName][           main] o.s.b.a.ApplicationAvailabilityBean      : Application availability state LivenessState changed to CORRECT

What I tried:我尝试了什么:

I saw there is a property for that, and I tried:我看到有一个属性,我试过了:

logging.pattern.level=%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]

However, this is not giving the correct output.然而,这并没有给出正确的 output。

May I ask what is the pattern in order to have this please?请问要这个是什么图案?

2023-01-30T21:21:06.076+08:00 5216  INFO --- [myappName][           main] org.example.Main                         : Started Main in 3.544 seconds (process running for 4.151)
2023-01-30T21:21:06.078+08:00 5216 DEBUG --- [myappName][           main] o.s.b.a.ApplicationAvailabilityBean      : Application availability state LivenessState changed to CORRECT

Thank you谢谢

Add the following to application.properties :将以下内容添加到application.properties

logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} %-5level ${PID} --- [${spring.application.name}]  [%thread] %logger{36} : %msg%n
spring.application.name=@project.name@

Sample output:样本 output:

2023-01-30 18:21:22 INFO  5340 --- [qualifier]  [main] c.example.demo.QualifierApplication : Starting QualifierApplication using Java 11.0.15 on NB-3HP3HG3 with PID 5340 (C:\workspaces\stackoverflow_workspace\qualifier\target\classes started by WilliamsJ in C:\workspaces\stackoverflow_workspace\qualifier)
2023-01-30 18:21:22 INFO  5340 --- [qualifier]  [main] c.example.demo.QualifierApplication : No active profile set, falling back to 1 default profile: "default"
2023-01-30 18:21:22 INFO  5340 --- [qualifier]  [main] o.s.b.w.e.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM