From: Darren Date: Wed, 27 Aug 2014 19:46:28 +0000 (+0100) Subject: Keep hold of X lines from IRCd for connection error context X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=e1e1cb331937eb5b882b128e5ddacaa2d38674f0;p=KiwiIRC.git Keep hold of X lines from IRCd for connection error context --- diff --git a/server/irc/connection.js b/server/irc/connection.js index 6267725..c275feb 100644 --- a/server/irc/connection.js +++ b/server/irc/connection.js @@ -46,6 +46,9 @@ var IrcConnection = function (hostname, port, ssl, nick, user, options, state, c // Number of times we have tried to reconnect this.reconnect_attempts = 0; + // Last few lines from the IRCd for context when disconnected (server errors, etc) + this.last_few_lines = []; + // IRCd write buffers (flood controll) this.write_buffer = []; @@ -846,7 +849,8 @@ function parseIrcLine(buffer_line) { tags = [], tag, line = '', - msg_obj; + msg_obj, + hold_last_lines; // Decode server encoding line = iconv.decode(buffer_line, this.encoding); @@ -863,6 +867,18 @@ function parseIrcLine(buffer_line) { return; } + // If enabled, keep hold of the last X lines + if (global.config.hold_ircd_lines) { + this.last_few_lines.push(line.replace(/^\r+|\r+$/, '')); + + // Trim the array down if it's getting to long. (max 3 by default) + hold_last_lines = parseInt(global.config.hold_ircd_lines, 10) || 3; + + if (this.last_few_lines.length > hold_last_lines) { + this.last_few_lines = this.last_few_lines.slice(this.last_few_lines.length - hold_last_lines); + } + } + // Extract any tags (msg[1]) if (msg[1]) { tags = msg[1].split(';'); diff --git a/server/irc/state.js b/server/irc/state.js index 9ae2df0..32e7cfc 100755 --- a/server/irc/state.js +++ b/server/irc/state.js @@ -66,7 +66,14 @@ State.prototype.connect = function (hostname, port, ssl, nick, user, options, ca }); con.on('error', function IrcConnectionError(err) { - winston.warn('irc_connection error (%s):', hostname, err); + var context = ''; + + // If we have any of the last lines stored, include them in the log for context + if (con.last_few_lines.length > 0) { + context = '\n' + con.last_few_lines.join('\n') + '\n'; + } + + winston.warn('irc_connection error (%s):' + context, hostname, err); return callback(err.message); });