Skip to content

Node.js based forum software built for the modern web

more winston, issue #62

Baris Usaklidceec0ce4646
diff --git a/public/src/app.js b/public/src/app.js
index 6dfb235cd3..d166bb8104 100644
--- a/public/src/app.js
+++ b/public/src/app.js
@@ -29,10 +29,6 @@ var socket,
socket.on('event:alert', function(data) {
app.alert(data);
});
-
- socket.on('event:consolelog', function(data) {
- console.log(data);
- });
socket.on('connect', function(data){
if(reconnecting) {
diff --git a/public/templates/install/footer.tpl b/public/templates/install/footer.tpl
index e76153ecb1..9aa8ccf75e 100644
--- a/public/templates/install/footer.tpl
+++ b/public/templates/install/footer.tpl
@@ -110,7 +110,6 @@
contentEl.addEventListener('click', function(e) {
if (e.target.hasAttribute('data-path')) {
var href = 'install/' + e.target.getAttribute('data-path');
- console.log(href);
if (!e.target.disabled) ajaxify.go(href);
}
}, false);
diff --git a/src/postTools.js b/src/postTools.js
index 3c22fabd61..b66886c912 100644
--- a/src/postTools.js
+++ b/src/postTools.js
@@ -9,7 +9,8 @@ var RDB = require('./redis.js'),
plugins = require('./plugins'),
reds = require('reds'),
postSearch = reds.createSearch('nodebbpostsearch'),
- topicSearch = reds.createSearch('nodebbtopicsearch');
+ topicSearch = reds.createSearch('nodebbtopicsearch'),
+ winston = require('winston');
(function(PostTools) {
PostTools.isMain = function(pid, tid, callback) {
@@ -111,7 +112,7 @@ var RDB = require('./redis.js'),
threadTools.get_latest_undeleted_pid(postData.tid, function(err, pid) {
if (err && err.message === 'no-undeleted-pids-found') {
threadTools.delete(postData.tid, -1, function(err) {
- if (err) console.log('Error: Could not delete topic (tid: ' + postData.tid + ')');
+ if (err) winston.error('Could not delete topic (tid: ' + postData.tid + ')', err.stack);
});
} else {
posts.getPostField(pid, 'timestamp', function(timestamp) {
diff --git a/src/posts.js b/src/posts.js
index 756a59797d..77c983b891 100644
--- a/src/posts.js
+++ b/src/posts.js
@@ -11,7 +11,8 @@ var RDB = require('./redis.js'),
plugins = require('./plugins'),
reds = require('reds'),
nconf = require('nconf'),
- postSearch = reds.createSearch('nodebbpostsearch');
+ postSearch = reds.createSearch('nodebbpostsearch'),
+ winston = require('winston');
(function(Posts) {
@@ -298,7 +299,7 @@ var RDB = require('./redis.js'),
uploadPostImages(postData, images, function(err, uploadedImages) {
if(err) {
- console.log('Uploading images failed!');
+ winston.error('Uploading images failed!', err.stack);
} else {
postData.uploadedImages = JSON.stringify(uploadedImages);
Posts.setPostField(pid, 'uploadedImages', postData.uploadedImages);
diff --git a/src/redis.js b/src/redis.js
index af962ac4a9..e2d5615421 100644
--- a/src/redis.js
+++ b/src/redis.js
@@ -1,7 +1,8 @@
(function(RedisDB) {
var redis = require('redis'),
nconf = require('nconf'),
- utils = require('./../public/src/utils.js');
+ utils = require('./../public/src/utils.js'),
+ winston = require('winston');
RedisDB.exports = redis.createClient(nconf.get('redis:port'), nconf.get('redis:host'));
@@ -11,14 +12,9 @@
RedisDB.exports.handle = function(error) {
if (error !== null) {
+ winston.err(error);
if (global.env !== 'production') {
- console.log("################# ERROR LOG ####################");
- console.log(error);
- console.log(arguments.callee.name);
- console.log("################# ERROR LOG ####################");
throw new Error(error);
- } else {
- console.log(error);
}
}
}
diff --git a/src/routes/admin.js b/src/routes/admin.js
index 57efba77af..ef98bbbff0 100644
--- a/src/routes/admin.js
+++ b/src/routes/admin.js
@@ -142,7 +142,7 @@ var user = require('./../user.js'),
finalData[key] = jsonObject[key];
}
} catch(err){
- console.log('invalid redis status', i, data[i], err);
+ winston.warn('can\'t parse redis status variable, ignoring', i, data[i], err);
}
}
diff --git a/src/routes/api.js b/src/routes/api.js
index a7f2f77562..9900b51501 100644
--- a/src/routes/api.js
+++ b/src/routes/api.js
@@ -201,7 +201,7 @@ var user = require('./../user.js'),
search(topicSearch, function(err, tids) {
if(err)
return callback(err, null);
- console.log(tids);
+
topics.getTopicsByTids(tids, 0, function(topics) {
callback(null, topics);
}, 0);
diff --git a/src/routes/authentication.js b/src/routes/authentication.js
index ecdf8972fe..04fab0035f 100644
--- a/src/routes/authentication.js
+++ b/src/routes/authentication.js
@@ -7,6 +7,7 @@
login_strategies = [],
nconf = require('nconf'),
users = require('../user'),
+ winston = require('winston'),
login_module = require('./../login.js');
passport.use(new passportLocal(function(user, password, next) {
@@ -85,7 +86,7 @@
app.get('/logout', function(req, res) {
if (req.user && req.user.uid > 0) {
- console.log('info: [Auth] Session ' + req.sessionID + ' logout (uid: ' + req.user.uid + ')');
+ winston.info('[Auth] Session ' + req.sessionID + ' logout (uid: ' + req.user.uid + ')');
login_module.logout(req.sessionID, function(logout) {
req.logout();
app.build_header({ req: req, res: res }, function(err, header) {
@@ -132,7 +133,6 @@
app.get('/reset', function(req, res) {
app.build_header({ req: req, res: res }, function(err, header) {
- console.log(header);
res.send(header + templates['reset'] + templates['footer']);
});
});
diff --git a/src/routes/user.js b/src/routes/user.js
index 3a1b153c57..45b13ba0ae 100644
--- a/src/routes/user.js
+++ b/src/routes/user.js
@@ -4,7 +4,8 @@ var user = require('./../user.js'),
fs = require('fs'),
utils = require('./../../public/src/utils.js'),
path = require('path'),
- marked = require('marked');
+ marked = require('marked'),
+ winston = require('winston');
(function(User) {
User.create_routes = function(app) {
@@ -136,7 +137,7 @@ var user = require('./../user.js'),
fs.unlink(absolutePath, function(err) {
if(err) {
- console.error('[%d] %s', Date.now(), + err);
+ winston.error('[%d] %s', Date.now(), + err);
}
uploadUserPicture(req.user.uid, path.extname(req.files.userPhoto.name), req.files.userPhoto.path, res);
@@ -155,8 +156,7 @@ var user = require('./../user.js'),
var filename = uid + '-profileimg' + extension;
var uploadPath = path.join(global.configuration['ROOT_DIRECTORY'], global.nconf.get('upload_path'), filename);
- // @todo move to proper logging code - this should only be temporary
- console.log('Info: Attempting upload to: '+ uploadPath);
+ winston.info('Attempting upload to: '+ uploadPath);
var is = fs.createReadStream(tempPath);
var os = fs.createWriteStream(uploadPath);
@@ -176,11 +176,7 @@ var user = require('./../user.js'),
height: 128
}, function(err, stdout, stderr){
if (err) {
- // @todo: better logging method; for now, send to stderr.
- // ideally, this should be happening in another process
- // to avoid poisoning the main process on error or allowing a significant problem
- // to crash the main process
- console.error('[%d] %s', Date.now(), + err);
+ winston.err(err.message, err.stack);
}
res.json({ path: imageUrl });
@@ -189,7 +185,7 @@ var user = require('./../user.js'),
});
os.on('error', function(err) {
- console.error('[%d] %s', Date.now(), + err);
+ winston.error('[%d] %s', Date.now(), + err);
});
is.pipe(os);
diff --git a/src/threadTools.js b/src/threadTools.js
index 5cc4979104..1f1746d3f5 100644
--- a/src/threadTools.js
+++ b/src/threadTools.js
@@ -6,7 +6,8 @@ var RDB = require('./redis.js'),
notifications = require('./notifications.js'),
posts = require('./posts'),
reds = require('reds'),
- topicSearch = reds.createSearch('nodebbtopicsearch');
+ topicSearch = reds.createSearch('nodebbtopicsearch'),
+ winston = require('winston');
(function(ThreadTools) {
@@ -192,7 +193,7 @@ var RDB = require('./redis.js'),
categories.moveRecentReplies(tid, oldCid, cid, function(err, data) {
if(err) {
- console.log(err);
+ winston.err(err);
}
});
diff --git a/src/upgrade.js b/src/upgrade.js
index a6285af162..1b6dc494c7 100644
--- a/src/upgrade.js
+++ b/src/upgrade.js
@@ -1,6 +1,6 @@
var RDB = require('./redis.js'),
- async = require('async');
-
+ async = require('async'),
+ winston = require('winston');
function upgradeCategory(cid, callback) {
@@ -20,7 +20,6 @@ function upgradeCategory(cid, callback) {
async.each(tids, moveTopic, function(err) {
if(!err) {
- console.log('renaming ' + cid);
RDB.rename('temp_categories:' + cid + ':tid', 'categories:' + cid + ':tid');
callback(null);
}
@@ -30,7 +29,7 @@ function upgradeCategory(cid, callback) {
});
} else {
- console.log('category already upgraded '+ cid);
+ winston.info('category already upgraded '+ cid);
callback(null);
}
});
@@ -52,33 +51,37 @@ function upgradeUser(uid, callback) {
exports.upgrade = function() {
- console.log('upgrading nodebb now');
+ winston.info('upgrading nodebb now');
var schema = [
function upgradeCategories(next) {
- console.log('upgrading categories');
+ winston.info('upgrading categories');
RDB.lrange('categories:cid', 0, -1, function(err, cids) {
async.each(cids, upgradeCategory, function(err) {
- if(!err)
- next(null, 'upgraded categories');
- else
+ if(!err) {
+ winston.info('upgraded categories');
+ next(null, null);
+ } else {
next(err, null);
+ }
});
});
},
function upgradeUsers(next) {
- console.log('upgrading users');
+ winston.info('upgrading users');
RDB.lrange('userlist', 0, -1, function(err, uids) {
async.each(uids, upgradeUser, function(err) {
- if(!err)
- next(null, 'upgraded users');
- else
+ if(!err) {
+ winston.info('upgraded users')
+ next(null, null);
+ } else {
next(err, null);
+ }
});
});
@@ -87,9 +90,9 @@ exports.upgrade = function() {
async.series(schema, function(err, results) {
if(!err)
- console.log('upgrade complete');
+ winston.info('upgrade complete');
else
- console.log(err);
+ winston.err(err);
process.exit();
diff --git a/src/webserver.js b/src/webserver.js
index 9e415baa5f..4e78b4af7f 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -108,7 +108,6 @@ var express = require('express'),
// respond with html page
if (req.accepts('html')) {
-
//res.json('404', { url: req.url });
res.redirect(global.nconf.get('relative_path') + '/404');
return;
@@ -116,7 +115,6 @@ var express = require('express'),
// respond with json
if (req.accepts('json')) {
- console.log('sending 404 json');
res.send({ error: 'Not found' });
return;
}
diff --git a/src/websockets.js b/src/websockets.js
index 5e48eec84c..56afb02f82 100644
--- a/src/websockets.js
+++ b/src/websockets.js
@@ -26,7 +26,8 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
'categories': require('./admin/categories.js'),
'user': require('./admin/user.js')
},
- plugins = require('./plugins');
+ plugins = require('./plugins'),
+ winston = require('winston');
(function(io) {
var users = {},
@@ -668,7 +669,7 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
user.getUsers(data.set, start, end, function(err, data) {
if(err) {
- console.log(err);
+ winston.err(err);
} else {
callback({users:data});
}