Skip to content

Commit

Permalink
Make logger compatible with Node (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospassos authored May 6, 2024
1 parent 24e7df8 commit 093332f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions src/logging/consoleLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ export class ConsoleLogger implements Logger {
}

public get debug(): (message: string) => void {
return this.bind(window.console.debug);
return this.bind(console.debug);

Check warning on line 15 in src/logging/consoleLogger.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
}

public get info(): (message: string) => void {
return this.bind(window.console.info);
return this.bind(console.info);

Check warning on line 19 in src/logging/consoleLogger.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
}

public get warn(): (message: string) => void {
return this.bind(window.console.warn);
return this.bind(console.warn);

Check warning on line 23 in src/logging/consoleLogger.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
}

public get error(): (message: string) => void {
return this.bind(window.console.error);
return this.bind(console.error);

Check warning on line 27 in src/logging/consoleLogger.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
}

private bind(method: ConsoleMethod): ConsoleMethod {
if (this.namespace !== undefined) {
return method.bind(window.console, `[${this.namespace}]`);
return method.bind(console, `[${this.namespace}]`);
}

return method.bind(window.console);
return method.bind(console);
}
}
16 changes: 8 additions & 8 deletions test/logging/consoleLogger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('A console logger', () => {
});

it('should log debug messages to the console', () => {
const consoleDebug = jest.spyOn(window.console, 'debug').mockImplementation();
const consoleDebug = jest.spyOn(console, 'debug').mockImplementation();

const logger = new ConsoleLogger();

Expand All @@ -16,7 +16,7 @@ describe('A console logger', () => {
});

it('should log debug messages prefixed with a namespace to the console', () => {
const consoleDebug = jest.spyOn(window.console, 'debug').mockImplementation();
const consoleDebug = jest.spyOn(console, 'debug').mockImplementation();

const logger = new ConsoleLogger('foo');

Expand All @@ -26,7 +26,7 @@ describe('A console logger', () => {
});

it('should log info messages to the console', () => {
const consoleInfo = jest.spyOn(window.console, 'info').mockImplementation();
const consoleInfo = jest.spyOn(console, 'info').mockImplementation();

const logger = new ConsoleLogger();

Expand All @@ -36,7 +36,7 @@ describe('A console logger', () => {
});

it('should log info messages prefixed with a namespace to the console', () => {
const consoleInfo = jest.spyOn(window.console, 'info').mockImplementation();
const consoleInfo = jest.spyOn(console, 'info').mockImplementation();

const logger = new ConsoleLogger('foo');

Expand All @@ -46,7 +46,7 @@ describe('A console logger', () => {
});

it('should log warn messages to the console', () => {
const consoleWarn = jest.spyOn(window.console, 'warn').mockImplementation();
const consoleWarn = jest.spyOn(console, 'warn').mockImplementation();

const logger = new ConsoleLogger();

Expand All @@ -56,7 +56,7 @@ describe('A console logger', () => {
});

it('should log warn messages prefixed with a namespace to the console', () => {
const consoleWarn = jest.spyOn(window.console, 'warn').mockImplementation();
const consoleWarn = jest.spyOn(console, 'warn').mockImplementation();

const logger = new ConsoleLogger('foo');

Expand All @@ -66,7 +66,7 @@ describe('A console logger', () => {
});

it('should log error messages to the console', () => {
const consoleError = jest.spyOn(window.console, 'error').mockImplementation();
const consoleError = jest.spyOn(console, 'error').mockImplementation();

const logger = new ConsoleLogger();

Expand All @@ -76,7 +76,7 @@ describe('A console logger', () => {
});

it('should log error messages prefixed with a namespace to the console', () => {
const consoleError = jest.spyOn(window.console, 'error').mockImplementation();
const consoleError = jest.spyOn(console, 'error').mockImplementation();

const logger = new ConsoleLogger('foo');

Expand Down

0 comments on commit 093332f

Please sign in to comment.