test(rootLogger): Redaction formatting
Signed-off-by: Harry Hogg <hhogg@spotify.com>
This commit is contained in:
@@ -15,7 +15,12 @@
|
||||
*/
|
||||
|
||||
import * as winston from 'winston';
|
||||
import { createRootLogger, getRootLogger, setRootLogger } from './rootLogger';
|
||||
import {
|
||||
createRootLogger,
|
||||
getRootLogger,
|
||||
setRootLogger,
|
||||
setRedactionList,
|
||||
} from './rootLogger';
|
||||
|
||||
describe('rootLogger', () => {
|
||||
it('can replace the default logger', () => {
|
||||
@@ -30,6 +35,19 @@ describe('rootLogger', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('redacts given secrets', () => {
|
||||
const logger = createRootLogger();
|
||||
jest.spyOn(logger, 'write');
|
||||
setRedactionList(['SECRET_1', 'SECRET_2']);
|
||||
logger.info('Logging SECRET_1 and SECRET_2 but not SECRET_3');
|
||||
|
||||
expect(logger.write).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
message: 'Logging [REDACTED] and [REDACTED] but not SECRET_3',
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
describe('createRootLoger', () => {
|
||||
it('creates a new logger', () => {
|
||||
const oldLogger = getRootLogger();
|
||||
|
||||
Reference in New Issue
Block a user