【问题标题】:Default logging file for spring boot applicationSpring Boot 应用程序的默认日志记录文件
【发布时间】:2017-01-02 15:33:02
【问题描述】:

我已经在 application.yml 的 spring boot 应用程序中设置了日志级别,如下所示:

logging.level.com.Myapplicationname=DEBUG

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

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

是否有框架创建的默认文件?

【问题讨论】:

    标签: logging spring-boot


    【解决方案1】:

    最新的spring版本有点变化,现在我们要使用了:

    logging.file.name

    而不是使用这个(这是旧方法)

    日志记录文件

    希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      您应该指定logging.filelogging.path,但不能同时指定( 当两者都指定时,logging.path 将被忽略,仅考虑 logging.file

      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 Documentation:

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

      Spring Boot's how to logging doc:

      如果您需要对日志记录进行的唯一更改是设置 各种记录器,然后您可以在 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 doc:

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

      springframework.guru on Spring Boot logging:

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

      【讨论】:

        【解决方案3】:

        对于使用 spring boot 2.2.x 的用户,您需要将其放入配置文件中

        logging.file.name='/var/log/app.log'
        

        或者使用这个

        logging.file.path='/var/log'
        

        请注意,如果您使用 logging.file.path,它会将 spring.log 写入指定目录。名称可以是确切的位置,也可以是相对于当前目录的位置

        【讨论】:

        • 此处无需使用刻度,但感谢您指出 spring boot 2.2.x 中的差异。
        【解决方案4】:

        正如 alexbt 所说,您不能同时使用这两个属性(logging.path 和 logging.file),因为 Spring Boot 会忽略这两个属性。

        但您可以使用带有路径编码的 logging.file。

        示例: logging.file=/path/to/logs/your_logfile.log

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2020-10-18
          • 1970-01-01
          • 2019-05-11
          • 1970-01-01
          • 1970-01-01
          • 2016-05-30
          • 2020-12-01
          • 1970-01-01
          相关资源
          最近更新 更多