春季启动日志记录 [英] Spring boot logging
问题描述
我正在使用Spring boot构建一个简单的REST服务,我想知道最合适的方式来处理日志记录.
I am using Spring boot to build a simple REST service and I am wondering about the most appropriate way to handle the logging.
在我的 application.properties 文件中,我具有以下内容:
In my application.properties file I have the following:
logging.level.org.springframework.web: DEBUG
在开发应用程序时,我只是这样运行它:
While developing the application I simply run it as such:
java -jar myapp.war
因此,我在stdout中得到了所有不错的日志消息.但是,我打算部署它,我想知道什么是最合适的方法来部署应用程序并保留日志.
thus, I got all the nice log messages in stdout. However, I intend to deploy it, and I'm wondering what is the most appropriate way to deploy the application and still have my logs.
当然,您可以简单地重定向输出
Sure, one can simply redirect the output
java -jar myapp.war >> somefile
但这不是很优雅,我想部署我的应用程序,以便可以轻松地将其用作服务:
but this is not very elegant, and I want to deploy my application so that it can easily be used as a service:
ln -s /my/app/xyz.war /etc/init.d/xyz
然后,做
service xyz start|stop|restrart
进行管理.似乎这样做阻止了我重定向stdout ..
to manage it. Seems like doing this prevents me from redirecting stdout ..
对此有任何想法或建议吗?
Any ideas or advice about this?
推荐答案
在application.properties文件中,可以为logging.file设置两个属性.
In you application.properties file you can set two attributes for your logging.file.
类似于文档描述:( 26.3文件输出)
默认情况下,Spring Boot将仅登录到控制台,而不会登录 写入日志文件.如果您还想写日志文件 控制台输出,您需要设置一个...
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
写入指定的日志文件.名称可以是确切的位置,也可以是相对于当前目录的位置.
Writes to the specified log file. Names can be an exact location or relative to the current directory.
-
logging.path
将spring.log写入指定目录.名称可以是确切的位置,也可以是相对于当前目录的位置.
Writes spring.log to the specified directory. Names can be an exact location or relative to the current directory.
设置后,这些日志记录属性之一将被写入文件中.
After setting one of those logging properties will be written in a file.
这篇关于春季启动日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!