Spring Boot 应用程序的默认日志记录文件

新手上路,请多包涵

我在 application.yml 中设置了 Spring Boot 应用程序的日志记录级别,如下所示:

 logging.level.com.Myapplicationname=DEBUG

该应用程序被打包并部署为对 tomcat 的战争。除此之外,我还没有设置 logback.xml 来定义日志文件等。

当某些用户通过浏览器使用应用程序时,我在哪里可以看到控制台日志?

框架是否创建了任何默认文件?

原文由 Megan 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 380
1 个回答

在 Spring-Boot 2.3.x 之前

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 以下方式之一:

 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 文档 中:

默认情况下,Spring Boot 只会登录到控制台,不会写入日志文件。如果您想在控制台输出之外写入日志文件,您需要设置一个 logging.file 或 logging.path 属性(例如在您的 application.properties 中)。

Spring Boot 的如何记录文档中

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

2. 使用 logging.path

您也可以使用 logging.path 设置路径,在这种情况下,日志文件将自动命名为 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 写入指定目录。名称可以是确切的位置,也可以是相对于当前目录的位置。

springframework.guru 关于 Spring Boot 日志记录

还有一个 logging.path 属性来指定日志文件的路径。如果使用它,Spring Boot 会在指定路径中创建一个 spring.log 文件。但是,您不能同时指定 logging.file 和 logging.path 属性。如果完成,Spring Boot 将忽略两者。

从 Spring-Boot 2.3.x 开始

The previously used properties logging.file or logging.path became deprecated in Spring-Boot 2.2.x and were replaced in version 2.3.x with logging.file.name and logging.file.path .

请参阅 Spring Boot 文档

原文由 alexbt 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进