v1.18.x
Baris Soner Usakli 11 years ago
parent 520fcadd3f
commit aff8cef5f3

@ -32,6 +32,7 @@ var opts = {
Logger.init = function(app) { Logger.init = function(app) {
opts.express.app = app; opts.express.app = app;
console.log(meta.config);
/* Open log file stream & initialize express logging if meta.config.logger* variables are set */ /* Open log file stream & initialize express logging if meta.config.logger* variables are set */
Logger.setup(); Logger.setup();
} }
@ -65,6 +66,7 @@ var opts = {
else opts.streams.log.f = process.stdout; else opts.streams.log.f = process.stdout;
} }
else { else {
console.log('CLOSING');
Logger.close(opts.streams.log); Logger.close(opts.streams.log);
} }
} }
@ -72,18 +74,26 @@ var opts = {
Logger.open = function(value) { Logger.open = function(value) {
/* Open the streams to log to: either a path or stdout */ /* Open the streams to log to: either a path or stdout */
var stream; var stream;
if(value && fs.existsSync(value)) { if(value) {
fs.stat(value, function(err, stats) { if(fs.existsSync(value)) {
if(stats.isDirectory()) { stats = fs.statSync(value);
stream = fs.createWriteStream(path.join(value, 'nodebb.log'), {flags: 'a'}); if(stats) {
} else { if(stats.isDirectory()) {
stream = fs.createWriteStream(value, {flags: 'a'}); 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) { stream.on('error', function(err) {
winston.error(err.message); winston.error(err.message);
}); });
}); }
} else { } else {
stream = process.stdout; stream = process.stdout;
} }
@ -189,8 +199,9 @@ var opts = {
var emit = socket.emit; var emit = socket.emit;
socket.emit = function() { socket.emit = function() {
if(opts.streams.log.f != null) { 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 { try {
emit.apply(socket, arguments); emit.apply(socket, arguments);
} catch(err) { } catch(err) {

Loading…
Cancel
Save