Skip to content

Commit

Permalink
feat(core-kernel): allow enabling/disabling log methods
Browse files Browse the repository at this point in the history
  • Loading branch information
faustbrian authored Nov 14, 2019
1 parent 1a4e132 commit 292d9e8
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions packages/core-kernel/src/services/log/drivers/pino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,25 @@ export class PinoLogger implements Logger {

this.fileStream = this.getFileStream(options.fileRotator);

// @ts-ignore
const consoleTransport = this.createPrettyTransport(options.levels.console, { colorize: true });
// @ts-ignore
const fileTransport = this.createPrettyTransport(options.levels.file, { colorize: false });
if (this.isValidLevel(options.levels.console)) {
pump(
stream,
split(),
// @ts-ignore - Object literal may only specify known properties, and 'colorize' does not exist in type 'PrettyOptions'.
this.createPrettyTransport(options.levels.console, { colorize: true }),
process.stdout,
);
}

pump(stream, split(), consoleTransport, process.stdout);
pump(stream, split(), fileTransport, this.fileStream);
if (this.isValidLevel(options.levels.file)) {
pump(
stream,
split(),
// @ts-ignore - Object literal may only specify known properties, and 'colorize' does not exist in type 'PrettyOptions'.
this.createPrettyTransport(options.levels.file, { colorize: false }),
this.fileStream,
);
}

return this;
}
Expand Down Expand Up @@ -282,4 +294,8 @@ export class PinoLogger implements Logger {
},
);
}

private isValidLevel(level: string): boolean {
return ["emergency", "alert", "critical", "error", "warning", "notice", "info", "debug"].includes(level);
}
}

0 comments on commit 292d9e8

Please sign in to comment.