【问题标题】:how to rotate log file in spring boot如何在spring boot中旋转日志文件
【发布时间】:2021-06-04 06:27:11
【问题描述】:

我尝试创建一个日志文件配置,当它大小为 20MB 时会创建一个新的日志文件。我正在使用 application.yaml 文件。我在文档和互联网上搜索了这个文件配置,但在我的机器上没有用。我还尝试了其他方法,例如文件的位置、分隔符(由 / 更改)以及 application.yaml 中属性的层次结构。

所以我的文件配置是这样的:

server:
  port: 8080
  logging.file: D:\logs\logfile.txt
  logging:
    file:
      max-history: 20
      max-size: 50MB
    level:
      org.springframework.web: DEBUG
      org.hibernate: DEBUG
spring:
  mvc:
    throw-exception-if-no-handler-found: true
  resources:
    add-mappings: false
  security:
    basic:
      enable: false
  server:
    contextPath: /
  datasource:
    url: jdbc:postgresql://servername.myent.com:5432/appname
    username: meandmsjake
    password: 123abc
    driver-class-name: org.postgresql.Driver
    type: com.zaxxer.hikari.HikariDataSource
    hikari:
      maximum-pool-size: 20
      idle-timeout: 10000
  jpa:
    #database-platform: org.hibernate.dialect.PostgreSQLDialect
    database-platform: org.hibernate.spatial.dialect.postgis.PostgisDialect
    show-sql: true
    properties:
      hibernate:
        temp:
          use_jdbc_metadata_defaults: false
    hibernate:
      ddl-auto: none

【问题讨论】:

    标签: spring logging yaml


    【解决方案1】:

    这里似乎有两个问题:

    1. 考虑到树形结构,我不确定同时设置 logging.file 和 logging.file.max-history 在 yaml 中是否有效。为了解决这个问题,我会尝试将这些特定属性放在 yaml 中。
    2. 我不认为 server.logging.file 是正确的属性(正如您在此处所拥有的那样)。它应该是简单的 logging.file。因此,其他属性不应以“server”为前缀。

    也就是说,如果您发布您正在使用的 Spring Boot 版本将会很有帮助。

    【讨论】:

    • Spring boot的版本是2.1.3。
    • 在这种情况下,属性肯定是 logging.file、logging.file.max-size、logging.file.max-history not server.logging.file、server。 logging.file.max-length, server.logging.file.max-history
    • 我在 localhost confs 中尝试发送到开发服务器之前。
    • 无论您是在本地运行还是在开发服务器上运行,属性名称都将如我所说的那样
    • 非常感谢@alexander-katsenelenbogen,但让我们解释一下我的痛苦,因为您可能不明白:我确实尝试将我的应用程序登录到一个文件中,我称之为logs/logfile.log。它还没有工作。在我的控制台中做了日志,就像一个像 logger.info("teste 123"); 这样的日志消息
    猜你喜欢
    • 2017-06-19
    • 2017-05-08
    • 1970-01-01
    • 1970-01-01
    • 2014-01-26
    • 1970-01-01
    • 2021-07-14
    • 2016-12-30
    • 1970-01-01
    相关资源
    最近更新 更多