Spring Boot应用程序的默认日志文件 [英] Default logging file for spring boot application

查看:101
本文介绍了Spring Boot应用程序的默认日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已在spring.boot应用程序的application.yml中将日志记录级别设置为: logging.level.com.Myapplicationname =调试

I have set the logging level in the spring boot application in application.yml as: logging.level.com.Myapplicationname=DEBUG

该应用程序已打包并部署为tomcat上的war.除此之外,我还没有设置logback.xml来定义日志文件等.请告诉我,当某些用户通过浏览器使用应用程序时,在哪里可以看到控制台日志.框架是否创建了任何默认文件.

The application is packaged and deployed as war on tomcat. Apart from this I haven't set the logback.xml to define the log file etc. Please tell me where can I see the console logs when some user uses the application over the browser. Is there any default file created by framework.

推荐答案

您应该指定logging.filelogging.path,但不能同时指定两个( 如果同时指定了两者,则logging.path将被忽略,而仅考虑logging.file.

You should either specify logging.file or logging.path, but not both ( when both are specified, logging.path is ignored and only logging.file is considered).

1.使用logging.file

您可以使用以下任一方法使用logging.file:

You may use logging.file one of the following way:

logging.file = logfile.log                     //in current folder
logging.file = relativepath/to/logfile.log     //relative path with filename
logging.file = /fullpath/to/logfile.log        //full path with filename

默认情况下,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).

Spring Boot的文档记录方法中,:

如果您唯一需要对日志记录进行的更改是设置日志记录的级别 各种记录器,然后您可以在application.properties中使用 "logging.level"前缀,例如 您还可以设置要登录到的文件的位置(除了 控制台)使用"logging.file".

If the only change you need to make to logging is to set the levels of various loggers then you can do that in application.properties using the "logging.level" prefix, e.g. You can also set the location of a file to log to (in addition to the console) using "logging.file".

2.使用logging.path

您还可以使用logging.path设置路径,在这种情况下,日志文件将自动命名为spring.log:

You could also use logging.path to set the path, in which case the logfile will automatically be be named spring.log:

logging.path = ./                         // -> spring.log in current folder
logging.path = relativepath/to/logs       // -> relativepath/to/logs/spring.log
logging.path = /fullpath/to/logs          // -> /fullpath/to/logs/spring.log

Spring Boot文档:

[使用logging.path ]将spring.log写入指定目录. 名称可以是确切的位置,也可以是相对于当前目录的位置.

[Using logging.path] Writes spring.log to the specified directory. Names can be an exact location or relative to the current directory.

Spring Boot日志中的springframework.guru :

还有一个logging.path属性,用于指定日志记录的路径 文件.如果使用它,Spring Boot会在 指定的路径.但是,不能同时指定logging.file和 logging.path属性在一起.如果完成,Spring Boot将忽略 两者.

There is also a logging.path property to specify a path for a logging file. If you use it, Spring Boot creates a spring.log file in the specified path. However, you cannot specify both the logging.file and logging.path properties together. If done, Spring Boot will ignore both.

这篇关于Spring Boot应用程序的默认日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