diff --git a/api/src/logger.js b/api/src/logger.js index 987e26e241a..827d7012285 100644 --- a/api/src/logger.js +++ b/api/src/logger.js @@ -67,7 +67,6 @@ const logger = createLogger({ info.level = info.level.toUpperCase(); return info; })(), - format.colorize(), format.timestamp({ format: DATE_FORMAT }), format.printf(info => `${info.timestamp} ${info.level}: ${info.message} ${info.stack ? info.stack : ''}`) ), diff --git a/sentinel/src/lib/logger.js b/sentinel/src/lib/logger.js index 1d5ab6279a3..933a627decd 100644 --- a/sentinel/src/lib/logger.js +++ b/sentinel/src/lib/logger.js @@ -1,5 +1,6 @@ const { createLogger, format, transports } = require('winston'); const env = process.env.NODE_ENV || 'development'; +const DATE_FORMAT = 'YYYY-MM-DDTHH:mm:ss.SSS'; const cleanUpSymbolProperties = (info) => { if (!info) { @@ -67,10 +68,7 @@ const logger = createLogger({ info.level = info.level.toUpperCase(); return info; })(), - format.colorize(), - format.timestamp({ - format: 'YYYY-MM-DD HH:mm:ss', - }), + format.timestamp({ format: DATE_FORMAT }), format.printf(info => `${info.timestamp} ${info.level}: ${info.message} ${info.stack ? info.stack : ''}`) ), }), diff --git a/tests/integration/logging/logging.spec.js b/tests/integration/logging/logging.spec.js new file mode 100644 index 00000000000..bdbdc0f438c --- /dev/null +++ b/tests/integration/logging/logging.spec.js @@ -0,0 +1,35 @@ +const utils = require('@utils'); +const moment = require('moment'); + +const validLog = (line, before, after) => { + const [date, action] = line.split(/\s/); + console.log(date, before.toISOString(), after.toISOString()); + + expect(moment.utc(date, 'YYYY-MM-DDTHH:mm:ss.SSS', true).isValid()).to.equal(true); + expect(moment.utc(date).isBetween(before, after)).to.be.true; + expect(action).to.be.oneOf(['REQ:', 'RES:', 'DEBUG:', 'INFO:', 'ERROR:', 'WARN:']); +}; + +describe('logging', () => { + it('logs should include formatted date in API and Sentinel', async () => { + const before = moment.utc(); + await utils.delayPromise(500); // dates are not exact + + const collectApiLogs = await utils.collectApiLogs(/.*/); + const collectSentinelLogs = await utils.collectApiLogs(/.*/); + await utils.delayPromise(1000); // log debug message for checking messages + await utils.request('/dbinfo'); + await utils.updateSettings({ test: true }, 'sentinel'); + const apiLogs = (await collectApiLogs()).filter(log => log.length); + const sentinelLogs = (await collectSentinelLogs()).filter(log => log.length); + + await utils.delayPromise(500); // dates are not exact + const after = moment.utc(); + + expect(apiLogs.length).to.be.greaterThan(0); + apiLogs.forEach(log => validLog(log, before, after)); + + expect(sentinelLogs.length).to.be.greaterThan(0); + sentinelLogs.forEach(log => validLog(log, before, after)); + }); +}); diff --git a/tests/utils/index.js b/tests/utils/index.js index ab75ed150f7..af2de70054b 100644 --- a/tests/utils/index.js +++ b/tests/utils/index.js @@ -1033,7 +1033,7 @@ const saveLogs = async () => { const tearDownServices = async (removeOrphans) => { if (removeOrphans) { - return dockerComposeCmd('down', '--remove-orphans', '--volumes'); + return dockerComposeCmd('down', '-t=0', '--remove-orphans', '--volumes'); } await saveLogs(); };