From b1270ff5650fc41847912885e574dd7dc31e0bc8 Mon Sep 17 00:00:00 2001 From: brain Date: Thu, 2 Mar 2006 14:57:40 +0000 Subject: Added stuff to log() to make it recalculate the time using asctime() less often git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@3426 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/helperfuncs.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index 1ea214264..cf795e697 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -64,29 +64,38 @@ extern chan_hash chanlist; extern std::vector local_users; +static char TIMESTR[26]; +static time_t LAST = 0; + void log(int level,char *text, ...) { va_list argsPtr; - struct tm * timeinfo; - if (level < Config->LogLevel) + + if (level < Config->LogLevel) return; + char textbuffer[MAXBUF]; - timeinfo = localtime(&TIME); + if (TIME != LAST) + { + struct tm * timeinfo; + timeinfo = localtime(&TIME); + strlcpy(TIMESTR,asctime(timeinfo),26); + TIMESTR[24] = ':'; + LAST = TIME; + } if (Config->log_file) { - char b[26]; va_start (argsPtr, text); vsnprintf(textbuffer, MAXBUF, text, argsPtr); va_end(argsPtr); - strlcpy(b,asctime(timeinfo),26); - b[24] = ':'; // we know this is the end of the time string + if (Config->log_file) - fprintf(Config->log_file,"%s %s\n",b,textbuffer); + fprintf(Config->log_file,"%s %s\n",TIMESTR,textbuffer); if (Config->nofork) { // nofork enabled? display it on terminal too - printf("%s %s\n",b,textbuffer); + printf("%s %s\n",TIMESTR,textbuffer); } } } -- cgit v1.2.3