diff --git a/packages/gasket-plugin-winston/CHANGELOG.md b/packages/gasket-plugin-winston/CHANGELOG.md index cd625d081..02f191f16 100644 --- a/packages/gasket-plugin-winston/CHANGELOG.md +++ b/packages/gasket-plugin-winston/CHANGELOG.md @@ -1,5 +1,7 @@ # `@gasket/plugin-winston` +- Ensure gasket.winston options are not overridden ([#1008]) + ### 7.1.0 - Aligned version releases across all packages @@ -11,3 +13,4 @@ [Version 7 Upgrade Guide]: /docs/upgrade-to-7.md +[#1008]: https://github.com/godaddy/gasket/pull/1008 diff --git a/packages/gasket-plugin-winston/lib/index.js b/packages/gasket-plugin-winston/lib/index.js index 69f5e427d..fd789333b 100644 --- a/packages/gasket-plugin-winston/lib/index.js +++ b/packages/gasket-plugin-winston/lib/index.js @@ -45,13 +45,13 @@ const plugin = { format.combine(format.splat(), format.json()); return createLogger({ + format: defaultFormat, + levels: Object.assign({ fatal: 0, warn: 4, trace: 7 }, winstonConfig.syslog.levels), + exitOnError: true, ...config.winston, transports: configTransports.concat( pluginTransports.flat().filter(Boolean) - ), - format: config.winston?.format ?? defaultFormat, - levels: Object.assign({ fatal: 0, warn: 4, trace: 7 }, winstonConfig.syslog.levels), - exitOnError: true + ) }); }, metadata(gasket, meta) { diff --git a/packages/gasket-plugin-winston/test/index.test.js b/packages/gasket-plugin-winston/test/index.test.js index 6b7600f18..bdfa52e82 100644 --- a/packages/gasket-plugin-winston/test/index.test.js +++ b/packages/gasket-plugin-winston/test/index.test.js @@ -7,6 +7,7 @@ const { name, version, description } = require('../package'); // Mock console methods jest.spyOn(console, 'error').mockImplementation(() => { }); +jest.spyOn(console, 'log').mockImplementation(() => { }); describe('@gasket/plugin-winston', function () { let gasket; @@ -65,7 +66,6 @@ describe('@gasket/plugin-winston', function () { gasket.execSync('create', mockContext); expect(mockContext.gasketConfig.addPlugin).toHaveBeenCalledWith('pluginWinston', name); }); - }); describe('createLogger hook', function () { @@ -116,6 +116,45 @@ describe('@gasket/plugin-winston', function () { } }); + it('allows custom levels', function () { + gasket.config.winston = { + levels: { + critical: 0, + awesome: 4, + bogus: 7 + } + }; + const [logger] = gasket.execSync('createLogger'); + + expect(logger).toBeDefined(); + expect(logger).not.toEqual(null); + expect(typeof logger).toEqual('object'); + expect(logger).toHaveProperty('critical'); + expect(logger).toHaveProperty('awesome'); + expect(logger).toHaveProperty('bogus'); + }); + + it('allows custom formats', function () { + const customFormat = { + transform: jest.fn((info) => info) + }; + gasket.config.winston = { + format: customFormat + }; + + const [logger] = gasket.execSync('createLogger'); + + expect(logger).toBeDefined(); + expect(logger).not.toEqual(null); + expect(typeof logger).toEqual('object'); + + logger.info('test 123'); + expect(customFormat.transform).toHaveBeenCalledWith(expect.objectContaining({ + level: 'info', + message: 'test 123' + }), expect.undefined); + }); + describe('custom transports', () => { let transport1; let transport2;