Skip to content

Commit

Permalink
Send Logger.Level.ERROR logs to STDERR
Browse files Browse the repository at this point in the history
  • Loading branch information
zefir-git committed Aug 12, 2023
1 parent 280f4af commit d5df0cc
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@ class Logger {
}

/**
* Print object without any log level
* Print object without any log level to STDOUT
* @param obj Object to print
*/
private send(...obj: any[]): void {
private stdout(...obj: any[]): void {
console.log(...obj);
}

/**
* Print object without any log level to STDERR
* @param obj Object to print
*/
private stderr(...obj: any[]): void {
console.error(...obj);
}

/**
* Format string with log level and prefix
* @param level Log level
Expand All @@ -29,7 +37,7 @@ class Logger {
* @param [obj] Objects to print
*/
public log(level: Logger.Level, message: string, ...obj: any[]): void {
this.send(this.format(level, message), ...obj);
this[level === Logger.Level.ERROR ? "stderr" : "stdout"](this.format(level, message), ...obj);
}

/**
Expand Down

0 comments on commit d5df0cc

Please sign in to comment.