Skip to content

Commit

Permalink
test child logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel-Ladzaretti committed Dec 12, 2024
1 parent 75614e9 commit 07df9f7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions lib/logger/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fs from 'fs-extra';
import { partial } from '../../test/util';
import { add } from '../util/host-rules';
import { addSecretForSanitizing as addSecret } from '../util/sanitize';
import type { RenovateLogger } from '.';
import {
addMeta,
addStream,
Expand Down Expand Up @@ -59,6 +60,18 @@ describe('logger/index', () => {
expect(logLevel()).toBe('debug');
});

it('should create a child logger', () => {
const childLogger = (logger as RenovateLogger).childLogger();
const loggerSpy = jest.spyOn(logger, 'debug');
const childDebugSpy = jest.spyOn(childLogger, 'debug');

childLogger.debug('test');

expect(loggerSpy).toHaveBeenCalledTimes(0);
expect(childDebugSpy).toHaveBeenCalledTimes(1);
expect(childDebugSpy).toHaveBeenCalledWith('test');
});

it('saves problems', () => {
addSecret('p4$$w0rd');
levels('stdout', 'fatal');
Expand Down
4 changes: 2 additions & 2 deletions lib/logger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ export class RenovateLogger implements Logger {
);
}

once = this.logger.once;

trace = this.log.bind(this, 'trace');
debug = this.log.bind(this, 'debug');
info = this.log.bind(this, 'info');
warn = this.log.bind(this, 'warn');
error = this.log.bind(this, 'error');
fatal = this.log.bind(this, 'fatal');

once = this.logger.once;

get logContext(): string {
return this.context;
}
Expand Down

0 comments on commit 07df9f7

Please sign in to comment.