log rotation re-implemented

This commit is contained in:
z3APA3A 2020-10-30 12:39:37 +03:00
parent f219544d6a
commit ee8cdbc85b
2 changed files with 9 additions and 4 deletions

View File

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

View File

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