From 61428716eec6acb344cc9ca40e4c26095a78d37f Mon Sep 17 00:00:00 2001 From: Darren Date: Fri, 28 Mar 2014 16:57:46 +0000 Subject: [PATCH] Finalising winston logging; Logging timestamp format; --- server/configuration.js | 5 +---- server/identd.js | 3 +-- server/irc/connection.js | 1 - server/irc/state.js | 9 ++++----- server/kiwi.js | 39 +++++++++++++++++++++++++-------------- server/weblistener.js | 1 - server_modules/control.js | 2 -- 7 files changed, 31 insertions(+), 29 deletions(-) diff --git a/server/configuration.js b/server/configuration.js index f5f73c7..12959c6 100644 --- a/server/configuration.js +++ b/server/configuration.js @@ -34,12 +34,10 @@ Config.prototype.loadConfig = function (manual_config_file) { this.manual_config_file = manual_config_file; } } catch (e) { - //console.log('An error occured parsing the config file ' + manual_config_file + ': ' + e.message); winston.error('An error occured parsing the config file %s: %s', manual_config_file, e.message); process.exit(1); } } else { - //console.log('Could not find config file ' + manual_config_file); winston.error('Could not find config file %s', manual_config_file); process.exit(1); } @@ -62,7 +60,6 @@ Config.prototype.loadConfig = function (manual_config_file) { case 'ENOENT': // No file/dir break; default: - //console.log('An error occured parsing the config file ' + config_dirs[i] + config_filename + ': ' + e.message); winston.warn('An error occured parsing the config file %s%s: %s', config_dirs[i], config_filename, e.message); return false; } @@ -90,7 +87,7 @@ Config.prototype.setEnvironment = function (new_environment) { // Get the current config. Optionally for a different environment than currently set Config.prototype.get = function (specific_environment) { specific_environment = specific_environment || environment; - + return loaded_config[specific_environment] || {}; }; diff --git a/server/identd.js b/server/identd.js index cb6e8d5..692bbc9 100644 --- a/server/identd.js +++ b/server/identd.js @@ -46,7 +46,6 @@ var IdentdServer = module.exports = function(opts) { server.on('listening', function() { var addr = server.address(); - //console.log('Ident Server listening on ' + server.address().address + ':' + server.address().port); winston.info('Ident Server listening on %s:%s', addr.address, addr.port); }); @@ -62,7 +61,7 @@ var IdentdServer = module.exports = function(opts) { /** * Process a line of data for an Identd response - * + * * @param {String} The line of data to process * @return {String} Data to send back to the Identd client */ diff --git a/server/irc/connection.js b/server/irc/connection.js index b764a1b..cea63de 100644 --- a/server/irc/connection.js +++ b/server/irc/connection.js @@ -756,7 +756,6 @@ function parseIrcLine(buffer_line) { if (!msg) { // The line was not parsed correctly, must be malformed - //console.log("Malformed IRC line: " + line.replace(/^\r+|\r+$/, '')); winston.warn('Malformed IRC line: %s', line.replace(/^\r+|\r+$/, '')); return; } diff --git a/server/irc/state.js b/server/irc/state.js index 083bda9..375f63d 100755 --- a/server/irc/state.js +++ b/server/irc/state.js @@ -10,10 +10,10 @@ var State = function (client, save_state) { events.EventEmitter.call(this); this.client = client; this.save_state = save_state || false; - + this.irc_connections = []; this.next_connection = 0; - + this.client.on('dispose', function () { if (!that.save_state) { _.each(that.irc_connections, function (irc_connection, i, cons) { @@ -23,7 +23,7 @@ var State = function (client, save_state) { cons[i] = null; } }); - + that.dispose(); } }); @@ -66,8 +66,7 @@ State.prototype.connect = function (hostname, port, ssl, nick, user, options, ca }); con.on('error', function IrcConnectionError(err) { - //console.log('irc_connection error (' + hostname + '):', err); - winston.warn('irc_connection error (%s): %s', hostname, err); + winston.warn('irc_connection error (%s):', hostname, err); return callback(err.message); }); diff --git a/server/kiwi.js b/server/kiwi.js index 8e0f29d..68dcf62 100755 --- a/server/kiwi.js +++ b/server/kiwi.js @@ -36,7 +36,31 @@ if (process.argv.indexOf('-f') === -1 && global.config && global.config.log) { log_file_name = __dirname + '/../' + log_file_name; } - winston.add(winston.transports.File, { filename: log_file_name, json: false}); + winston.add(winston.transports.File, { + filename: log_file_name, + json: false, + timestamp: function() { + var year, month, day, time_string, + d = new Date(); + + year = String(d.getFullYear()); + month = String(d.getMonth() + 1); + if (month.length === 1) { + month = "0" + month; + } + + day = String(d.getDate()); + if (day.length === 1) { + day = "0" + day; + } + + // Take the time from the existing toTimeString() format + time_string = (new Date()).toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"); + + return year + "-" + month + "-" + day + ' ' + time_string; + } + }); + winston.remove(winston.transports.Console); })(); } @@ -45,13 +69,11 @@ if (process.argv.indexOf('-f') === -1 && global.config && global.config.log) { // Make sure we have a valid config file and at least 1 server if (!global.config || Object.keys(global.config).length === 0) { - //console.log('Couldn\'t find a valid config.js file (Did you copy the config.example.js file yet?)'); winston.error('Couldn\'t find a valid config.js file (Did you copy the config.example.js file yet?)'); process.exit(1); } if ((!global.config.servers) || (global.config.servers.length < 1)) { - //console.log('No servers defined in config file'); winston.error('No servers defined in config file'); process.exit(2); } @@ -69,10 +91,8 @@ modules.registerPublisher(global.modules); if (global.config.module_dir) { (global.config.modules || []).forEach(function (module_name) { if (modules.load(module_name)) { - //console.log('Module ' + module_name + ' loaded successfuly'); winston.info('Module %s loaded successfully', module_name); } else { - //console.log('Module ' + module_name + ' failed to load'); winston.warn('Module %s failed to load', module_name); } }); @@ -238,7 +258,6 @@ _.each(global.config.servers, function (server) { serv.listen(server.port, server.address, server); serv.on('listening', function() { - //console.log('Kiwi proxy listening on %s:%s %s SSL', server.address, server.port, (server.ssl ? 'with' : 'without')); winston.info('Kiwi proxy listening on %s:%s %s SSL', server.address, server.port, (server.ssl ? 'with' : 'without')); }); @@ -269,13 +288,11 @@ _.each(global.config.servers, function (server) { }); wl.on('listening', function () { - //console.log('Listening on %s:%s %s SSL', server.address, server.port, (server.ssl ? 'with' : 'without')); winston.info('Listening on %s:%s %s SSL', server.address, server.port, (server.ssl ? 'with' : 'without')); webListenerRunning(); }); wl.on('error', function (err) { - //console.log('Error listening on %s:%s: %s', server.address, server.port, err.code); winston.info('Error listening on %s:%s: %s', server.address, server.port, err.code); // TODO: This should probably be refactored. ^JA webListenerRunning(); @@ -315,26 +332,20 @@ function setProcessUid() { // Make sure Kiwi doesn't simply quit on an exception process.on('uncaughtException', function (e) { - //console.log('[Uncaught exception] ' + e); - //console.log(e.stack); winston.error('[Uncaught exception] %s', e, {stack: e.stack}); }); process.on('SIGUSR1', function() { if (config.loadConfig()) { - //console.log('New config file loaded'); winston.info('New config file loaded'); } else { - //console.log("No new config file was loaded"); winston.info('No new config file was loaded'); } }); process.on('SIGUSR2', function() { - //console.log('Connected clients: ' + _.size(global.clients.clients).toString()); - //console.log('Num. remote hosts: ' + _.size(global.clients.addresses).toString()); winston.info('Connected clients: %s', _.size(global.clients.clients)); winston.info('Num. remote hosts: %s', _.size(global.clients.addresses)); }); diff --git a/server/weblistener.js b/server/weblistener.js index 0525d9c..7727ca4 100644 --- a/server/weblistener.js +++ b/server/weblistener.js @@ -135,7 +135,6 @@ function initialiseSocket(socket, callback) { if (request.headers[global.config.http_proxy_ip_header || 'x-forwarded-for']) { // Check we're connecting from a whitelisted proxy if (!global.config.http_proxies || !rangeCheck(address, global.config.http_proxies)) { - //console.log('Unlisted proxy:', address); winston.info('Unlisted proxy: %s', address); callback(null, false); return; diff --git a/server_modules/control.js b/server_modules/control.js index c9f8f7a..c1e5517 100644 --- a/server_modules/control.js +++ b/server_modules/control.js @@ -23,7 +23,6 @@ function SocketClient (socket) { this.socket_closing = false; this.remoteAddress = this.socket.remoteAddress; - //console.log('Control connection from ' + this.socket.remoteAddress + ' opened'); winston.info('Control connection from %s opened', this.socket.remoteAddress); this.bindEvents(); @@ -55,7 +54,6 @@ SocketClient.prototype.onClose = function() { this.unbindEvents(); this.socket = null; - //console.log('Control connection from ' + this.remoteAddress + ' closed'); winston.info('Control connection from %s closed', this.remoteAddress); }; -- 2.25.1