summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-03-02 14:57:40 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-03-02 14:57:40 +0000
commitb1270ff5650fc41847912885e574dd7dc31e0bc8 (patch)
treec08ea25558da099da3b03cfa4f2a38072ab8db17 /src
parentaf0f219afc4099a6cc0b8b7f2d96786f0baf6b21 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/helperfuncs.cpp25
1 files 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<userrec*> 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);
}
}
}