* ⚡ Release 3.1.3 (#5267) * ⚡ Release 3.1.3 * Update CHANGELOG.md * ⬆️ Bump winston and winston-daily-rotate-file Bumps [winston](https://github.com/winstonjs/winston) and [winston-daily-rotate-file](https://github.com/winstonjs/winston-daily-rotate-file). These dependencies needed to be updated together. Updates `winston` from 2.4.4 to 3.1.0 - [Release notes](https://github.com/winstonjs/winston/releases) - [Changelog](https://github.com/winstonjs/winston/blob/master/CHANGELOG.md) - [Commits](https://github.com/winstonjs/winston/compare/2.4.4...3.1.0) Updates `winston-daily-rotate-file` from 1.7.2 to 3.5.1 - [Release notes](https://github.com/winstonjs/winston-daily-rotate-file/releases) - [Commits](https://github.com/winstonjs/winston-daily-rotate-file/compare/v1.7.2...v3.5.1) Signed-off-by: dependabot[bot] <support@dependabot.com> * Rewrote WinstonLogger to work with winston 3.x api * Changed winston logger test to use winston-transport * Added winston-transport dependency * Close and remove transports before adding them again * Changed to strict equal * Override adapter name * Updated and added getLogs tests * Bump winston and winston-daily-rotate-file Bumps [winston](https://github.com/winstonjs/winston) and [winston-daily-rotate-file](https://github.com/winstonjs/winston-daily-rotate-file). These dependencies needed to be updated together. Updates `winston` from 2.4.4 to 3.2.0 - [Release notes](https://github.com/winstonjs/winston/releases) - [Changelog](https://github.com/winstonjs/winston/blob/master/CHANGELOG.md) - [Commits](https://github.com/winstonjs/winston/compare/2.4.4...3.2.0) Updates `winston-daily-rotate-file` from 1.7.2 to 3.6.0 - [Release notes](https://github.com/winstonjs/winston-daily-rotate-file/releases) - [Commits](https://github.com/winstonjs/winston-daily-rotate-file/compare/v1.7.2...v3.6.0) Signed-off-by: dependabot[bot] <support@dependabot.com> * Fixed tests, updated parse logging * Fixed tests, better error logging * Fix failing tests * Updates as per review
66 lines
1.8 KiB
JavaScript
66 lines
1.8 KiB
JavaScript
const logging = require('../lib/Adapters/Logger/WinstonLogger');
|
|
const Transport = require('winston-transport');
|
|
|
|
class TestTransport extends Transport {
|
|
log(info, callback) {
|
|
callback(null, true);
|
|
}
|
|
}
|
|
|
|
describe('WinstonLogger', () => {
|
|
it('should add transport', () => {
|
|
const testTransport = new TestTransport();
|
|
spyOn(testTransport, 'log');
|
|
logging.addTransport(testTransport);
|
|
expect(logging.logger.transports.length).toBe(4);
|
|
logging.logger.info('hi');
|
|
expect(testTransport.log).toHaveBeenCalled();
|
|
logging.logger.error('error');
|
|
expect(testTransport.log).toHaveBeenCalled();
|
|
logging.removeTransport(testTransport);
|
|
expect(logging.logger.transports.length).toBe(3);
|
|
});
|
|
|
|
it('should have files transports', done => {
|
|
reconfigureServer().then(() => {
|
|
const transports = logging.logger.transports;
|
|
expect(transports.length).toBe(3);
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should disable files logs', done => {
|
|
reconfigureServer({
|
|
logsFolder: null,
|
|
}).then(() => {
|
|
const transports = logging.logger.transports;
|
|
expect(transports.length).toBe(1);
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should enable JSON logs', done => {
|
|
// Force console transport
|
|
reconfigureServer({
|
|
logsFolder: null,
|
|
jsonLogs: true,
|
|
silent: false,
|
|
})
|
|
.then(() => {
|
|
spyOn(process.stdout, 'write');
|
|
logging.logger.info('hi', { key: 'value' });
|
|
expect(process.stdout.write).toHaveBeenCalled();
|
|
const firstLog = process.stdout.write.calls.first().args[0];
|
|
expect(firstLog).toEqual(
|
|
JSON.stringify({ key: 'value', level: 'info', message: 'hi' }) + '\n'
|
|
);
|
|
return reconfigureServer({
|
|
jsonLogs: false,
|
|
});
|
|
})
|
|
.then(() => {
|
|
done();
|
|
});
|
|
});
|
|
});
|