Explorar o código

log rotation re-implemented

z3APA3A %!s(int64=5) %!d(string=hai) anos
pai
achega
ee8cdbc85b
Modificáronse 2 ficheiros con 9 adicións e 4 borrados
  1. 8 4
      src/log.c
  2. 1 0
      src/proxy.h

+ 8 - 4
src/log.c

@@ -123,6 +123,12 @@ static void delayflushlogs(void){
 	struct LOGGER *log;
 	for(log = loggers; log; log=log->next){
 		if(log->logfunc && log->logfunc->flush)log->logfunc->flush(log);
+#ifndef WITHMAIN
+		if(log->rotate && log->logfunc && log->logfunc->rotate && timechanged(log->rotated, conf.time, log->rotate)){
+			log->logfunc->rotate(log);
+			log->rotated = conf.time;
+		}
+#endif
 	}
 }
 
@@ -145,6 +151,7 @@ void delayregisterlog(struct LOGGER *log){
 		if(!strncmp(log->selector, funcs->prefix, strlen(funcs->prefix))){
 			if(funcs->init && funcs->init(log)) break;
 			log->logfunc = funcs;
+			log->rotated = conf.time;
 			return;
 		}
 	}
@@ -495,10 +502,7 @@ unsigned char * dologname (unsigned char *buf,  int bufsize, unsigned char *name
 
 	ts = localtime(&t);
 	if(strchr((char *)name, '%')){
-		struct clientparam fakecli;
-
-		memset(&fakecli, 0, sizeof(fakecli));
-		dobuf2(&fakecli, buf, bufsize - strlen(ext), NULL, NULL, ts, (char *)name);
+		dobuf2(&logparam, buf, bufsize - (ext?strlen(ext):0), NULL, NULL, ts, (char *)name);
 	}
 	else switch(lt){
 		case NONE:

+ 1 - 0
src/proxy.h

@@ -197,6 +197,7 @@ void clearstat(struct clientparam * param);
 void dumpcounters(struct trafcount *tl, int counterd);
 int startconnlims (struct clientparam *param);
 void stopconnlims (struct clientparam *param);
+int timechanged (time_t oldtime, time_t newtime, ROTATION lt);