Java spring-boot 默认日志位置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31939849/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
spring-boot default log location
提问by cahen
In a spring-boot
application I can specify a custom log file with
在spring-boot
应用程序中,我可以指定一个自定义日志文件
java -jar spring-boot-app.jar --logging.file=/home/ubuntu/spring-boot-app.log
java -jar spring-boot-app.jar --logging.file=/home/ubuntu/spring-boot-app.log
But if I don't specify one, where does it go?
但是如果我不指定一个,它会去哪里?
I couldn't find it in any of the following folders:
我在以下任何文件夹中都找不到它:
/tmp/
/var/log/
~/
I do nothave spring-boot-starter-logging
or any additional logging dependencies.
我不具备spring-boot-starter-logging
或任何其他日志记录的依赖。
I was hoping to have something similar to catalina.out
since the default configuration runs an embedded Tomcat:
我希望有类似的东西,catalina.out
因为默认配置运行嵌入式 Tomcat:
INFO 10374 --- [main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8100 (http)
采纳答案by Laurentiu L.
Spring Boot uses Commons Logging for all internal logging, but leaves the underlying log implementation open.
Spring Boot 使用 Commons Logging 进行所有内部日志记录,但保持底层日志实现开放。
Default configurations are provided for Java Util Logging, Log4J, Log4J2 and Logback. In each case loggers are pre-configured to use console outputwith optional file output also available.
为 Java Util Logging、Log4J、Log4J2 和 Logback 提供了默认配置。在每种情况下,记录器都预先配置为使用控制台输出,也可以使用可选的文件输出。
From the Spring Boot logging documentation.
The default log configuration will echo messages to the console as they are written. So until you explicitly specify a file as you described, it stays in the Console.
默认日志配置将在写入消息时将消息回显到控制台。因此,除非您按照描述明确指定文件,否则它会保留在控制台中。
回答by ZhaoGang
By default, Spring Boot logs only to the console and does 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
).
默认情况下,Spring Boot 只记录到控制台,不写入日志文件。如果你想在控制台输出之外写入日志文件,你需要设置一个logging.file
orlogging.path
属性(例如,在你的 中application.properties
)。
Below codes in your application.properties
will write the log into /home/user/my.log
:
您application.properties
将以下代码写入日志/home/user/my.log
:
logging.path = /home/user
logging.file = my.log
回答by LeandroPL
By default Spring Boot does not output logs to any file. If you want to have logs written in a file (in addition to the console output) then you should use either of logging.fileor logging.pathproperties (not both).
默认情况下,Spring Boot 不会将日志输出到任何文件。如果您希望将日志写入文件(除了控制台输出),那么您应该使用logging.file或logging.path属性之一(不是两者)。
In application.properties, just set:
在 application.properties 中,只需设置:
logging.file=/home/ubuntu/spring-boot-app.log
This will create a spring-boot-app.log
file under /home/ubuntu
.
这将spring-boot-app.log
在/home/ubuntu
.