如何为 spring-boot 应用程序设置 logging.path? [英] How to set logging.path for spring-boot apps?
问题描述
spring-boot
提供了几个 logging.*
设置,可以应用在 application.properties
中,例如:
spring-boot
provides several logging.*
settings that can be applied in application.properties
, like:
logging.level.=DEBUG
logging.file=myfile.log
logging.path=d:/logs/
问题:生成了myfile.log
,但在类路径中!为什么spring不考虑我的绝对路径?
Problem: myfile.log
is generated, BUT inside the classpath! Why isn't spring taking my absolute path into account?
推荐答案
默认情况下,Spring Boot 只会登录到控制台,不会写日志文件.如果你想写日志文件除了控制台输出您需要设置 logging.file 或 logging.path 属性(例如在您的 application.properties 中).
By default, Spring Boot will only log to the console and will not write log files. If you want to write log files in addition to the console output you need to set a logging.file or logging.path property (for example in your application.properties).
然后描述 logging.file
和 logging.path
属性是如何工作的.你应该只设置一个.
and then describes how the logging.file
and logging.path
properties work. You should only set one.
如果设置了 logging.file
,它将写入该特定文件.文档说明
If logging.file
is set, it will write to that specific file. The documentation states
名称可以是确切位置或相对于当前目录.
Names can be an exact location or relative to the current directory.
因此您可能正在写入当前目录,该目录恰好与您的类路径相同.
So you're likely writing to your current directory, which happens to be the same as your classpath.
如果设置了logging.path
,Spring Boot
If you set logging.path
, Spring Boot
将 spring.log
写入指定目录.名称可以是确切位置或相对于当前目录.
Writes
spring.log
to the specified directory. Names can be an exact location or relative to the current directory.
检查您当前的目录是否不是您的类路径,如果您不希望它们混合,并调整 logging.file
和 logging.path
之一相应地.
Check that your current directory isn't your classpath, if you don't want them to mix, and adapt one of the logging.file
and logging.path
accordingly.
这篇关于如何为 spring-boot 应用程序设置 logging.path?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!