// 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 = [];
tags = [],
tag,
line = '',
- msg_obj;
+ msg_obj,
+ hold_last_lines;
// Decode server encoding
line = iconv.decode(buffer_line, this.encoding);
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(';');
});
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);
});