From b8cafefce225a7e0fb2881881ac88f1a8206f5ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 26 Nov 2020 13:56:34 -0500 Subject: [PATCH] fix: winston usages --- app.js | 2 ++ src/analytics.js | 2 +- src/cli/reset.js | 2 +- src/controllers/admin/dashboard.js | 2 +- src/database/redis.js | 2 +- src/database/redis/connection.js | 2 +- src/flags.js | 2 +- src/notifications.js | 2 +- src/prestart.js | 14 ++++++++++++++ src/webserver.js | 2 +- 10 files changed, 24 insertions(+), 8 deletions(-) diff --git a/app.js b/app.js index 1c7e5017d5..d9d92f545d 100644 --- a/app.js +++ b/app.js @@ -45,6 +45,8 @@ prestart.setupWinston(); prestart.versionCheck(); winston.verbose('* using configuration stored in: %s', configFile); +winston.error('oppps we faled', new Error('yah')); + if (!process.send) { // If run using `node app`, log GNU copyright info along with server info winston.info('NodeBB v' + nconf.get('version') + ' Copyright (C) 2013-' + (new Date()).getFullYear() + ' NodeBB Inc.'); diff --git a/src/analytics.js b/src/analytics.js index d1ec60af2d..1fe00f9803 100644 --- a/src/analytics.js +++ b/src/analytics.js @@ -139,7 +139,7 @@ Analytics.writeData = async function () { try { await Promise.all(dbQueue); } catch (err) { - winston.error('[analytics] Encountered error while writing analytics to data store', err.stack); + winston.error('[analytics] Encountered error while writing analytics to data store\n' + err.stack); throw err; } }; diff --git a/src/cli/reset.js b/src/cli/reset.js index 9edbfee8e7..a7822ba2c1 100644 --- a/src/cli/reset.js +++ b/src/cli/reset.js @@ -133,7 +133,7 @@ async function resetPlugin(pluginId) { winston.info('[reset] No action taken.'); } } catch (err) { - winston.error('[reset] Could not disable plugin: ' + pluginId + ' encountered error %s', err.stack); + winston.error('[reset] Could not disable plugin: ' + pluginId + ' encountered error %s\n' + err.stack); throw err; } } diff --git a/src/controllers/admin/dashboard.js b/src/controllers/admin/dashboard.js index cef8c8921a..49e34db80a 100644 --- a/src/controllers/admin/dashboard.js +++ b/src/controllers/admin/dashboard.js @@ -69,7 +69,7 @@ async function getLatestVersion() { try { return await versions.getLatestVersion(); } catch (err) { - winston.error('[acp] Failed to fetch latest version', err.stack); + winston.error('[acp] Failed to fetch latest version\n' + err.stack); } return null; } diff --git a/src/database/redis.js b/src/database/redis.js index 7de6efd5b4..b0fd76f284 100644 --- a/src/database/redis.js +++ b/src/database/redis.js @@ -40,7 +40,7 @@ redisModule.init = function (callback) { callback = callback || function () { }; redisModule.client = connection.connect(nconf.get('redis'), function (err) { if (err) { - winston.error('NodeBB could not connect to your Redis database. Redis returned the following error', err.stack); + winston.error('NodeBB could not connect to your Redis database. Redis returned the following error\n' + err.stack); return callback(err); } require('./redis/promisify')(redisModule.client); diff --git a/src/database/redis/connection.js b/src/database/redis/connection.js index b291b1f284..b79c154f63 100644 --- a/src/database/redis/connection.js +++ b/src/database/redis/connection.js @@ -58,7 +58,7 @@ connection.connect = function (options, callback) { if (dbIdx >= 0) { cxn.select(dbIdx, function (err) { if (err) { - winston.error('NodeBB could not select Redis database. Redis returned the following error', err.stack); + winston.error('NodeBB could not select Redis database. Redis returned the following error\n' + err.stack); throw err; } }); diff --git a/src/flags.js b/src/flags.js index 8c716765b2..ae954d1607 100644 --- a/src/flags.js +++ b/src/flags.js @@ -79,7 +79,7 @@ Flags.init = async function () { const data = await plugins.hooks.fire('filter:flags.getFilters', hookData); Flags._filters = data.filters; } catch (err) { - winston.error('[flags/init] Could not retrieve filters', err.stack); + winston.error('[flags/init] Could not retrieve filters\n' + err.stack); Flags._filters = {}; } }; diff --git a/src/notifications.js b/src/notifications.js index f4f526c6d5..11d3ac05c8 100644 --- a/src/notifications.js +++ b/src/notifications.js @@ -333,7 +333,7 @@ Notifications.prune = async function () { }, { batch: 500, interval: 100 }); } catch (err) { if (err) { - winston.error('Encountered error pruning notifications', err.stack); + winston.error('Encountered error pruning notifications\n' + err.stack); } } }; diff --git a/src/prestart.js b/src/prestart.js index ed61e28c16..a46e7d3299 100644 --- a/src/prestart.js +++ b/src/prestart.js @@ -13,6 +13,20 @@ function setupWinston() { return; } + // allow winton.error to log error objects properly + // https://github.com/NodeBB/NodeBB/issues/6848 + // const winstonError = winston.error; + // winston.error = function (msg, error) { + // if (msg instanceof Error) { + // winstonError(msg); + // } else if (error instanceof Error) { + // msg = msg + '\n' + error.stack; + // winstonError(msg); + // } else { + // winstonError.apply(null, arguments); + // } + // }; + var formats = []; if (nconf.get('log-colorize') !== 'false') { formats.push(winston.format.colorize()); diff --git a/src/webserver.js b/src/webserver.js index 4a6898f9a0..827baa5cc4 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -278,7 +278,7 @@ function listen(callback) { oldUmask = process.umask('0000'); module.exports.testSocket(socketPath, function (err) { if (err) { - winston.error('[startup] NodeBB was unable to secure domain socket access (' + socketPath + ')', err.stack); + winston.error('[startup] NodeBB was unable to secure domain socket access (' + socketPath + ')\n' + err.stack); throw err; }