Skip to content

Commit

Permalink
fix: stringify error
Browse files Browse the repository at this point in the history
Close #2469, Close #2471
  • Loading branch information
develar committed Jan 15, 2018
1 parent a832ba7 commit be9a5f9
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/builder-util/src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ export class Logger {
}
}

private doLog(message: string | undefined, messageOrFields: Fields | null | string, level: LogLevel) {
if (message instanceof Error) {
message = message.stack
}

private doLog(message: string | undefined | Error, messageOrFields: Fields | null | string, level: LogLevel) {
if (message === undefined) {
this._doLog(messageOrFields as string, null, level)
}
Expand All @@ -65,7 +61,15 @@ export class Logger {
}
}

private _doLog(message: string, fields: Fields | null, level: LogLevel) {
private _doLog(message: string | Error, fields: Fields | null, level: LogLevel) {
// noinspection SuspiciousInstanceOfGuard
if (message instanceof Error) {
message = message.stack || message.toString()
}
else {
message = message.toString()
}

const levelIndicator = "•"
const color = LEVEL_TO_COLOR[level]
this.stream.write(`${" ".repeat(PADDING)}${color(levelIndicator)} `)
Expand Down

0 comments on commit be9a5f9

Please sign in to comment.