From 0fe0306caa49c9b07bc3b377d72056c33cae2c7a Mon Sep 17 00:00:00 2001 From: John Crepezzi Date: Fri, 18 Nov 2011 17:26:25 -0500 Subject: [PATCH] Logger configuration --- config.js | 10 +++++++++- server.js | 16 +++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/config.js b/config.js index 6b2c436..7ccdd64 100644 --- a/config.js +++ b/config.js @@ -3,6 +3,14 @@ "host": "localhost", "port": 7777, - "keyLength": 6 + "keyLength": 6, + + "logging": [ + { + "level": "verbose", + "type": "Console", + "colorize": true + } + ] } diff --git a/server.js b/server.js index e8e0348..08a03f6 100644 --- a/server.js +++ b/server.js @@ -12,9 +12,19 @@ var config = JSON.parse(fs.readFileSync('config.js', 'utf8')); config.port = config.port || 7777; config.host = config.host || 'localhost'; -// Configure logging - TODO make configurable -winston.remove(winston.transports.Console); -winston.add(winston.transports.Console, { colorize: true, level: 'verbose' }); +// Set up the logger +if (config.logging) { + try { + winston.remove(winston.transports.Console); + } catch(er) { } + var detail, type; + for (var i = 0; i < config.logging.length; i++) { + detail = config.logging[i]; + type = detail.type; + delete detail.type; + winston.add(winston.transports[type], detail); + } +} // TODO preparse static instead of using exists // TODO implement command line