From 1d1230544bc63c8187f0e1bca834c00e149c4887 Mon Sep 17 00:00:00 2001 From: ac-stef Date: Fri, 26 Feb 2016 11:11:58 +0100 Subject: [PATCH] speed up logging don't bother processing a line, if the level is too high for any queue --- source/src/log.cpp | 8 ++++++- source/src/protos.h | 1 + source/src/serverfiles.h | 45 +++++++++++++++++++++------------------- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/source/src/log.cpp b/source/src/log.cpp index 47b2fc9b..8fb8dc4c 100644 --- a/source/src/log.cpp +++ b/source/src/log.cpp @@ -76,13 +76,19 @@ void exitlogging() enabled = false; } +bool logcheck(int level) +{ + return enabled && level >= 0 && level < ACLOG_NUM && (consolethreshold <= level || (fp && filethreshold <= level) || syslogthreshold <= level); +} + bool logline(int level, const char *msg, ...) { if(!enabled) return false; if(level < 0 || level >= ACLOG_NUM) return false; + bool logtocon = consolethreshold <= level, logtofile = fp && filethreshold <= level, logtosyslog = syslogthreshold <= level; + if(!(logtocon || logtofile || logtosyslog)) return false; defvformatstring(sf, msg, msg); filtertext(sf, sf, FTXT__LOG); - bool logtocon = consolethreshold <= level, logtofile = fp && filethreshold <= level, logtosyslog = syslogthreshold <= level; const char *ts = timestamp ? timestring(true, "%b %d %H:%M:%S ") : "", *ld = levelprefix[level]; char *p, *l = sf; do diff --git a/source/src/protos.h b/source/src/protos.h index 83c0535c..3bbf5854 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -1109,6 +1109,7 @@ enum { ACLOG_DEBUG = 0, ACLOG_VERBOSE, ACLOG_INFO, ACLOG_WARNING, ACLOG_ERROR, A extern bool initlogging(const char *identity, int facility_, int consolethres, int filethres, int syslogthres, bool logtimestamp); extern void exitlogging(); +extern bool logcheck(int level); extern bool logline(int level, const char *msg, ...) PRINTFARGS(2, 3); // server config diff --git a/source/src/serverfiles.h b/source/src/serverfiles.h index aa3f47a8..8140eda2 100644 --- a/source/src/serverfiles.h +++ b/source/src/serverfiles.h @@ -807,7 +807,7 @@ struct serveripcclist : serverconfigfile ipranges.remove(i--); continue; } } - loopv(ipranges) logline(ACLOG_VERBOSE," %s %s", iprtoa(ipranges[i]), printcomment(ipranges[i])); + if(logcheck(ACLOG_VERBOSE)) loopv(ipranges) logline(ACLOG_VERBOSE," %s %s", iprtoa(ipranges[i]), printcomment(ipranges[i])); logline(ACLOG_INFO,"read %d (%d) IP list entries from '%s', %d errors, %d concatenated", ipranges.length(), orglength, filename, errors, concatd); } @@ -873,7 +873,7 @@ struct serveripblacklist : serverconfigfile ipranges.remove(i--); continue; } } - loopv(ipranges) logline(ACLOG_VERBOSE," %s", iprtoa(ipranges[i])); + if(logcheck(ACLOG_VERBOSE)) loopv(ipranges) logline(ACLOG_VERBOSE," %s", iprtoa(ipranges[i])); logline(ACLOG_INFO,"read %d (%d) blacklist entries from '%s', %d errors", ipranges.length(), orglength, filename, errors); } @@ -978,29 +978,32 @@ struct servernickblacklist : serverconfigfile line++; } DELETEA(buf); - logline(ACLOG_VERBOSE," nickname whitelist (%d entries):", whitelist.numelems); - string text; - enumeratekt(whitelist, const char *, key, int, idx, + if(logcheck(ACLOG_VERBOSE)) { - text[0] = '\0'; - for(int i = idx; i >= 0; i = whitelistranges[i].next) + logline(ACLOG_VERBOSE," nickname whitelist (%d entries):", whitelist.numelems); + string text; + enumeratekt(whitelist, const char *, key, int, idx, { - iprchain &ic = whitelistranges[i]; - if(ic.pwd) concatformatstring(text, " pwd:\"%s\"", hiddenpwd(ic.pwd)); - else concatformatstring(text, " %s", iprtoa(ic.ipr)); - } - logline(ACLOG_VERBOSE, " accept %s%s", key, text); - }); - logline(ACLOG_VERBOSE," nickname blacklist (%d entries):", blacklines.length()); - loopv(blacklines) - { - text[0] = '\0'; - loopj(MAXNICKFRAGMENTS) + text[0] = '\0'; + for(int i = idx; i >= 0; i = whitelistranges[i].next) + { + iprchain &ic = whitelistranges[i]; + if(ic.pwd) concatformatstring(text, " pwd:\"%s\"", hiddenpwd(ic.pwd)); + else concatformatstring(text, " %s", iprtoa(ic.ipr)); + } + logline(ACLOG_VERBOSE, " accept %s%s", key, text); + }); + logline(ACLOG_VERBOSE," nickname blacklist (%d entries):", blacklines.length()); + loopv(blacklines) { - int k = blacklines[i].frag[j]; - if(k >= 0) { concatstring(text, " "); concatstring(text, blfraglist[k]); } + text[0] = '\0'; + loopj(MAXNICKFRAGMENTS) + { + int k = blacklines[i].frag[j]; + if(k >= 0) { concatstring(text, " "); concatstring(text, blfraglist[k]); } + } + logline(ACLOG_VERBOSE, " %2d block%s%s", blacklines[i].line, blacklines[i].ignorecase ? "i" : "", text); } - logline(ACLOG_VERBOSE, " %2d block%s%s", blacklines[i].line, blacklines[i].ignorecase ? "i" : "", text); } logline(ACLOG_INFO,"read %d + %d entries from nickname blacklist file '%s', %d errors", whitelist.numelems, blacklines.length(), filename, errors); }