diff --git a/app.js b/app.js index 4c910262bc..f4cda16d5b 100644 --- a/app.js +++ b/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 diff --git a/install/package.json b/install/package.json index f2f6febfdc..60187a1868 100644 --- a/install/package.json +++ b/install/package.json @@ -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" diff --git a/install/web.js b/install/web.js index 8ebf0fb641..d004760d46 100644 --- a/install/web.js +++ b/install/web.js @@ -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) { diff --git a/src/meta/minifier.js b/src/meta/minifier.js index 14da9beb93..d34d9169a6 100644 --- a/src/meta/minifier.js +++ b/src/meta/minifier.js @@ -26,7 +26,9 @@ Object.defineProperty(Minifier, 'maxThreads', { }, set: function (val) { maxThreads = val; - winston.verbose('[minifier] utilizing a maximum of ' + maxThreads + ' additional threads'); + 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); - pool.splice(i, 1); + if (i !== -1) { + pool.splice(i, 1); + } } function forkAction(action, callback) { diff --git a/src/prestart.js b/src/prestart.js index 1d5a5146ab..f36f6effd0 100644 --- a/src/prestart.js +++ b/src/prestart.js @@ -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, }); diff --git a/test/authentication.js b/test/authentication.js index f22ae7fc04..83c4092e11 100644 --- a/test/authentication.js +++ b/test/authentication.js @@ -1,7 +1,7 @@ 'use strict'; -var assert = require('assert'); +var assert = require('assert'); var nconf = require('nconf'); var request = require('request'); var async = require('async'); diff --git a/test/build.js b/test/build.js index 20888f0b0c..55dbae861a 100644 --- a/test/build.js +++ b/test/build.js @@ -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(); }); }); diff --git a/test/controllers.js b/test/controllers.js index e26694ba4d..61d70f05f3 100644 --- a/test/controllers.js +++ b/test/controllers.js @@ -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(); }); }); diff --git a/test/defer-logger.js b/test/defer-logger.js index 3ddb9de45c..a3e5c91716 100644 --- a/test/defer-logger.js +++ b/test/defer-logger.js @@ -1,40 +1,37 @@ 'use strict'; -var util = require('util'); 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; -} +var winstonLogged = []; -util.inherits(DeferLogger, winston.Transport); +class DeferLogger extends Transport { + constructor(opts) { + super(opts); + this.logged = opts.logged; + } -DeferLogger.prototype.log = function log(level, msg, meta, callback) { - this.logged.push([level, msg, meta]); - callback(null, true); -}; + log(info, callback) { + setImmediate(() => { + this.emit('logged', info); + }); -var winstonLogged = []; + 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]); }); }); diff --git a/test/mocks/databasemock.js b/test/mocks/databasemock.js index 47f3e37b72..7624877a75 100644 --- a/test/mocks/databasemock.js +++ b/test/mocks/databasemock.js @@ -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;