fix: explicitly stringify extra fields passed to the logger service
Signed-off-by: Paul Schultz <pschultz@pobox.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/backend-defaults': patch
|
||||
---
|
||||
|
||||
Explicitly stringify extra logger fields with `JSON.stringify` to prevent `[object Object]` errors.
|
||||
@@ -93,28 +93,4 @@ describe('WinstonLogger', () => {
|
||||
expect.any(Function),
|
||||
);
|
||||
});
|
||||
|
||||
it('gracefully handles fields that are not castable to a string', () => {
|
||||
const mockTransport = new Transport({
|
||||
log: jest.fn(),
|
||||
logv: jest.fn(),
|
||||
});
|
||||
|
||||
const logger = WinstonLogger.create({
|
||||
transports: [mockTransport],
|
||||
});
|
||||
|
||||
logger.error('something went wrong', {
|
||||
field: Object.create(null),
|
||||
});
|
||||
|
||||
expect(mockTransport.log).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
[MESSAGE]: expect.stringContaining(
|
||||
'[field value not castable to string]',
|
||||
),
|
||||
}),
|
||||
expect.any(Function),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -151,7 +151,7 @@ export class WinstonLogger implements RootLoggerService {
|
||||
let stringValue = '';
|
||||
|
||||
try {
|
||||
stringValue = `${value}`;
|
||||
stringValue = JSON.stringify(value);
|
||||
} catch (e) {
|
||||
stringValue = '[field value not castable to string]';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user