开发者

Log Rotation with Date Appended to Filename

Originally I thought log rotation would be easy with the perl's module Logfile:Rotate, but now the requirement changed to appending the date to the filename of the log file.开发者_如何学JAVA

I need to:

  1. Append the filename rotated (daily) with date.
  2. Zip the log files older than 10 days.
  3. Delete log files older than 30 days.
  4. Logs to be rotated in a directory (i.e. ../logs)

I tried Python's logging.handlers.TimedRotatingFileHandler, but it creates new empty log files on cron execution. I think it's meant for a process that's continuous and not per interval cron execution.

I'm open to any programming (scripting) language for easy log rotation. Anyone got better ideas?

Not meant to ask for code. Just suggestions.


logrotate utility on most of *nix distros available today support following options of your interest:

 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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