From aff8cef5f3c8ac89f91d6138f6fc769e2a788bc9 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Thu, 2 Jan 2014 15:59:25 -0500 Subject: [PATCH] closes #717 --- src/logger.js | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/logger.js b/src/logger.js index 6ee2775255..4b63817f20 100644 --- a/src/logger.js +++ b/src/logger.js @@ -32,6 +32,7 @@ var opts = { Logger.init = function(app) { opts.express.app = app; + console.log(meta.config); /* Open log file stream & initialize express logging if meta.config.logger* variables are set */ Logger.setup(); } @@ -65,6 +66,7 @@ var opts = { else opts.streams.log.f = process.stdout; } else { + console.log('CLOSING'); Logger.close(opts.streams.log); } } @@ -72,18 +74,26 @@ var opts = { Logger.open = function(value) { /* Open the streams to log to: either a path or stdout */ var stream; - if(value && fs.existsSync(value)) { - fs.stat(value, function(err, stats) { - if(stats.isDirectory()) { - stream = fs.createWriteStream(path.join(value, 'nodebb.log'), {flags: 'a'}); - } else { - stream = fs.createWriteStream(value, {flags: 'a'}); + if(value) { + if(fs.existsSync(value)) { + stats = fs.statSync(value); + if(stats) { + if(stats.isDirectory()) { + stream = fs.createWriteStream(path.join(value, 'nodebb.log'), {flags: 'a'}); + } else { + stream = fs.createWriteStream(value, {flags: 'a'}); + } } + } else { + stream = fs.createWriteStream(value, {flags: 'a'}); + + } + + if(stream) { stream.on('error', function(err) { winston.error(err.message); }); - }); - + } } else { stream = process.stdout; } @@ -189,8 +199,9 @@ var opts = { var emit = socket.emit; socket.emit = function() { if(opts.streams.log.f != null) { - opts.streams.log.f.write(Logger.prepare_io_string("emit",uid,arguments)); + opts.streams.log.f.write(Logger.prepare_io_string("emit", uid, arguments)); } + try { emit.apply(socket, arguments); } catch(err) {