Skip to content

Commit

Permalink
Adds e2e test and removes colorize.
Browse files Browse the repository at this point in the history
Signed-off-by: Diana Barsan <[email protected]>
  • Loading branch information
dianabarsan committed Jul 31, 2023
1 parent 63d5fe7 commit 8196064
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
1 change: 0 additions & 1 deletion api/src/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 : ''}`)
),
Expand Down
6 changes: 2 additions & 4 deletions sentinel/src/lib/logger.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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 : ''}`)
),
}),
Expand Down
35 changes: 35 additions & 0 deletions tests/integration/logging/logging.spec.js
Original file line number Diff line number Diff line change
@@ -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));
});
});
2 changes: 1 addition & 1 deletion tests/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down

0 comments on commit 8196064

Please sign in to comment.