Replace calls to console.log() with Winston.info() etc.
authorJack Allnutt <jack@allnutt.eu>
Tue, 18 Feb 2014 19:43:06 +0000 (19:43 +0000)
committerJack Allnutt <jack@allnutt.eu>
Tue, 18 Feb 2014 19:43:06 +0000 (19:43 +0000)
package.json
server/configuration.js
server/identd.js
server/irc/connection.js
server/irc/state.js
server/kiwi.js
server/weblistener.js
server_modules/control.js

index cb988a75ba4a67a31a72f63a59f6bf872e29ac1d..40003fccd3c45fbdc97d7d66eda20057f36f5610 100644 (file)
@@ -1,28 +1,31 @@
-{\r
-  "name": "kiwiirc",\r
-  "version": "0.8.2-dev",\r
-  "description": "A hand-crafted webirc client",\r
-  "homepage": "https://www.kiwiirc.com/",\r
-  "preferGlobal": "true",\r
-  "bin": { "kiwiirc": "./kiwi" },\r
-  "repository" : {\r
-        "type": "git",\r
-        "url": "https://github.com/prawnsalad/KiwiIRC.git"\r
-    },\r
-  "scripts": {\r
-    "postinstall": "node client/build.js"\r
-  },\r
-  "dependencies": {\r
-    "node-static": "0.7.3",\r
-    "uglify-js": "2.4.12",\r
-    "engine.io": "0.7.9",\r
-    "lodash": "2.4.1",\r
-    "daemonize2": "0.4.2",\r
-    "eventemitter2": "0.4.13",\r
-    "ipaddr.js": "0.1.2",\r
-    "socksjs": "0.4.4",\r
-    "iconv-lite" : "0.2.11",\r
-    "spdy": "1.19.1",\r
-    "po2json": "0.2.3"\r
-  }\r
-}\r
+{
+  "name": "kiwiirc",
+  "version": "0.8.2-dev",
+  "description": "A hand-crafted webirc client",
+  "homepage": "https://www.kiwiirc.com/",
+  "preferGlobal": "true",
+  "bin": {
+    "kiwiirc": "./kiwi"
+  },
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/prawnsalad/KiwiIRC.git"
+  },
+  "scripts": {
+    "postinstall": "node client/build.js"
+  },
+  "dependencies": {
+    "node-static": "0.7.3",
+    "uglify-js": "2.4.12",
+    "engine.io": "0.7.9",
+    "lodash": "2.4.1",
+    "daemonize2": "0.4.2",
+    "eventemitter2": "0.4.13",
+    "ipaddr.js": "0.1.2",
+    "socksjs": "0.4.4",
+    "iconv-lite": "0.2.11",
+    "spdy": "1.19.1",
+    "po2json": "0.2.3",
+    "winston": "~0.7.2"
+  }
+}
index 4f0ce0372c802de23a420832c3e70c6bc0149091..f5f73c7453c67e0312ae28017d41552ed86e236d 100644 (file)
@@ -1,7 +1,8 @@
 var fs      = require('fs'),
     events  = require('events'),
     util    = require('util'),
-    path    = require('path');
+    path    = require('path'),
+    winston = require('winston');
 
 var config_filename = 'config.js',
     config_dirs = ['/etc/kiwiirc/', __dirname + '/../'],
@@ -33,11 +34,13 @@ 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);
+                //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);
+            //console.log('Could not find config file ' + manual_config_file);
+            winston.error('Could not find config file %s', manual_config_file);
             process.exit(1);
         }
     } else {
@@ -59,7 +62,8 @@ 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);
+                    //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;
                 }
                 continue;
index 5c588e273d0b86390397e3db1681f295c20fcca0..cb6e8d578276dde56281ffaaec9f5a62a5d364aa 100644 (file)
@@ -1,4 +1,5 @@
-var net = require('net');
+var net     = require('net'),
+    winston = require('winston');
 
 var IdentdServer = module.exports = function(opts) {
 
@@ -44,7 +45,9 @@ var IdentdServer = module.exports = function(opts) {
     });
 
     server.on('listening', function() {
-        console.log('Ident Server listening on ' + server.address().address + ':' +  server.address().port);
+        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);
     });
 
 
index c0ca216c0ce0d69980b35402e9d698a912e43876..13c4d43366e88273c1df563e25614fd7f8277fd9 100644 (file)
@@ -3,6 +3,7 @@ var net             = require('net'),
     util            = require('util'),
     dns             = require('dns'),
     _               = require('lodash'),
+    winston         = require('winston'),
     EventBinder     = require('./eventbinder.js'),
     IrcServer       = require('./server.js'),
     IrcCommands     = require('./commands.js'),
