Sfoglia il codice sorgente

* Added syslog style repeated log detection for all logging.

svn: 2270
Bryan Drewery 21 anni fa
parent
commit
6d6b326e21
2 ha cambiato i file con 26 aggiunte e 0 eliminazioni
  1. 1 0
      doc/UPDATES
  2. 25 0
      src/log.c

+ 1 - 0
doc/UPDATES

@@ -28,6 +28,7 @@ Lines prefixed with '-' were disabled before release and are not finished, or ar
 * Added irc.ptptech.com/efnet.port80.se to default servers/servers6, added irc.pte.hu, irc.efnet.fr to servers.
 * Fixed a segfault/cpulock with mode parsing. (#25)
 * Fixed an issue with bot respdoning to TCM CTCP VERSIONS too slowly at times on connect. (#128)
+* Added syslog style repeated log detection for all logging.
 
 1.2.4
 * Fixed cmd_botset not displaying botnick.

+ 25 - 0
src/log.c

@@ -194,6 +194,12 @@ void logfile(int type, const char *msg)
  * putlog(level,channel_name,format,...);
  * Broadcast the log if chname is not '@'
  */
+char last_log[201] = "";
+int log_repeats = 0;
+char last_chname[25] = "";
+int last_type;
+bool log_repeated;
+
 void putlog(int type, const char *chname, const char *format, ...)
 {
   char va_out[LOGLINEMAX + 1] = "";
@@ -208,6 +214,25 @@ void putlog(int type, const char *chname, const char *format, ...)
     return;
   }
 
+  if (!log_repeated) {
+    if (type == last_type && 
+        !egg_strncasecmp(chname, last_chname, sizeof(last_chname)) && 
+        !egg_strncasecmp(va_out, last_log, sizeof(last_log))) {
+      log_repeats++;
+
+      return;
+    }
+    if (log_repeats) {
+      log_repeated = 1;
+      putlog(type, last_chname, "Last message repeated %d times.\n", log_repeats);
+      log_repeats = 0;
+    }
+    strlcpy(last_log, va_out, sizeof(last_log));
+    last_type = type;
+    strlcpy(last_chname, chname, sizeof(last_chname));
+  } else
+    log_repeated = 0;
+
   char *p = NULL;
 
   if ((p = strchr(va_out, '\n')))		/* make sure no trailing newline */