[英]Archive only old logs with logback
Is it possible to to archive only the old files with the logs? 是否可以仅使用日志归档旧文件?
For example, I need to store logs as text 14 days, and then archive? 例如,我需要将日志存储为文本14天,然后进行归档?
Currently used appender: 当前使用的追加器:
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>../log/mylog.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>../log/mylog.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>50MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>50</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy.MM.dd HH:mm:ss} %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
He archives the files immediately after the change log file. 他在更改日志文件之后立即归档文件。
slf4j-1.7.2 / logback-1.0.9 slf4j-1.7.2 / logback-1.0.9
The rolled-over log file is an alias of archived log file in logback so that rolling means means archiving. 滚转日志文件是logback中已归档日志文件的别名,因此滚转表示存档。
I need to store logs as text 14 days, and then archive 我需要将日志存储为文本14天,然后进行归档
Then don't make a max file limit on rolling policy. 然后,不要对滚动策略设置最大文件限制。 However, I don't think it is necessary to make it as text. 但是,我认为没有必要将其制成文本。 As far as I know, logback archive the log into .gz format. 据我所知,logback将日志归档为.gz格式。 You can use a bunch of command to directly take a look at those logs in .gz format. 您可以使用一堆命令直接查看.gz格式的那些日志。 For example, zcat, zgrep, you can directly use less to take a look at the gz-format log. 例如,zcat,zgrep,您可以直接使用更少的内容来查看gz格式的日志。
You could write a simple shell program to move 14 days of log from the directory to another place(This is the real archiving). 您可以编写一个简单的Shell程序,将14天的日志从目录移动到另一个位置(这是真正的归档)。 That shell only needs to run once a day by setting a cron job. 通过设置cron作业,该shell仅需要每天运行一次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.