mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-05 05:25:49 +01:00
* upgrade to winston 3.1 * fix winston in web/install and tests
This commit is contained in:
committed by
GitHub
parent
6fb11d37ff
commit
85c60316ed
3
app.js
3
app.js
@@ -45,8 +45,9 @@ var configExists = file.existsSync(configFile) || (nconf.get('url') && nconf.get
|
||||
|
||||
var prestart = require('./src/prestart');
|
||||
prestart.loadConfig(configFile);
|
||||
prestart.versionCheck();
|
||||
prestart.setupWinston();
|
||||
prestart.versionCheck();
|
||||
winston.verbose('* using configuration stored in: %s', configFile);
|
||||
|
||||
if (!process.send) {
|
||||
// If run using `node app`, log GNU copyright info along with server info
|
||||
|
||||
@@ -111,7 +111,7 @@
|
||||
"uglify-es": "^3.3.9",
|
||||
"util.promisify": "1.0.0",
|
||||
"validator": "10.8.0",
|
||||
"winston": "^2.4.0",
|
||||
"winston": "3.1.0",
|
||||
"xml": "^1.0.1",
|
||||
"xregexp": "^4.1.1",
|
||||
"zxcvbn": "^4.4.2"
|
||||
|
||||
@@ -15,14 +15,28 @@ var Benchpress = require('benchpressjs');
|
||||
var app = express();
|
||||
var server;
|
||||
|
||||
winston.add(winston.transports.File, {
|
||||
filename: 'logs/webinstall.log',
|
||||
colorize: true,
|
||||
timestamp: function () {
|
||||
var date = new Date();
|
||||
return date.getDate() + '/' + (date.getMonth() + 1) + ' ' + date.toTimeString().substr(0, 5) + ' [' + global.process.pid + ']';
|
||||
},
|
||||
var formats = [
|
||||
winston.format.colorize(),
|
||||
];
|
||||
|
||||
const timestampFormat = winston.format((info) => {
|
||||
var dateString = new Date().toISOString() + ' [' + global.process.pid + ']';
|
||||
info.level = dateString + ' - ' + info.level;
|
||||
return info;
|
||||
});
|
||||
formats.push(timestampFormat());
|
||||
formats.push(winston.format.splat());
|
||||
formats.push(winston.format.simple());
|
||||
|
||||
winston.configure({
|
||||
level: 'verbose',
|
||||
format: winston.format.combine.apply(null, formats),
|
||||
transports: [
|
||||
new winston.transports.Console(),
|
||||
new winston.transports.File({
|
||||
filename: 'logs/webinstall.log',
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
var web = module.exports;
|
||||
@@ -42,7 +56,7 @@ var launchUrl;
|
||||
|
||||
web.install = function (port) {
|
||||
port = port || 4567;
|
||||
winston.info('Launching web installer on port', port);
|
||||
winston.info('Launching web installer on port ' + port);
|
||||
|
||||
app.use(express.static('public', {}));
|
||||
app.engine('tpl', function (filepath, options, callback) {
|
||||
|
||||
@@ -26,7 +26,9 @@ Object.defineProperty(Minifier, 'maxThreads', {
|
||||
},
|
||||
set: function (val) {
|
||||
maxThreads = val;
|
||||
if (!process.env.minifier_child) {
|
||||
winston.verbose('[minifier] utilizing a maximum of ' + maxThreads + ' additional threads');
|
||||
}
|
||||
},
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
@@ -65,7 +67,9 @@ function freeChild(proc) {
|
||||
|
||||
function removeChild(proc) {
|
||||
var i = pool.indexOf(proc);
|
||||
if (i !== -1) {
|
||||
pool.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
function forkAction(action, callback) {
|
||||
|
||||
@@ -9,23 +9,36 @@ var pkg = require('../package.json');
|
||||
var dirname = require('./cli/paths').baseDir;
|
||||
|
||||
function setupWinston() {
|
||||
winston.remove(winston.transports.Console);
|
||||
winston.add(winston.transports.Console, {
|
||||
colorize: nconf.get('log-colorize') !== 'false',
|
||||
timestamp: function () {
|
||||
var date = new Date();
|
||||
return nconf.get('json-logging') ? date.toJSON() :
|
||||
date.toISOString() + ' [' + global.process.pid + ']';
|
||||
},
|
||||
var formats = [];
|
||||
|
||||
if (nconf.get('log-colorize') !== 'false') {
|
||||
formats.push(winston.format.colorize());
|
||||
}
|
||||
|
||||
if (nconf.get('json-logging')) {
|
||||
formats.push(winston.format.timestamp());
|
||||
formats.push(winston.format.json());
|
||||
} else {
|
||||
const timestampFormat = winston.format((info) => {
|
||||
var dateString = new Date().toISOString() + ' [' + global.process.pid + ']';
|
||||
info.level = dateString + ' - ' + info.level;
|
||||
return info;
|
||||
});
|
||||
formats.push(timestampFormat());
|
||||
formats.push(winston.format.splat());
|
||||
formats.push(winston.format.simple());
|
||||
}
|
||||
|
||||
winston.configure({
|
||||
level: nconf.get('log-level') || (global.env === 'production' ? 'info' : 'verbose'),
|
||||
json: !!nconf.get('json-logging'),
|
||||
stringify: !!nconf.get('json-logging'),
|
||||
format: winston.format.combine.apply(null, formats),
|
||||
transports: [
|
||||
new winston.transports.Console(),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
function loadConfig(configFile) {
|
||||
winston.verbose('* using configuration stored in: %s', configFile);
|
||||
|
||||
nconf.file({
|
||||
file: configFile,
|
||||
});
|
||||
|
||||
@@ -182,7 +182,8 @@ describe('Build', function (done) {
|
||||
assert.ifError(err);
|
||||
var filename = path.join(__dirname, '../build/public/admin.css');
|
||||
assert(file.existsSync(filename));
|
||||
assert(fs.readFileSync(filename).toString().startsWith('@charset "UTF-8";'));
|
||||
var adminCSS = fs.readFileSync(filename).toString();
|
||||
assert(adminCSS.startsWith('@charset "UTF-8";') || adminCSS.startsWith('@import url'));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -801,7 +801,11 @@ describe('Controllers', function () {
|
||||
}, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 403);
|
||||
assert.equal(body, '{"path":"/user/doesnotexist/session/1112233","loggedIn":true,"title":"[[global:403.title]]"}');
|
||||
assert.deepEqual(JSON.parse(body), {
|
||||
path: '/user/doesnotexist/session/1112233',
|
||||
loggedIn: true,
|
||||
title: '[[global:403.title]]',
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,40 +1,37 @@
|
||||
'use strict';
|
||||
|
||||
var util = require('util');
|
||||
var winston = require('winston');
|
||||
|
||||
function DeferLogger(options) {
|
||||
options = options || {};
|
||||
|
||||
this.name = 'DeferLogger';
|
||||
this.level = options.level || 'info';
|
||||
|
||||
this.logged = options.logged;
|
||||
}
|
||||
|
||||
util.inherits(DeferLogger, winston.Transport);
|
||||
|
||||
DeferLogger.prototype.log = function log(level, msg, meta, callback) {
|
||||
this.logged.push([level, msg, meta]);
|
||||
callback(null, true);
|
||||
};
|
||||
var Transport = require('winston-transport');
|
||||
|
||||
var winstonLogged = [];
|
||||
|
||||
class DeferLogger extends Transport {
|
||||
constructor(opts) {
|
||||
super(opts);
|
||||
this.logged = opts.logged;
|
||||
}
|
||||
|
||||
log(info, callback) {
|
||||
setImmediate(() => {
|
||||
this.emit('logged', info);
|
||||
});
|
||||
|
||||
this.logged.push([info.level, info.message]);
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
before(function () {
|
||||
// defer winston logs until the end
|
||||
winston.remove(winston.transports.Console);
|
||||
winston.clear();
|
||||
|
||||
winston.add(DeferLogger, {
|
||||
logged: winstonLogged,
|
||||
});
|
||||
winston.add(new DeferLogger({ logged: winstonLogged }));
|
||||
});
|
||||
|
||||
after(function () {
|
||||
console.log('\n\n');
|
||||
|
||||
var con = new winston.transports.Console();
|
||||
winstonLogged.forEach(function (args) {
|
||||
con.log(args[0], args[1], args[2], function () {});
|
||||
console.log(args[0] + ' ' + args[1]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
var async = require('async');
|
||||
var winston = require('winston');
|
||||
var path = require('path');
|
||||
var nconf = require('nconf');
|
||||
var url = require('url');
|
||||
@@ -14,6 +13,14 @@ var errorText;
|
||||
|
||||
var packageInfo = require('../../package');
|
||||
|
||||
var winston = require('winston');
|
||||
winston.add(new winston.transports.Console({
|
||||
format: winston.format.combine(
|
||||
winston.format.splat(),
|
||||
winston.format.simple()
|
||||
),
|
||||
}));
|
||||
|
||||
nconf.file({ file: path.join(__dirname, '../../config.json') });
|
||||
nconf.defaults({
|
||||
base_dir: path.join(__dirname, '../..'),
|
||||
@@ -83,9 +90,7 @@ if (testDbConfig.database === productionDbConfig.database &&
|
||||
|
||||
nconf.set(dbType, testDbConfig);
|
||||
|
||||
winston.info('database config');
|
||||
winston.info(dbType);
|
||||
winston.info(testDbConfig);
|
||||
winston.info('database config %s', dbType, testDbConfig);
|
||||
|
||||
var db = require('../../src/database');
|
||||
module.exports = db;
|
||||
|
||||
Reference in New Issue
Block a user