httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject cvs commit: httpd-2.0/support rotatelogs.c
Date Tue, 13 Mar 2001 21:25:29 GMT
coar        01/03/13 13:25:29

  Modified:    .        CHANGES
               docs/man rotatelogs.8
               support  rotatelogs.c
  Log:
  	Enhance customisability of rotatelogs: strftime(3)
  	formatting of filename and offset from UTC.
  
  Reviewed by:	Greg Stein, David Reid, OtherBill
  
  Revision  Changes    Path
  1.130     +5 -0      httpd-2.0/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/CHANGES,v
  retrieving revision 1.129
  retrieving revision 1.130
  diff -u -u -r1.129 -r1.130
  --- CHANGES	2001/03/12 17:29:02	1.129
  +++ CHANGES	2001/03/13 21:25:22	1.130
  @@ -1,4 +1,9 @@
   Changes with Apache 2.0.15-dev
  +
  +  *) Enhance rotatelogs so that a UTC offset can be specified, and
  +     the logfile name can be formatted using strftime(3).  (Brought
  +     forward from 1.3.)  [Ken Coar]
  +
     *) Reimplement the Windows MPM (mpm_winnt.c) to eliminate calling 
        DuplicateHandle on an IOCompletionPort (a practice which
        MS "discourages"). The new model does not rely on associating
  
  
  
  1.5       +11 -5     httpd-2.0/docs/man/rotatelogs.8
  
  Index: rotatelogs.8
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/docs/man/rotatelogs.8,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -u -r1.4 -r1.5
  --- rotatelogs.8	2001/02/16 04:26:28	1.4
  +++ rotatelogs.8	2001/03/13 21:25:26	1.5
  @@ -1,4 +1,4 @@
  -.TH rotatelogs 8 "March 1998"
  +.TH rotatelogs 8 "March 2001"
   .\" The Apache Software License, Version 1.1
   .\"
   .\" Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
  @@ -56,6 +56,7 @@
   .B rotatelogs
   .I logfile
   .I rotationtime
  +.I [offset]
   .PP
   .SH DESCRIPTION
   .B rotatelogs
  @@ -63,7 +64,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
  @@ -72,11 +73,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.14      +21 -5     httpd-2.0/support/rotatelogs.c
  
  Index: rotatelogs.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/support/rotatelogs.c,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -u -r1.13 -r1.14
  --- rotatelogs.c	2001/02/16 04:26:53	1.13
  +++ rotatelogs.c	2001/03/13 21:25:28	1.14
  @@ -90,11 +90,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,
  @@ -115,26 +119,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) {
  
  
  

Mime
View raw message