Scripting 文件名后附加日期的日志循环

Scripting 文件名后附加日期的日志循环,scripting,rotation,logging,Scripting,Rotation,Logging,最初我认为使用perl的模块Logfile:Rotate可以轻松地进行日志旋转,但现在要求更改为在日志文件的文件名中添加日期 我需要: 附加文件名(每日)和日期 压缩超过10天的日志文件 删除超过30天的日志文件 要在目录中旋转的日志(即.../日志) 我尝试了Python,但它会在cron执行时创建新的空日志文件。我认为这是为了一个连续的进程,而不是按时间间隔执行cron 我对任何编程(脚本)语言都持开放态度,以便于日志循环。 有人有更好的主意吗 不是为了要代码。只是建议。目前大多数*nix发

最初我认为使用perl的模块Logfile:Rotate可以轻松地进行日志旋转,但现在要求更改为在日志文件的文件名中添加日期

我需要:

  • 附加文件名(每日)和日期
  • 压缩超过10天的日志文件
  • 删除超过30天的日志文件
  • 要在目录中旋转的日志(即.../日志)
  • 我尝试了Python,但它会在cron执行时创建新的空日志文件。我认为这是为了一个连续的进程,而不是按时间间隔执行cron

    我对任何编程(脚本)语言都持开放态度,以便于日志循环。 有人有更好的主意吗

    不是为了要代码。只是建议。

    目前大多数*nix发行版上的实用程序都支持以下您感兴趣的选项:

     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.
    

    啊。。是的,我也注意到了。因此,如果服务器是我客户的服务器,我是否应该要求他们的系统管理员进行配置?是的,我认为这是正确的做法。使用logrotate提供的特性比编写代码来实现相同的功能要好得多。