2011-03-07 60 views
2

最初我以为perl的模块logfile:Rotate很容易实现日志轮转,但是现在需求已经改变为将日期附加到日志文件的文件名。带日期的日志循环附加到文件名

我需要:

  1. 追加与日期(每日)旋转的文件名。
  2. 压缩日期超过10天的日志文件。
  3. 删除超过30天的日志文件。
  4. 日志在一个目录(即../logs)

旋转我试着Python的logging.handlers.TimedRotatingFileHandler,但它的cron执行创建新的空日志文件。我认为这意味着一个连续的过程,而不是每间隔cron执行。

我接受任何编程(脚本)语言,以方便日志旋转。 任何人有更好的想法?

不打算要求代码。只是建议。下面您感兴趣的选项上大多数* nix发行版的当今支持

回答

5

logrotate实用程序:

compress 
      Old versions of log files are compressed with gzip by default. See also nocompress. 

dateext 
      Archive old versions of log files adding a daily extension like YYYYMMDD instead of simply adding a number. 

olddir directory 
      Logs are moved into directory for rotation. The directory must be on the same physical device as the log file being 
      rotated, and is assumed to be relative to the directory holding the log file unless an absolute path name is speci- 
      fied. When this option is used all old versions of the log end up in directory. This option may be overriden by 
      the noolddir option. 

notifempty 
      Do not rotate the log if it is empty (this overrides the ifempty option). 

postrotate/endscript 
      The lines between postrotate and endscript (both of which must appear on lines by themselves) are executed after 
      the log file is rotated. These directives may only appear inside of a log file definition. See prerotate as well. 
+0

啊...是的,我也注意到了。所以如果服务器是我客户的服务器,我应该问他们的系统管理员来配置它吗? – LynxLee 2011-03-07 05:50:45

+0

是的,我认为这是要走的路。使用logrotate提供的功能要比编写代码实现相同效果要好得多。 – anubhava 2011-03-07 14:20:04

+0

好的,非常感谢。 – LynxLee 2011-03-08 03:25:52

相关问题