Skip to content
Snippets Groups Projects
Commit 5f89c517 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

De-duplicate repeated errors logged via sbbs_t::errormsg() by reducing severity

... from ERROR to WARNING, so the repeats won't be logged to error.log file
and won't (normally) be sent as notifications (e.g. emails) to the sysop. The
duplicates are identified as from the same source file and line number as the
immediately previous logged error within the last 12 hours. String comparison
doesn't really work for deduplication since if you look closely, the errors
usually are *not* exact duplicates (i.e. there's a node number or a socket
descriptor or something that uniquely identifies the user/client/session).
Repeated errors don't increment the node's error counter either.

This does not de-duplicate errors logged via other means (e.g. direct calls to
log()/lputs(),lprintf() with a severity of LOG_ERR or higher), but will
solve the majority of duplicate errors that can be logged from the terminal
server.

So this at least partially addresses issue #619.
parent 6000b760
No related branches found
No related tags found
No related merge requests found
Pipeline #7329 passed
......@@ -271,14 +271,19 @@ void sbbs_t::logch(char ch, bool comma)
void sbbs_t::errormsg(int line, const char* function, const char *src, const char* action, const char *object
,int access, const char *extinfo)
{
char str[2048];
char repeat[128] = "";
char errno_str[128];
char errno_info[256] = "";
static const char* lastfunc;
static int lastline;
static time_t lasttime;
static uint repeat_count;
/* prevent recursion */
if(errormsg_inside)
return;
errormsg_inside=true;
now=time(NULL);
if(errno != 0 && strcmp(action, ERR_CHK) != 0)
safe_snprintf(errno_info, sizeof(errno_info), "%d (%s) "
......@@ -291,25 +296,36 @@ void sbbs_t::errormsg(int line, const char* function, const char *src, const cha
#endif
);
safe_snprintf(str,sizeof(str),"ERROR %s"
int level = LOG_ERR;
if(function == lastfunc && line == lastline) {
++repeat_count;
snprintf(repeat, sizeof repeat, "[x%u]", repeat_count + 1);
// De-duplicate by reducing severity of log messages
if((now - lasttime) < 12*60*60)
level = LOG_WARNING;
} else
repeat_count = 0;
lastfunc = function;
lastline = line;
lasttime = now;
lprintf(level, "!ERROR%s %s"
"in %s line %u (%s) %s \"%s\" access=%d %s%s"
,repeat
,errno_info
,src, line, function, action, object, access
,extinfo==NULL ? "":"info="
,extinfo==NULL ? "":extinfo);
lprintf(LOG_ERR, "!%s", str);
if(online == ON_REMOTE) {
int savatr=curatr;
attr(cfg.color[clr_err]);
bprintf("\7\r\n!ERROR %s %s\r\n", action, object); /* tell user about error */
bprintf("\7\r\n!ERROR%s %s %s\r\n", repeat, action, object); /* tell user about error */
bputs("\r\nThe sysop has been notified.\r\n");
pause();
attr(savatr);
CRLF;
}
safe_snprintf(str,sizeof(str),"ERROR %s %s", action, object);
if(cfg.node_num>0) {
if(repeat_count == 0 && cfg.node_num>0) {
if(getnodedat(cfg.node_num,&thisnode, true)) {
if(thisnode.errors<UCHAR_MAX)
thisnode.errors++;
......@@ -317,12 +333,14 @@ void sbbs_t::errormsg(int line, const char* function, const char *src, const cha
putnodedat(cfg.node_num,&thisnode);
}
}
now=time(NULL);
if(logfile_fp!=NULL) {
if(logcol!=1)
fputs(log_line_ending, logfile_fp);
fprintf(logfile_fp,"!! %s%s", str, log_line_ending);
fprintf(logfile_fp,"%s!! ERROR%s %s %s%s"
,logcol == 1 ? "" : log_line_ending
,repeat
,action
,object
,log_line_ending);
logcol=1;
fflush(logfile_fp);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment