我有一个春季启动应用程序。嵌入式tomcat的访问日志配置为每天在application.properties中以时间戳后缀进行旋转。我的要求是将旋转的日志文件生成到存档文件夹中。但我找不到任何配置来指定application.properties中旋转文件的位置。有谁知道如何实现这一目标?
所有最新日志都将在/ logs文件夹中,所有轮换的日志文件应位于/ logs / archive文件夹中。 - 这该怎么做?
您可以创建DailySchedular类来完成该任务。使用@EnableScheduling
和@Scheduled
方法,每天唤醒一次,根据日期扫描想要的目录,并将所需文件删除到存档目录。
OK, finally i figured out a way to do this using logback access.
Include the following dependency
<dependency>
<groupId>net.rakugakibox.spring.boot</groupId>
<artifactId>logback-access-spring-boot-starter</artifactId>
<version>2.7.0</version>
</dependency>
Also create a logback-access.xml in resources folder with following configuration.
<configuration>
<property resource="application.properties" />
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/dev_access.log</file>
<rollingPolicy
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>logs/Archive/dev_access_%d{yyyy-MM-dd}.log</fileNamePattern>
</rollingPolicy>
<encoder>
<pattern>%h %l %u %t "%r" %s %b %D</pattern>
</encoder>
</appender>
<appender-ref ref="FILE" />
</configuration>