Here is an enhancement for rotatelogs.  Two enhancements, actually;
one enables another argument for specifying an offset from UTC,
and the other causes filenames that include '%' to be treated
as strftime(3) format strings (so the name does not have to
be a human-opaque ten-digit number).

I will commit these to both 1.3 and 2.0 if no-one objects within
a couple of days..

Index: rotatelogs.8
===================================================================
RCS file: /home/cvs/apache-1.3/src/support/rotatelogs.8,v
retrieving revision 1.7
diff -u -r1.7 rotatelogs.8
--- rotatelogs.8        2001/01/15 17:06:39     1.7
+++ rotatelogs.8        2001/03/13 17:11:57
@@ -1,4 +1,4 @@
-.TH rotatelogs 8 "March 1998"
+.TH rotatelogs 8 "March 2001"
 .\" ====================================================================
 .\" The Apache Software License, Version 1.1
 .\"
@@ -62,6 +62,7 @@
 .B rotatelogs
 .I logfile
 .I rotationtime
+.I [offset]
 .PP
 .SH DESCRIPTION
 .B rotatelogs
@@ -69,7 +70,7 @@
 feature which can be used like this:
 
 .fi
-   TransferLog "|rotatelogs /path/to/logs/access_log 86400"
+   TransferLog "| rotatelogs /path/to/logs/access_log 86400"
 .mf
 
 This creates the files /path/to/logs/access_log.nnnn where nnnn is the system
@@ -78,11 +79,16 @@
 of each rotation time (here after 24 hours) a new log is started.
 .SH OPTIONS
 .IP \fB\fIlogfile\fP
-The path plus basename of the logfile. The suffix .nnnn is automatically
-added.
+The path plus basename of the logfile.  If \fBlogfile\fP includes any
+'%' characters, it is treated as a format string for \fIstrftime(3)\fP.
+Otherwise, the suffix .nnnn is automatically added and is the time at which
+the logfile was created.
 .IP \fB\fIrotationtime\fP
 The rotation time in seconds.
+.IP \fB\fIoffset\fP
+The number of minutes offset from UTC.  If omitted, zero is assumed and
+UTC is used.  For example, to use local time in the zone UTC -5 hours,
+specify a value of \fI-300\fP for this argument.
 .PD
 .SH SEE ALSO
 .BR httpd(8)
-.
Index: rotatelogs.c
===================================================================
RCS file: /home/cvs/apache-1.3/src/support/rotatelogs.c,v
retrieving revision 1.15
diff -u -r1.15 rotatelogs.c
--- rotatelogs.c        2000/11/21 13:42:11     1.15
+++ rotatelogs.c        2001/03/13 17:11:57
@@ -23,11 +23,15 @@
     char buf[BUFSIZE], buf2[MAX_PATH], errbuf[ERRMSGSZ];
     time_t tLogEnd = 0, tRotation;
     int nLogFD = -1, nLogFDprev = -1, nMessCount = 0, nRead, nWrite;
+    int utc_offset = 0;
+    int use_strftime = 0;
+    time_t now;
     char *szLogRoot;
 
-    if (argc != 3) {
+    if (argc < 3) {
         fprintf(stderr,
-                "%s <logfile> <rotation time in seconds>\n\n",
+                "Usage: %s <logfile> <rotation time in seconds> "
+                "[offset minutes from UTC]\n\n",
                 argv[0]);
 #ifdef OS2
         fprintf(stderr,
@@ -48,26 +52,38 @@
     }
 
     szLogRoot = argv[1];
+    if (argc >= 4) {
+        utc_offset = atoi(argv[3]) * 60;
+    }
     tRotation = atoi(argv[2]);
     if (tRotation <= 0) {
         fprintf(stderr, "Rotation time must be > 0\n");
         exit(6);
     }
 
+    use_strftime = (strstr(szLogRoot, "%") != NULL);
     for (;;) {
         nRead = read(0, buf, sizeof buf);
+        now = time(NULL) + utc_offset;
         if (nRead == 0)
             exit(3);
         if (nRead < 0)
             if (errno != EINTR)
                 exit(4);
-        if (nLogFD >= 0 && (time(NULL) >= tLogEnd || nRead < 0)) {
+        if (nLogFD >= 0 && (now >= tLogEnd || nRead < 0)) {
             nLogFDprev = nLogFD;
             nLogFD = -1;
         }
         if (nLogFD < 0) {
-            time_t tLogStart = (time(NULL) / tRotation) * tRotation;
-            sprintf(buf2, "%s.%010d", szLogRoot, (int) tLogStart);
+            time_t tLogStart = (now / tRotation) * tRotation;
+            if (use_strftime) {
+                struct tm *tm_now;
+                tm_now = gmtime(&tLogStart);
+                strftime(buf2, sizeof(buf2), szLogRoot, tm_now);
+            }
+            else {
+                sprintf(buf2, "%s.%010d", szLogRoot, (int) tLogStart);
+            }
             tLogEnd = tLogStart + tRotation;
             nLogFD = open(buf2, O_WRONLY | O_CREAT | O_APPEND, 0666);
             if (nLogFD < 0) {

-- 
#ken    P-)}

Ken Coar                    <http://Golux.Com/coar/>
Apache Software Foundation  <http://www.apache.org/>
"Apache Server for Dummies" <http://Apache-Server.Com/>
"Apache Server Unleashed"   <http://ApacheUnleashed.Com/>

ApacheCon 2001!
Four tracks with over 70+ sessions. Free admission to exhibits
and special events - keynote presentations by John 'maddog' Hall
and David Brin. Special thanks to our Platinum Sponsors IBM and
Covalent, Gold Sponsor Thawte, and Silver Sponsor Compaq.  Attend
the only Apache event designed and fully supported by the members of
the ASF. See more information and register at <http://ApacheCon.Com/>!

Reply via email to