Return-Path: Delivered-To: apmail-apache-cvs-archive@apache.org Received: (qmail 86523 invoked by uid 500); 13 Mar 2001 20:05:15 -0000 Mailing-List: contact apache-cvs-help@apache.org; run by ezmlm Precedence: bulk Reply-To: new-httpd@apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list apache-cvs@apache.org Received: (qmail 86403 invoked by uid 500); 13 Mar 2001 20:05:10 -0000 Delivered-To: apmail-apache-1.3-cvs@apache.org Date: 13 Mar 2001 20:05:07 -0000 Message-ID: <20010313200507.86368.qmail@apache.org> From: coar@apache.org To: apache-1.3-cvs@apache.org Subject: cvs commit: apache-1.3/src/support rotatelogs.8 rotatelogs.c coar 01/03/13 12:05:06 Modified: src CHANGES src/support rotatelogs.8 rotatelogs.c Log: Improve customisability of rotatelogs' behaviour. Allow the logfile name to be formatted according to strftime(3), and let the user specify an offset from UTC. Revision Changes Path 1.1666 +3 -0 apache-1.3/src/CHANGES Index: CHANGES =================================================================== RCS file: /home/cvs/apache-1.3/src/CHANGES,v retrieving revision 1.1665 retrieving revision 1.1666 diff -u -u -r1.1665 -r1.1666 --- CHANGES 2001/03/13 10:22:14 1.1665 +++ CHANGES 2001/03/13 20:05:00 1.1666 @@ -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, ] 1.8 +11 -5 apache-1.3/src/support/rotatelogs.8 Index: rotatelogs.8 =================================================================== RCS file: /home/cvs/apache-1.3/src/support/rotatelogs.8,v retrieving revision 1.7 retrieving revision 1.8 diff -u -u -r1.7 -r1.8 --- rotatelogs.8 2001/01/15 17:06:39 1.7 +++ rotatelogs.8 2001/03/13 20:05:04 1.8 @@ -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) -. 1.16 +21 -5 apache-1.3/src/support/rotatelogs.c Index: rotatelogs.c =================================================================== RCS file: /home/cvs/apache-1.3/src/support/rotatelogs.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -u -r1.15 -r1.16 --- rotatelogs.c 2000/11/21 13:42:11 1.15 +++ rotatelogs.c 2001/03/13 20:05:05 1.16 @@ -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 \n\n", + "Usage: %s " + "[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) {