]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Improve customisability of rotatelogs' behaviour. Allow the
authorKen Coar <coar@apache.org>
Tue, 13 Mar 2001 20:05:05 +0000 (20:05 +0000)
committerKen Coar <coar@apache.org>
Tue, 13 Mar 2001 20:05:05 +0000 (20:05 +0000)
logfile name to be formatted according to strftime(3), and
let the user specify an offset from UTC.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x@88510 13f79535-47bb-0310-9956-ffa450edef68

src/CHANGES
src/support/rotatelogs.8
src/support/rotatelogs.c

index 8c26c10a248f2ad9defbb77b013d17b0eff018c6..5783cc783767c62126f588a337552d82741eecea 100644 (file)
@@ -1,5 +1,8 @@
 Changes with Apache 1.3.20
 
+  *) Enhance rotatelogs so that a UTC offset can be specified, and
+     the logfile name can be formatted using strftime(3).  [Ken Coar]
+
   *) Fix a possible NULL pointer dereference in the detection of the
      default ServerName or IP string (introduced in 1.3.18).
      [Ignasi Roca, <Ignasi.Roca@fujitsu-siemens.com>]
index 6c60ca42927eb73d3903a8d43145e2bc43a41ded..0699e5c41c01e897591bae9493b3b88face6d08d 100644 (file)
@@ -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 @@ rotatelogs \- rotate Apache logs without having to kill the server
 .B rotatelogs
 .I logfile
 .I rotationtime
+.I [offset]
 .PP
 .SH DESCRIPTION
 .B rotatelogs
@@ -69,7 +70,7 @@ is a simple program for use in conjunction with Apache's piped logfile
 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 @@ the rotation time, so you can synchronize cron scripts with it).  At the end
 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 45f86f1dd47544169730273e112f9177f8f09918..ba74585a828b94fcc59ce7fcf3bba1246b1c23d3 100644 (file)
@@ -23,11 +23,15 @@ int main (int argc, char **argv)
     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 @@ int main (int argc, char **argv)
     }
 
     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) {