logrotate dateformat似乎不支持%H:%M:%S [英] logrotate dateformat seems not supporting %H:%M:%S
问题描述
我是新来的logrotate。当配置使用属性 dateformat时,logrotate似乎不支持strftime%H。这里是配置:
I am newer to logrotate. when the configure comes to the property "dateformat",it seems that logrotate doesn't support strftime "%H" . here is the config:
{
daily
rotate 2
size 3M
missingok
notifempty
dateext
dateformat -%Y%m%d_%H:%M:%S
...
}
旋转的文件格式通常看起来像:uwsgi_dev.log-20150630_%H:%M:%S,但是我想要确切的小时分钟和秒。
the rotated file format tend to look like : uwsgi_dev.log-20150630_%H:%M:%S, but I want the exact "hour minutes and seconds".
谢谢
推荐答案
支持在版本 3.9.0 中添加了%H。在早期版本中,logrotate不支持strftime%H:
Support for %H was added in version 3.9.0. In earlier versions, logrotate did not support strftime "%H:
dateformat format_string:使用类似于strftime()的符号指定dateext的扩展名3)函数,只允许%Y%m%d和%s指定符。
dateformat format_string: Specify the extension for dateext using the notation similar to strftime(3) function. Only %Y %m %d and %s specifiers are allowed.
来自logrotate手册页 http://linux.die.net/man/8/logrotate
From the logrotate man page http://linux.die.net/man/8/logrotate
但是,您可以在dateformat字符串中使用%s
,这是自1970-01-01起的秒数。您可以设置 dateformat-%Y%m%d-%s
。每次旋转日志时,它都会产生唯一的文件名,因此您可以每天多次旋转文件。不幸的是,%s
部分不容易阅读,但是您可以使用 perl -e print scalar(localtime(1451214849 )) 。
However, you can use %s
in the dateformat string, which is the number of seconds since 1970-01-01. You can set dateformat -%Y%m%d-%s
. This will produce unique filenames every time the log is rotated, so you can rotate the file multiple times a day. Unfortunately, the %s
part will not be easy to read, but you can easily convert it back into a readable date with perl -e "print scalar(localtime(1451214849))"
.
在某些系统上, date
程序允许这样做转换只需 date -d @ 1451214849
即可(例如GNU date
)。在大多数系统上(包括Solaris date
),您可能会碰巧使用 date -d 1970-01-01 + 1451214849 sec
。请注意,Busybox date
仅支持 @
技巧,但不支持第二个示例的复杂表达式。
On some systems, the date
program allows to do such conversion easily with date -d @1451214849
(e.g. GNU date
). On most systems (including e.g. Solaris date
), you may have luck with syntax like date -d "1970-01-01 + 1451214849 sec"
. Note that Busybox date
supports only the @
trick but not complex expressions of the second example.
这篇关于logrotate dateformat似乎不支持%H:%M:%S的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!