2

I want to make a new logs for my website every 00:00:01 (= each new day).

The problem with rotatelogs is that you can either precise the max size of the logs before creating a new one, or precise the rotation time in seconds. It's not possible to precise an hour of rotation.

They talk about "cronjobs", but I don't get it. Could someone please explain if it's possible, and if so, give an example?

Thank you very much

Following is the help of the rotatelogs utility:

/ # /opt/httpd/bin/rotatelogs --help Incorrect number of arguments Usage: /opt/httpd/bin/rotatelogs [-l] [-f] {|} [offset minutes from UTC]

Add this:

TransferLog "|/opt/httpd/bin/rotatelogs /some/where 86400"

or

TransferLog "|/opt/httpd/bin/rotatelogs /some/where 5M"

to httpd.conf. The generated name will be /some/where.nnnn where nnnn is the system time at which the log nominally starts (N.B. if using a rotation time, the time will always be a multiple of the rotation time, so you can synchronize cron scripts with it). At the end of each rotation time or when the file size is reached a new log is started. / #

1 Answers1

1

According to this section of the manual page for rotatelogs:

   rotationtime
          The time between log file rotations  in  seconds.  The  rotation
          occurs  at  the  beginning of this interval. For example, if the
          rotation time is 3600, the log  file  will  be  rotated  at  the
          beginning  of every hour; if the rotation time is 86400, the log
          file will be rotated every night at midnight.

setting 86400 as the period will do what you want (new file started at midnight every day).

Also use the -l option if you want "midnight" to be in your local timezone rather than UTC.

The case when a cronjob would be needed is if you wanted a period of one day but at a different time than midnight. More general tools like logrotate (outside apache) are typically used for that.

Daniel Vérité
  • 58,074
  • 15
  • 129
  • 156
  • From my point of view, if you precise `3600` and you start at `18:30` the next log should start at `19:30`. What I don't get is this: **`at the beginning of this interval`**. And the examples they give are not helping: `86400` and `3600`... what if you precise `3660` or `86401`?? –  Mar 22 '12 at 08:12
  • I think the start time of server doesn't play any role. If given 3600 as the rotationtime, the server will divide the unix epoch (number of seconds since 1/1/70 00:00) by 3600 and switch to a new logfile when the remainder of this division is zero (which happens at the beginning of every hour). If given 3660, it would happen every 70mn since 1/1/70 00:00 – Daniel Vérité Mar 22 '12 at 13:42
  • 1
    If what you say is right (which is probably the case), then the documentation is bad. I'll take a look, write some test cases, then make an article explaining this on my blog. Thanks a lot for your answer! **`=)`** –  Mar 23 '12 at 08:59
  • @user292916 I was wondering the same thing. Did you ever get around to writing that blog post? – Johannes Fahrenkrug Apr 24 '12 at 11:42