@@ -752,7 +753,8 @@ function parseIrcLine(buffer_line) {
 
     if (!msg) {
         // The line was not parsed correctly, must be malformed
-        console.log("Malformed IRC line: " + line.replace(/^\r+|\r+$/, ''));
+        //console.log("Malformed IRC line: " + line.replace(/^\r+|\r+$/, ''));
+        winston.warn('Malformed IRC line: %s', line.replace(/^\r+|\r+$/, ''));
         return;
     }
 
index 7108d145b5f80cb3129bbe303119d1bf7e856ba8..083bda995da2f3825436d7fbb10e8ca9bca49998 100755 (executable)
@@ -1,6 +1,7 @@
 var util            = require('util'),
     events          = require('events'),
     _               = require('lodash'),
+    winston         = require('winston'),
     IrcConnection   = require('./connection.js').IrcConnection;
 
 var State = function (client, save_state) {
@@ -65,7 +66,8 @@ State.prototype.connect = function (hostname, port, ssl, nick, user, options, ca
     });
 
     con.on('error', function IrcConnectionError(err) {
-        console.log('irc_connection error (' + hostname + '):', err);
+        //console.log('irc_connection error (' + hostname + '):', err);
+        winston.warn('irc_connection error (%s): %s', hostname, err);
         return callback(err.message);
     });
 
index 44c267eae1cf5b7b661be6e3496048d93df5665d..8e0f29d740efb08b7f6ff02c9cb9fc3d0b80b125 100755 (executable)
@@ -1,6 +1,7 @@
 var fs          = require('fs'),
     _           = require('lodash'),
     util        = require('util'),
+    winston     = require('winston'),
     WebListener = require('./weblistener.js'),
     config      = require('./configuration.js'),
     modules     = require('./modules.js'),
@@ -35,22 +36,8 @@ if (process.argv.indexOf('-f') === -1 && global.config && global.config.log) {
             log_file_name = __dirname + '/../' + log_file_name;
         }
 
-
-
-        console.log = function() {
-            var logfile = fs.openSync(log_file_name, 'a'),
-                out;
-
-            out = util.format.apply(util, arguments);
-
-            // Make sure we out somthing to log and we have an open file
-            if (!out || !logfile) return;
-
-            out += '\n';
-            fs.writeSync(logfile, out, null);
-
-            fs.closeSync(logfile);
-        };
+        winston.add(winston.transports.File, { filename: log_file_name, json: false});
+        winston.remove(winston.transports.Console);
     })();
 }
 
@@ -58,12 +45,14 @@ 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?)');
+    //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');
+    //console.log('No servers defined in config file');
+    winston.error('No servers defined in config file');
     process.exit(2);
 }
 
@@ -80,9 +69,11 @@ 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');
+            //console.log('Module ' + module_name + ' loaded successfuly');
+            winston.info('Module %s loaded successfully', module_name);
         } else {
-            console.log('Module ' + module_name + ' failed to load');
+            //console.log('Module ' + module_name + ' failed to load');
+            winston.warn('Module %s failed to load', module_name);
         }
     });
 }
@@ -247,7 +238,8 @@ _.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'));
+            //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'));
         });
 
         serv.on('socket_connected', function(pipe) {
@@ -277,12 +269,14 @@ _.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'));
+            //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);
+            //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();
         });
@@ -321,23 +315,28 @@ 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);
+    //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');
+        //console.log('New config file loaded');
+        winston.info('New config file loaded');
     } else {
-        console.log("No new config file was loaded");
+        //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());
+    //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));
 });
 
 
index 964118b6786fb671562abb210a0d4c2d886bbc5b..0525d9c3d64576efb08ea692b665531af6baf11c 100644 (file)
@@ -1,5 +1,5 @@
 var engine       = require('engine.io'),
-    WebsocketRpc = require('./websocketrpc.js');
+    WebsocketRpc = require('./websocketrpc.js'),
     events       = require('events'),
     http         = require('http'),
     https        = require('https'),
@@ -10,6 +10,7 @@ var engine       = require('engine.io'),
     _            = require('lodash'),
     spdy         = require('spdy'),
     ipaddr       = require('ipaddr.js'),
+    winston      = require('winston'),
     Client       = require('./client.js').Client,
     HttpHandler  = require('./httphandler.js').HttpHandler,
     rehash       = require('./rehash.js');
@@ -134,7 +135,8 @@ 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);
+            //console.log('Unlisted proxy:', address);
+            winston.info('Unlisted proxy: %s', address);
             callback(null, false);
             return;
         }
index 8619be55afb52678c7b93271a2cdb72a7c9f5796..c9f8f7a942d02e84f6707df286404735e3ff5a4d 100644 (file)
@@ -7,7 +7,8 @@
 var net                = require('net'),\r
     kiwiModules        = require('../server/modules'),\r
     ControlInterface   = require('../server/controlinterface.js'),\r
-    _                  = require('lodash');\r
+    _                  = require('lodash'),\r
+    winston            = require('winston');\r
 \r
 var control_module = new kiwiModules.Module('Control');\r
 \r
@@ -22,7 +23,8 @@ function SocketClient (socket) {
     this.socket_closing = false;\r
 \r
     this.remoteAddress = this.socket.remoteAddress;\r
-    console.log('Control connection from ' + this.socket.remoteAddress + ' opened');\r
+    //console.log('Control connection from ' + this.socket.remoteAddress + ' opened');\r
+    winston.info('Control connection from %s opened', this.socket.remoteAddress);\r
 \r
     this.bindEvents();\r
 \r
@@ -53,7 +55,8 @@ SocketClient.prototype.onClose = function() {
     this.unbindEvents();\r
     this.socket = null;\r
 \r
-    console.log('Control connection from ' + this.remoteAddress + ' closed');\r
+    //console.log('Control connection from ' + this.remoteAddress + ' closed');\r
+    winston.info('Control connection from %s closed', this.remoteAddress);\r
 };\r
 \r
 \r