added winston, added wrapper for winston.error until they fix it, issue #62

v1.18.x
Baris Usakli 12 years ago
parent 1d81f43249
commit 6e17ff7981

@ -17,6 +17,7 @@
*/
var fs = require('fs'),
winston = require('winston'),
nconf = require('nconf'),
pkg = require('./package.json'),
url = require('url');
@ -27,11 +28,26 @@ global.env = process.env.NODE_ENV || 'production',
// Configuration setup
nconf.argv().file({ file: __dirname + '/config.json'});
winston.remove(winston.transports.Console);
winston.add(winston.transports.Console, {
colorize:true
});
winston.add(winston.transports.File, {
filename:'error.log',
level:'error'
})
// TODO: remove once https://github.com/flatiron/winston/issues/280 is fixed
winston.err = function(err) {
winston.error(err.stack);
};
// Log GNU copyright info along with server info
console.log('Info: NodeBB v' + pkg.version + ' Copyright (C) 2013 DesignCreatePlay Inc.');
console.log('Info: This program comes with ABSOLUTELY NO WARRANTY.');
console.log('Info: This is free software, and you are welcome to redistribute it under certain conditions.');
console.log('Info: ===');
winston.info('NodeBB v' + pkg.version + ' Copyright (C) 2013 DesignCreatePlay Inc.');
winston.info('This program comes with ABSOLUTELY NO WARRANTY.');
winston.info('This is free software, and you are welcome to redistribute it under certain conditions.');
winston.info('===');
if(nconf.get('upgrade')) {
require('./src/upgrade').upgrade();
@ -40,8 +56,8 @@ if(nconf.get('upgrade')) {
nconf.set('upload_url', nconf.get('url') + 'uploads/');
global.nconf = nconf;
console.log('Info: Initializing NodeBB v' + pkg.version + ', on port ' + nconf.get('port') + ', using Redis store at ' + nconf.get('redis:host') + ':' + nconf.get('redis:port') + '.');
console.log('Info: Base Configuration OK.');
winston.info('Initializing NodeBB v' + pkg.version + ', on port ' + nconf.get('port') + ', using Redis store at ' + nconf.get('redis:host') + ':' + nconf.get('redis:port') + '.');
winston.info('Base Configuration OK.');
// TODO: Replace this with nconf-redis
var meta = require('./src/meta.js');
@ -83,10 +99,10 @@ if(nconf.get('upgrade')) {
//setup scripts to be moved outside of the app in future.
function setup_categories() {
console.log('Info: Checking categories...');
winston.info('Checking categories...');
categories.getAllCategories(function(data) {
if (data.categories.length === 0) {
console.log('Info: Setting up default categories...');
winston.info('Setting up default categories...');
fs.readFile(config.ROOT_DIRECTORY + '/install/data/categories.json', function(err, default_categories) {
default_categories = JSON.parse(default_categories);
@ -97,26 +113,24 @@ if(nconf.get('upgrade')) {
});
console.log('Info: Hardcoding uid 1 as an admin');
winston.info('Hardcoding uid 1 as an admin');
var user = require('./src/user.js');
user.makeAdministrator(1);
} else {
console.log('Info: Categories OK. Found ' + data.categories.length + ' categories.');
winston.info('Categories OK. Found ' + data.categories.length + ' categories.');
}
});
}
setup_categories();
}(global.configuration));
});
} else {
// New install, ask setup questions
if (nconf.get('setup')) console.log('Info: NodeBB Setup Triggered via Command Line');
else console.log('Info: Configuration not found, starting NodeBB setup');
if (nconf.get('setup')) winston.info('NodeBB Setup Triggered via Command Line');
else winston.info('Configuration not found, starting NodeBB setup');
var install = require('./src/install');
@ -128,7 +142,7 @@ if(nconf.get('upgrade')) {
install.setup(function(err) {
if (err) {
console.log('Error: There was a problem completing NodeBB setup: ', err.message);
winston.error('There was a problem completing NodeBB setup: ', err.message);
} else {
if (!nconf.get('setup')) {
process.stdout.write(

@ -33,7 +33,8 @@
"sitemap": "~0.6.0",
"cheerio": "~0.12.0",
"request": "~2.25.0",
"reds": "~0.2.4"
"reds": "~0.2.4",
"winston": "~0.7.2"
},
"bugs": {
"url": "https://github.com/designcreateplay/NodeBB/issues"

@ -3,7 +3,8 @@ var RDB = require('./redis.js'),
utils = require('./../public/src/utils.js'),
user = require('./user.js'),
async = require('async'),
topics = require('./topics.js');
topics = require('./topics.js'),
winston = require('winston');
(function(Categories) {
@ -187,8 +188,9 @@ var RDB = require('./redis.js'),
Categories.getRecentReplies = function(cid, count, callback) {
RDB.zrevrange('categories:recent_posts:cid:' + cid, 0, (count<10)?10:count, function(err, pids) {
if(err) {
console.log(err);
winston.err(err);
callback([]);
return;
}
@ -222,12 +224,12 @@ var RDB = require('./redis.js'),
if(!err) {
callback(null, 1)
} else {
console.log(err);
winston.err(err);
callback(err, null);
}
});
} else {
console.log(err);
winston.err(err);
callback(err, null);
}
});
@ -249,7 +251,7 @@ var RDB = require('./redis.js'),
if(err === null)
callback(data);
else
console.log(err);
winston.err(err);
});
}
@ -288,7 +290,7 @@ var RDB = require('./redis.js'),
async.eachSeries(cids, getCategory, function(err) {
if(err) {
console.log(err);
winston.err(err);
callback(null);
return;
}

@ -2,12 +2,13 @@ var fs = require('fs'),
path = require('path'),
RDB = require('./redis.js'),
async = require('async'),
winston = require('winston'),
plugins = {
libraries: [],
loadedHooks: {},
init: function() {
if (this.initialized) return;
if (global.env === 'development') console.log('Info: [plugins] Initializing plugins system');
if (global.env === 'development') winston.info('[plugins] Initializing plugins system');
var _self = this;
@ -32,12 +33,12 @@ var fs = require('fs'),
_self.registerHook(pluginData.id, pluginData.hooks[x]);
}
}
if (global.env === 'development') console.log('Info: [plugins] Loaded plugin: ' + pluginData.id);
if (global.env === 'development') winston.info('[plugins] Loaded plugin: ' + pluginData.id);
next();
});
} else {
if (global.env === 'development') console.log('Info: [plugins] Plugin \'' + plugin + '\' not found');
if (global.env === 'development') winston.info('[plugins] Plugin \'' + plugin + '\' not found');
next(); // Ignore this plugin silently
}
})
@ -45,11 +46,11 @@ var fs = require('fs'),
}
], function(err) {
if (err) {
if (global.env === 'development') console.log('Info: [plugins] NodeBB encountered a problem while loading plugins', err.message);
if (global.env === 'development') winston.info('[plugins] NodeBB encountered a problem while loading plugins', err.message);
return;
}
if (global.env === 'development') console.log('Info: [plugins] Plugins OK');
if (global.env === 'development') winston.info('[plugins] Plugins OK');
});
},
initialized: false,
@ -66,7 +67,7 @@ var fs = require('fs'),
if (data.hook && data.method) {
_self.loadedHooks[data.hook] = _self.loadedHooks[data.hook] || [];
_self.loadedHooks[data.hook].push([id, data.method]);
if (global.env === 'development') console.log('Info: [plugins] Hook registered: ' + data.hook + ' will call ' + id);
if (global.env === 'development') winston.info('[plugins] Hook registered: ' + data.hook + ' will call ' + id);
} else return;
},
fireHook: function(hook, args, callback) {
@ -75,7 +76,7 @@ var fs = require('fs'),
hookList = this.loadedHooks[hook];
if (hookList && Array.isArray(hookList)) {
if (global.env === 'development') console.log('Info: [plugins] Firing hook: \'' + hook + '\'');
if (global.env === 'development') winston.info('[plugins] Firing hook: \'' + hook + '\'');
var hookType = hook.split(':')[0];
switch(hookType) {
case 'filter':
@ -94,7 +95,7 @@ var fs = require('fs'),
}
}, function(err) {
if (err) {
if (global.env === 'development') console.log('Info: [plugins] Problem executing hook: ' + hook);
if (global.env === 'development') winston.info('[plugins] Problem executing hook: ' + hook);
}
callback(returnVal);
@ -109,7 +110,7 @@ var fs = require('fs'),
) {
_self.libraries[hookObj[0]][hookObj[1]].apply(_self.libraries[hookObj[0]], args);
} else {
if (global.env === 'development') console.log('Info: [plugins] Expected method \'' + hookObj[1] + '\' in plugin \'' + hookObj[0] + '\' not found, skipping.');
if (global.env === 'development') winston.info('[plugins] Expected method \'' + hookObj[1] + '\' in plugin \'' + hookObj[0] + '\' not found, skipping.');
}
});
break;
@ -129,13 +130,13 @@ var fs = require('fs'),
toggleActive: function(id, callback) {
this.isActive(id, function(err, active) {
if (err) {
if (global.env === 'development') console.log('Info: [plugins] Could not toggle active state on plugin \'' + id + '\'');
if (global.env === 'development') winston.info('[plugins] Could not toggle active state on plugin \'' + id + '\'');
return;
}
RDB[(active ? 'srem' : 'sadd')]('plugins:active', id, function(err, success) {
if (err) {
if (global.env === 'development') console.log('Info: [plugins] Could not toggle active state on plugin \'' + id + '\'');
if (global.env === 'development') winston.info('[plugins] Could not toggle active state on plugin \'' + id + '\'');
return;
}

Loading…
Cancel
Save