spring boot tomcat访问日志按大小旋转

spring boot tomcat访问日志按大小旋转,tomcat,spring-boot,Tomcat,Spring Boot,是否可以根据大小旋转tomcat访问日志?通过调查,我找不到这样的选择。以下是我看到的唯一访问日志选项: 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

是否可以根据大小旋转tomcat访问日志?通过调查,我找不到这样的选择。以下是我看到的唯一访问日志选项:

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不提供基于大小的访问日志轮换,尽管您可以使用server.Tomcat.accesslog.file-date-format使用文件日期格式配置每小时/每月等。例如每小时

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

若仍需要仅根据尺寸进行旋转,则可以扩展访问日志阀。检查或参考

使用开箱即用的Tomcat无法做到这一点。但有两种选择

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

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