Skip to content

Commit

Permalink
make ConsoleLogger compatible with node < 8
Browse files Browse the repository at this point in the history
  • Loading branch information
aoberoi committed Feb 16, 2019
1 parent 6d54f96 commit 0bff647
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/logger.ts
Expand Up @@ -83,9 +83,19 @@ export class ConsoleLogger implements Logger {
[LogLevel.DEBUG]: 100,
};

/** Reference to a function that can be used as console.debug() */
private debugFn: (message?: any, ...optionalParams: any[]) => void;

constructor() {
this.level = LogLevel.INFO;
this.name = '';

// In node < 8.0.0, console.debug does not exist
if (console.debug !== undefined) {
this.debugFn = console.debug;
} else {
this.debugFn = console.log;
}
}

/**
Expand All @@ -107,7 +117,7 @@ export class ConsoleLogger implements Logger {
*/
public debug(...msg: any[]): void {
if (ConsoleLogger.isMoreOrEqualSevere(LogLevel.DEBUG, this.level)) {
console.debug(ConsoleLogger.labels.get(LogLevel.DEBUG), this.name, ...msg);
this.debugFn(ConsoleLogger.labels.get(LogLevel.DEBUG), this.name, ...msg);
}
}
/**
Expand Down

0 comments on commit 0bff647

Please sign in to comment.