Forráskód Böngészése

Merge branch '129-logging' into next

* 129-logging:
  Add set 'logging' to log to .l-botnick files
  Show forwarded message timestamps
  Add set 'logfile-flags'
  Remove stupid syntax
Bryan Drewery 6 éve
szülő
commit
88a7213219
8 módosított fájl, 38 hozzáadás és 33 törlés
  1. 1 0
      doc/UPDATES.md
  2. 2 0
      doc/help.txt
  3. 2 7
      src/botmsg.cc
  4. 11 19
      src/log.cc
  5. 2 1
      src/log.h
  6. 18 4
      src/set.cc
  7. 1 1
      src/set.h
  8. 1 1
      src/tandem.h

+ 1 - 0
doc/UPDATES.md

@@ -17,6 +17,7 @@
   * Tweak server connect burst to progress quicker.
   * Sort cmd_groups and cmd_bots better.
   * cmd_groups: Indicate which bots are down with a _*_.
+  * Logs now include timestamps for forwarded messages.
 
 # maint
   * Clear FiSH keys when a client quits.

+ 2 - 0
doc/help.txt

@@ -1735,6 +1735,8 @@ See also: reload, backup
 [N]  $bmsgrate$b             How often (msecs) to dequeue msgs to the server. Only used on
                          non-ratbox servers. Too small a value can result in Excess Flood.
 [L]  $bgroups$b              List of groups that the affected bots are a part of.
+[S]  $blogfile-flags$b       Logfile modes. See '%dhelp console'.
+[B]  $blogging$b             Log to .l-botnick files.
 [L]  $brbl-servers$b         Servers to use for RBL checking in channels that are +rbl.
  
 [S]  $brealname$b            The bot's "real name" when connecting. (supports '$n' expansion)

+ 2 - 7
src/botmsg.cc

@@ -330,14 +330,9 @@ void putbot(const char *bot, const char *par)
 	 - sends to uplink if a leaf
 	 - sends to all linked hubs if a hub
 */
