Skip to content

Commit

Permalink
Ensure custom winston options are not overridden (#1008)
Browse files Browse the repository at this point in the history
* fix: ensure winston custom options are not overridden

* docs: changelog
  • Loading branch information
agerard-godaddy authored Jan 13, 2025
1 parent e71aa0f commit 49fffa8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
3 changes: 3 additions & 0 deletions packages/gasket-plugin-winston/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# `@gasket/plugin-winston`

- Ensure gasket.winston options are not overridden ([#1008])

### 7.1.0

- Aligned version releases across all packages
Expand All @@ -11,3 +13,4 @@


[Version 7 Upgrade Guide]: /docs/upgrade-to-7.md
[#1008]: https://github.com/godaddy/gasket/pull/1008
8 changes: 4 additions & 4 deletions packages/gasket-plugin-winston/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
41 changes: 40 additions & 1 deletion packages/gasket-plugin-winston/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,7 +66,6 @@ describe('@gasket/plugin-winston', function () {
gasket.execSync('create', mockContext);
expect(mockContext.gasketConfig.addPlugin).toHaveBeenCalledWith('pluginWinston', name);
});

});

describe('createLogger hook', function () {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 49fffa8

Please sign in to comment.