/var/log/
(Debian/Ubuntu)上的日志存储为
x.log
x.log.1
x.log.2.gz
...
Run Code Online (Sandbox Code Playgroud)
如内核日志、系统日志等。
我看到随着日志信息的增加,它们通过拆分成更小的文件来存储(而不是将所有文件都保存在一个文件中)。我想知道为什么第二个文件 ( x.log.1
) 没有被压缩?是否与更容易访问最近的日志有关?
小智 13
我同意您的看法,这只会让您更轻松地访问最近的文件。无论如何,实际行为是通过 logrotatedelaycompress
指令决定的,它说:
不要在旋转时压缩文件,而是在下次压缩它
历史原因可以在logrotate手册中找到:
Postpone compression of the previous log file to the next rotation
cycle. This has only effect when used in combination with compress.
It can be used when some program can not be told to close its logfile and
thus might continue writing to the previous log file for some time.
Run Code Online (Sandbox Code Playgroud)
是的,这样做是为了更容易访问最近的日志文件。logrotate 选项delaycompress
控制这一点。从 logrotate 联机帮助页:
延迟压缩
Run Code Online (Sandbox Code Playgroud)Postpone compression of the previous log file to the next rotation cycle. This only has effect when used in combination with compress. It can be used when some program cannot be told to close its logfile and thus might continue writing to the previous log file for some time.