Hello Peter

below a small piece of code i found somewhere.
It works but mayby you wanna fix something.

Add in httpd.conf

LogFormat "%h %v %u %t \"%r\" %>s %b \"%{Referer}i\" " combined
.....
CustomLog   "| PATH_TO_ROTATELOGSDAY YOUR_LOGFILE" combined

<snip>
/*
 * Simple program to rotate Apache logs without having to kill the server.
 *
 * Contributed by Ben Laurie <[EMAIL PROTECTED]>
 *
 * 12 Mar 1996
 */

#define BUFSIZE         65536
#define MAX_PATH        1024

#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/timeb.h>



int main (int argc, char **argv)
{
    char buf[BUFSIZE], buf2[MAX_PATH];
    int nLogFD = -1;
    int nRead;
    int LogDay=-1;
    char *szLogRoot;
 
    time_t curtime;
    struct tm *curtm;
    char curtimestr[20]; 
 
 
 
    if (argc != 2) {
        fprintf(stderr,
                "%s <logfile>\n\n",
                argv[0]);
#ifdef OS2
        fprintf(stderr,
                "Add this:\n\nTransferLog \"|%s.exe /some/where \"\n\n",
                argv[0]);
#else
        fprintf(stderr,
                "Add this:\n\nTransferLog \"|%s /some/where \"\n\n",
                argv[0]);
#endif
        fprintf(stderr,
                "to httpd.conf. \n\nThe generated name will be
/some/where.yyyymm \n"
                "where yyyymmm is the year and month. \n"
                "At the end of each month a new log is started.\n");
        exit(1);
    }

    szLogRoot = argv[1];

  for (;;) 
    {
        nRead = read(0, buf, sizeof buf);
        if (nRead == 0)
            exit(3);
        if (nRead < 0)
            if (errno != EINTR)
                exit(4);
                
        curtime=time(NULL);     
        curtm=localtime(&curtime);
  
        if (nLogFD >= 0 && (curtm->tm_mday != LogDay || nRead < 0)) {
            close(nLogFD);
            nLogFD = -1;
        }
        if (nLogFD < 0) {
          
      LogDay=curtm->tm_mday;
      sprintf(curtimestr, "%04d%02d%02d", 1900 + curtm->tm_year,
curtm->tm_mon+1, curtm->tm_mday);
      
            sprintf(buf2, "%s.%s", szLogRoot, curtimestr);
            nLogFD = open(buf2, O_WRONLY | O_CREAT | O_APPEND, 0666);
            if (nLogFD < 0) {
                perror(buf2);
                exit(2);
            }
        }
        if (write(nLogFD, buf, nRead) != nRead) {
            perror(buf2);
            exit(5);
        }
  }
}

-- 
GMX Produkte empfehlen und ganz einfach Geld verdienen!
Satte Provisionen f|r GMX Partner: http://www.gmx.net/de/go/partner

Reply via email to