mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-09 15:35:47 +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');
|
var prestart = require('./src/prestart');
|
||||||
prestart.loadConfig(configFile);
|
prestart.loadConfig(configFile);
|
||||||
prestart.versionCheck();
|
|
||||||
prestart.setupWinston();
|
prestart.setupWinston();
|
||||||
|
prestart.versionCheck();
|
||||||
|
winston.verbose('* using configuration stored in: %s', configFile);
|
||||||
|
|
||||||
if (!process.send) {
|
if (!process.send) {
|
||||||
// If run using `node app`, log GNU copyright info along with server info
|
// If run using `node app`, log GNU copyright info along with server info
|
||||||
|
|||||||
@@ -111,7 +111,7 @@
|
|||||||
"uglify-es": "^3.3.9",
|
"uglify-es": "^3.3.9",
|
||||||
"util.promisify": "1.0.0",
|
"util.promisify": "1.0.0",
|
||||||
"validator": "10.8.0",
|
"validator": "10.8.0",
|
||||||
"winston": "^2.4.0",
|
"winston": "3.1.0",
|
||||||
"xml": "^1.0.1",
|
"xml": "^1.0.1",
|
||||||
"xregexp": "^4.1.1",
|
"xregexp": "^4.1.1",
|
||||||
"zxcvbn": "^4.4.2"
|
"zxcvbn": "^4.4.2"
|
||||||
|
|||||||
@@ -15,14 +15,28 @@ var Benchpress = require('benchpressjs');
|
|||||||
var app = express();
|
var app = express();
|
||||||
var server;
|
var server;
|
||||||
|
|
||||||
winston.add(winston.transports.File, {
|
var formats = [
|
||||||
filename: 'logs/webinstall.log',
|
winston.format.colorize(),
|
||||||
colorize: true,
|
];
|
||||||
timestamp: function () {
|
|
||||||
var date = new Date();
|
const timestampFormat = winston.format((info) => {
|
||||||
return date.getDate() + '/' + (date.getMonth() + 1) + ' ' + date.toTimeString().substr(0, 5) + ' [' + global.process.pid + ']';
|
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',
|
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;
|
var web = module.exports;
|
||||||
@@ -42,7 +56,7 @@ var launchUrl;
|
|||||||
|
|
||||||
web.install = function (port) {
|
web.install = function (port) {
|
||||||
port = port || 4567;
|
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.use(express.static('public', {}));
|
||||||
app.engine('tpl', function (filepath, options, callback) {
|
app.engine('tpl', function (filepath, options, callback) {
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ Object.defineProperty(Minifier, 'maxThreads', {
|
|||||||
},
|
},
|
||||||
set: function (val) {
|
set: function (val) {
|
||||||
maxThreads = val;
|
maxThreads = val;
|
||||||
|
if (!process.env.minifier_child) {
|
||||||
winston.verbose('[minifier] utilizing a maximum of ' + maxThreads + ' additional threads');
|
winston.verbose('[minifier] utilizing a maximum of ' + maxThreads + ' additional threads');
|
||||||
|
}
|
||||||
},
|
},
|
||||||
configurable: true,
|
configurable: true,
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
@@ -65,7 +67,9 @@ function freeChild(proc) {
|
|||||||
|
|
||||||
function removeChild(proc) {
|
function removeChild(proc) {
|
||||||
var i = pool.indexOf(proc);
|
var i = pool.indexOf(proc);
|
||||||
|
if (i !== -1) {
|
||||||
pool.splice(i, 1);
|
pool.splice(i, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function forkAction(action, callback) {
|
function forkAction(action, callback) {
|
||||||
|
|||||||
@@ -9,23 +9,36 @@ var pkg = require('../package.json');
|
|||||||
var dirname = require('./cli/paths').baseDir;
|
var dirname = require('./cli/paths').baseDir;
|
||||||
|
|
||||||
function setupWinston() {
|
function setupWinston() {
|
||||||
winston.remove(winston.transports.Console);
|
var formats = [];
|
||||||
winston.add(winston.transports.Console, {
|
|
||||||
colorize: nconf.get('log-colorize') !== 'false',
|
if (nconf.get('log-colorize') !== 'false') {
|
||||||
timestamp: function () {
|
formats.push(winston.format.colorize());
|
||||||
var date = new Date();
|
}
|
||||||
return nconf.get('json-logging') ? date.toJSON() :
|
|
||||||
date.toISOString() + ' [' + global.process.pid + ']';
|
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'),
|
level: nconf.get('log-level') || (global.env === 'production' ? 'info' : 'verbose'),
|
||||||
json: !!nconf.get('json-logging'),
|
format: winston.format.combine.apply(null, formats),
|
||||||
stringify: !!nconf.get('json-logging'),
|
transports: [
|
||||||
|
new winston.transports.Console(),
|
||||||
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadConfig(configFile) {
|
function loadConfig(configFile) {
|
||||||
winston.verbose('* using configuration stored in: %s', configFile);
|
|
||||||
|
|
||||||
nconf.file({
|
nconf.file({
|
||||||
file: configFile,
|
file: configFile,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -182,7 +182,8 @@ describe('Build', function (done) {
|
|||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
var filename = path.join(__dirname, '../build/public/admin.css');
|
var filename = path.join(__dirname, '../build/public/admin.css');
|
||||||
assert(file.existsSync(filename));
|
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();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -801,7 +801,11 @@ describe('Controllers', function () {
|
|||||||
}, function (err, res, body) {
|
}, function (err, res, body) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(res.statusCode, 403);
|
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();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,40 +1,37 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var util = require('util');
|
|
||||||
var winston = require('winston');
|
var winston = require('winston');
|
||||||
|
var Transport = require('winston-transport');
|
||||||
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 winstonLogged = [];
|
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 () {
|
before(function () {
|
||||||
// defer winston logs until the end
|
// defer winston logs until the end
|
||||||
winston.remove(winston.transports.Console);
|
winston.clear();
|
||||||
|
|
||||||
winston.add(DeferLogger, {
|
winston.add(new DeferLogger({ logged: winstonLogged }));
|
||||||
logged: winstonLogged,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
after(function () {
|
after(function () {
|
||||||
console.log('\n\n');
|
console.log('\n\n');
|
||||||
|
|
||||||
var con = new winston.transports.Console();
|
|
||||||
winstonLogged.forEach(function (args) {
|
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 async = require('async');
|
||||||
var winston = require('winston');
|
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var nconf = require('nconf');
|
var nconf = require('nconf');
|
||||||
var url = require('url');
|
var url = require('url');
|
||||||
@@ -14,6 +13,14 @@ var errorText;
|
|||||||
|
|
||||||
var packageInfo = require('../../package');
|
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.file({ file: path.join(__dirname, '../../config.json') });
|
||||||
nconf.defaults({
|
nconf.defaults({
|
||||||
base_dir: path.join(__dirname, '../..'),
|
base_dir: path.join(__dirname, '../..'),
|
||||||
@@ -83,9 +90,7 @@ if (testDbConfig.database === productionDbConfig.database &&
|
|||||||
|
|
||||||
nconf.set(dbType, testDbConfig);
|
nconf.set(dbType, testDbConfig);
|
||||||
|
|
||||||
winston.info('database config');
|
winston.info('database config %s', dbType, testDbConfig);
|
||||||
winston.info(dbType);
|
|
||||||
winston.info(testDbConfig);
|
|
||||||
|
|
||||||
var db = require('../../src/database');
|
var db = require('../../src/database');
|
||||||
module.exports = db;
|
module.exports = db;
|
||||||
|
|||||||
Reference in New Issue
Block a user