Skip to content

Commit

Permalink
Merge pull request #1460 from apiel/master
Browse files Browse the repository at this point in the history
enhancement(common): make logger output more customizable
  • Loading branch information
kamilmysliwiec committed Feb 5, 2019
2 parents 93b3e0b + 8f66fd1 commit 233e7ad
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/common/services/logger.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,17 @@ export class Logger implements LoggerService {
this.printMessage(message, clc.yellow, context, isTimeDiffEnabled);
}

protected static isActive(): boolean {
return Logger.contextEnvironment !== NestEnvironment.TEST;
}

private static printMessage(
message: any,
color: (message: string) => string,
context: string = '',
isTimeDiffEnabled?: boolean,
) {
if (Logger.contextEnvironment === NestEnvironment.TEST) {
if (!this.isActive()) {
return;
}
const output = isObject(message) ? JSON.stringify(message, null, 2) : message;
Expand All @@ -108,7 +112,7 @@ export class Logger implements LoggerService {
}

private static printStackTrace(trace: string) {
if (this.contextEnvironment === NestEnvironment.TEST || !trace) {
if (!this.isActive() || !trace) {
return;
}
process.stdout.write(trace);
Expand Down

0 comments on commit 233e7ad

Please sign in to comment.