Logging
在默认情况下,Spring Boot 应用程序会将消息记录到控制台,这非常令人讨厌,还可能与 shell 命令混合输出。幸运的是,有一个简单的方法可以通过 boot 属性指导日志记录更改。
On default a Spring Boot application will log messages into a console which at minimum is annoying and may also mix output from a shell commands. Fortunately there is a simple way to instruct logging changes via boot properties.
通过将其模式定义为空值来完全禁止控制台日志记录。
Completely silence console logging by defining its pattern as an empty value.
logging:
pattern:
console:
如果你需要 shell 日志,然后将其写入文件。
If you need log from a shell then write those into a file.
logging:
file:
name: shell.log
如果你需要不同的日志级别。
If you need different log levels.
logging:
level:
org:
springframework:
shell: debug
不支持将配置属性作为命令行选项传递,但你可以使用 boot 支持的任何其他方式,例如。
Passing contiguration properties as command line options is not supported but you can use any other ways supported by boot, for example.
$ java -Dlogging.level.root=debug -jar demo.jar
$ LOGGING_LEVEL_ROOT=debug java -jar demo.jar
GraalVM 镜像中的设置在编译过程中被锁定,这意味着您在运行时无法更改日志级别。 |
In a GraalVM image settings are locked during compilation which means you can’t change log levels at runtime. |