Skip to content

Commit

Permalink
fix logger module for error (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomendezroyo authored Dec 2, 2024
1 parent f35bff7 commit 79cbeec
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/brain/src/modules/logger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ class Logger {
if (this.print("error")) {
const errorColor = "\x1b[31m\x1b[0m";
console.log(`${errorColor}[ERROR]${errorColor} ${this.parseMessage(message)}`);
if (error) console.error(error);
if (error) console.error(this.parseMessage(error));
}
}

private parseMessage(message: string | object | null): string {
if (typeof message === "string") return message;
if (message instanceof Error) {
return `${message.name}: ${message.message}\n${message.stack}`;
}
if (typeof message === "object") return JSON.stringify(message, null, 2);
return message;
return String(message);
}

private print(logger: "debug" | "info" | "warn" | "error"): boolean {
Expand Down

0 comments on commit 79cbeec

Please sign in to comment.