tests: Disable non-test logging unless level <= DEBUG

This makes it easier to see the test results, and it hides some
scary-looking but intentional error messages.

This code will likely have to be updated if/when we change the logging
library (see issue #1922).
docker-travis
Richard Hansen 2020-10-04 17:29:45 -04:00 committed by John McLear
parent 34b232d658
commit c74b254334
1 changed files with 10 additions and 0 deletions

View File

@ -14,10 +14,19 @@ exports.baseUrl = null;
exports.httpServer = null;
exports.logger = log4js.getLogger('test');
const logLevel = exports.logger.level;
exports.init = async function() {
if (inited) return exports.agent;
inited = true;
if (!logLevel.isLessThanOrEqualTo(log4js.levels.DEBUG)) {
exports.logger.warn('Disabling non-test logging for the duration of the test. ' +
'To enable non-test logging, change the loglevel setting to DEBUG.');
log4js.setGlobalLogLevel(log4js.levels.OFF);
exports.logger.setLevel(logLevel);
}
// Note: This is only a shallow backup.
backups.settings = Object.assign({}, settings);
// Start the Etherpad server on a random unused port.
@ -37,6 +46,7 @@ exports.init = async function() {
await server.stop();
// Note: This does not unset settings that were added.
Object.assign(settings, backups.settings);
log4js.setGlobalLogLevel(logLevel);
});
return exports.agent;