【问题标题】:spring-boot tomcat access log rotation by sizespring-boot tomcat 访问日志按大小轮换
【发布时间】:2018-03-21 16:49:41
【问题描述】:

是否可以根据大小轮换 tomcat 访问日志?通过Appendix,我找不到这样的选项。这些是我看到的唯一访问日志选项:

server.tomcat.accesslog.buffered=true # Whether to buffer output such that it is flushed only periodically.
server.tomcat.accesslog.directory=logs # Directory in which log files are created. Can be absolute or relative to the Tomcat base dir.
server.tomcat.accesslog.enabled=false # Enable access log.
server.tomcat.accesslog.file-date-format=.yyyy-MM-dd # Date format to place in the log file name.
server.tomcat.accesslog.pattern=common # Format pattern for access logs.
server.tomcat.accesslog.prefix=access_log # Log file name prefix.
server.tomcat.accesslog.rename-on-rotate=false # Whether to defer inclusion of the date stamp in the file name until rotate time.
server.tomcat.accesslog.request-attributes-enabled=false # Set request attributes for the IP address, Hostname, protocol, and port used for the request.
server.tomcat.accesslog.rotate=true # Whether to enable access log rotation.
server.tomcat.accesslog.suffix=.log # Log file name suffix.

【问题讨论】:

    标签: tomcat spring-boot


    【解决方案1】:

    开箱即用的 Tomcat 无法做到这一点。但是有几个选择。

    a) 通过将 server.tomcat.accesslog.rotate 设置为 false 来完全禁用 tomcat 的旋转,然后使用另一个实用程序(如 unix 的 logrotate)进行旋转,它支持按大小旋转。使用copytruncate 选项避免重启tomcat。

    b) 实现自定义AccessLogValve 并覆盖rotate() 方法以根据需要自定义旋转。然后在 TomcatEmbeddedServletContainerFactory 中使用addContextValves 注入此阀门(您可以找到自定义 TomcatEmbeddedServletContainerFactory here 的示例)。您还必须从getValves 返回的列表中删除默认实现。

    【讨论】:

      【解决方案2】:

      默认情况下,Tomcat 不提供基于大小的访问日志轮换,但您可以使用 server.tomcat.accesslog.file-date-format 使用文件日期格式配置每小时/每月等配置。例如每小时

      server.tomcat.accesslog.file-date-format=.yyyy-MM-dd.HH
      

      如果您仍然需要仅根据大小旋转,您可以扩展Access Log Valve。检查tomcat docs或参考this thread

      【讨论】:

        猜你喜欢
        • 2017-09-25
        • 2014-06-29
        • 1970-01-01
        • 2020-03-30
        • 2014-01-01
        • 2019-08-25
        • 2017-10-26
        • 2018-07-18
        • 1970-01-01
        相关资源
        最近更新 更多