-void botnet_send_log(int idx, const char *from, int type, const char *msg, bool truncate_ts)
+void botnet_send_log(int idx, const char *from, int type, const char *msg)
 {
-  size_t len;
-  // Cut out timestamp
-  if (truncate_ts)
-    len = simple_snprintf(OBUF, sizeof(OBUF), "lo %s %d %s\n", from, type, &msg[LOG_TS_LEN + 1]); //+1 due to excess space
-  else
-    len = simple_snprintf(OBUF, sizeof(OBUF), "lo %s %d %s\n", from, type, msg);
+  const size_t len = simple_snprintf(OBUF, sizeof(OBUF), "lo %s %d %s\n", from, type, msg);
 
   if (conf.bot->hub) {
     send_hubs_but(idx, OBUF, len);

+ 11 - 19
src/log.cc

@@ -49,6 +49,7 @@
 #include <unistd.h>
 
 int	conmask = LOG_MODES | LOG_CMDS | LOG_MISC; /* Console mask */
+int	logfile_masks = 0;      /* Defaults from 'logfile-flags' */
 bool	debug_output = 1;      /* Disply output to server to LOG_SERVEROUT */
 
 typedef struct {
@@ -156,8 +157,6 @@ void logidx(int idx, const char *format, ...)
     dprintf(idx, "%s\n", va_out);
 }
 
-#ifdef DEBUG
-/* CURRENTLY SPAWNS TONS OF FILES */
 FILE *log_f;
 bool flush_log = 1;
 bool init_log_exit = 0;
@@ -179,7 +178,7 @@ void logfile_close(void)
 
 bool logfile_open()
 {
-  if (!conf.bot || !conf.bot->nick) return 0;
+  if (!conf.bot || !conf.bot->nick || !logging) return 0;
 
   char filename[20] = "";
   simple_snprintf(filename, sizeof(filename), ".l-%s", conf.bot->nick);
@@ -241,7 +240,6 @@ void logfile(int type, const char *msg)
   if (flush_log)
     fflush(log_f);
 }
-#endif
 
 /* Log something
  * putlog(level,channel_name,format,...);
@@ -294,31 +292,25 @@ void putlog(int type, const char *chname, const char *format, ...)
   int idx = 0;
   char out[LOGLINEMAX + 1] = "";
 
-  if (conf.bot && conf.bot->hub) {
-    char stamp[34] = "";
+  /* Prepend timestamp into out.  */
+  {
+    char stamp[100];
     time_t synced = now + timesync;
     struct tm *t = gmtime(&synced);
 
     strftime(stamp, sizeof(stamp), LOG_TS, t);
     /* Place the timestamp in the string to be printed */
-    strlcpy(out, stamp, sizeof(out));
-    strlcat(out, " ", sizeof(out));
-    strlcat(out, va_out, sizeof(out));
-  } else
-    strlcpy(out, va_out, sizeof(out));
+    simple_snprintf(out, sizeof(out), "%s %s", stamp, va_out);
+  }
 
   /* strcat(out, "\n"); */
 
-#ifdef DEBUG
-  /* FIXME: WRITE LOG HERE */
-  int logfile_masks = LOG_ALL;
-
-  if ((logfile_masks && (logfile_masks & type)) || 1)
+  if (logfile_masks & type)
     logfile(type, out);
-#endif
+
   /* broadcast to hubs */
   if (chname[0] == '*' && conf.bot && conf.bot->nick)
-    botnet_send_log(-1, conf.bot->nick, type, out, (conf.bot->hub ? 1 : 0));
+    botnet_send_log(-1, conf.bot->nick, type, out);
 
   for (idx = 0; idx < dcc_total; idx++) {
     if (dcc[idx].type && (dcc[idx].type == &DCC_CHAT && dcc[idx].simul == -1) && (dcc[idx].u.chat->con_flags & type)) {
@@ -330,7 +322,7 @@ void putlog(int type, const char *chname, const char *format, ...)
 
   if ((!backgrd) && (!term_z)) {
     dprintf(DP_STDOUT, "%s\n", out);
-  } else if ((type & LOG_ERRORS || type & LOG_MISC) && use_stderr) {
+  } else if ((type & (LOG_ERRORS|LOG_MISC)) && use_stderr) {
     dprintf(DP_STDERR, "%s\n", va_out);
   }
 }

+ 2 - 1
src/log.h

@@ -39,8 +39,9 @@ void irc_log(struct chanset_t *, const char *, ...) __attribute__((format(printf
 #define irc_log(...) do {} while (0)
 #endif
 void logfile(int type, const char *msg);
+void logfile_close(void);
 
-extern int		conmask;
+extern int		conmask, logfile_masks;
 extern bool		debug_output;
 
 #endif /* !_LOG_H */

+ 18 - 4
src/set.cc

@@ -54,6 +54,15 @@ int ison_time = 10;
 int kill_threshold;
 int lag_threshold;
 int login;
+bool logging;
+static char logfile_flags_str[100] = "";
+#ifdef DEBUG
+#define LOGFILE_FLAGS_DFL "*"
+#define LOGGING_DFL "1"
+#else
+#define LOGFILE_FLAGS_DFL "mcobeuw"
+#define LOGGING_DFL "0"
+#endif
 /* Number of seconds to wait between transmitting queued lines to the server
  * lower this value at your own risk.  ircd is known to start flood control
  * at 512 bytes/2 seconds.
@@ -110,6 +119,8 @@ static variable_t vars[] = {
  VAR("kill-threshold",	&kill_threshold,	VAR_INT|VAR_NOLOC,				0, 0, "0"),
  VAR("lag-threshold",	&lag_threshold,		VAR_INT|VAR_NOLHUB,				0, 0, "15"),
  VAR("link_cleartext",	&link_cleartext,	VAR_INT|VAR_NOLOC|VAR_BOOL,			0, 1, "0"),
+ VAR("logfile-flags",	logfile_flags_str,	VAR_STRING,					0, 0, LOGFILE_FLAGS_DFL),
+ VAR("logging",		&logging,	VAR_INT|VAR_BOOL,					0, 1, LOGGING_DFL),
  VAR("login",		&login,			VAR_INT|VAR_DETECTED,				0, 4, "warn"),
  VAR("manop-warn",	&manop_warn,		VAR_INT|VAR_BOOL|VAR_NOLHUB,			0, 1, "1"),
  VAR("motd",		motd,			VAR_STRING|VAR_HIDE|VAR_NOLOC,			0, 0, NULL),
@@ -416,15 +427,18 @@ sdprintf("var (mem): %s -> %s", var->name, datain ? datain : "(NULL)");
     sdprintf("server-use-ssl changed, reprocessing server list");
     variable_t *servers = var_get_var_by_name(get_server_type());
     var_set_mem(servers, servers->ldata ? servers->ldata : servers->gdata);
-  }
-
-  // Check if should part/join channels based on groups changing
-  if (!conf.bot->hub && !strcmp(var->name, "groups")) {
+  } else if (!conf.bot->hub && !strcmp(var->name, "groups")) {
+    // Check if should part/join channels based on groups changing
     if (server_online && !restarting && !loading && !reset_chans) {
       for (struct chanset_t* chan = chanset; chan; chan = chan->next) {
         check_shouldjoin(chan);
       }
     }
+  } else if (!strcmp(var->name, "logfile-flags")) {
+    logfile_masks = logmodes(logfile_flags_str);
+  } else if (!strcmp(var->name, "logging")) {
+    if (!logging)
+      logfile_close();
   }
 
   free(datap);

+ 1 - 1
src/set.h

@@ -70,7 +70,7 @@ typedef struct rate_b {
 extern char		auth_key[], auth_prefix[2], motd[], alias[], rbl_servers[1024], groups[1024],
 			msgident[], msginvite[], msgop[], msgpass[], msgrelease[],
                         homechan[], altchars[];
-extern bool		dccauth, auth_obscure, manop_warn, auth_chan, oidentd, ident_botnick, irc_autoaway, link_cleartext, use_deaf, use_callerid, fish_auto_keyx, fish_paranoid;
+extern bool		dccauth, auth_obscure, manop_warn, auth_chan, oidentd, ident_botnick, irc_autoaway, link_cleartext, use_deaf, use_callerid, fish_auto_keyx, fish_paranoid, logging;
 extern int		cloak_script, fight_threshold, in_bots, set_noshare, dcc_autoaway,
 			kill_threshold, lag_threshold, op_bots, hijack, login, promisc, trace,
                         ison_time, msgrate, msgburst, server_cycle_wait, wait_split;

+ 1 - 1
src/tandem.h

@@ -61,7 +61,7 @@ void botnet_send_link(int, const char *, const char *, const char *);
 void botnet_send_update(int, tand_t *);
 void botnet_send_nlinked(int, const char *, const char *, const char, int, time_t, const char *, const char *, int);
 void botnet_send_reject(int, const char *, const char *, const char *, const char *, const char *);
-void botnet_send_log(int, const char *, int, const char *, bool = 0);
+void botnet_send_log(int, const char *, int, const char *);
 void botnet_send_zapf(int, const char *, const char *, const char *);
 void botnet_send_zapf_broad(int, const char *, const char *, const char *);
 void botnet_send_away(int, const char *, int, const char *, int);