Skip to content

Commit

Permalink
fix(utils/log): Remove formatting of log messages in ConsoleLogger
Browse files Browse the repository at this point in the history
  • Loading branch information
odinr committed Aug 27, 2024
1 parent 00d5e9c commit e9f75a3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-knives-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@equinor/fusion-log': minor
---

Removed formatting of messages in the `log` function. Now the messages are printed as they are, without any additional formatting. This is done to make the messages more readable and to avoid any additional formatting that might be added by the user. Formatting objects would result in the console outputting `[[object,object]]` which was not very helpful.
13 changes: 1 addition & 12 deletions packages/utils/log/src/ConsoleLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,14 @@ export class ConsoleLogger extends Logger {
* @returns An array of unknown, representing the formatted log message.
*/
protected _createMessage(lvl: LogLevel, ...msg: unknown[]): unknown[] {
return this._formatMessage(lvl, this._formatTitle(lvl), ...msg);
return [this._formatTitle(lvl), ...msg];
}

protected _formatTitle(_lvl: LogLevel): string {
const title = [this.title, this.subtitle].filter((x) => !!x).join(' - ');
return chalk.magenta(title);
}

protected _formatMessage(lvl: LogLevel, ...msg: unknown[]): unknown[] {
switch (lvl) {
case LogLevel.Debug:
return [chalk.dim(...msg)];
case LogLevel.Warning:
return [chalk.bold(...msg)];
default:
return msg;
}
}

/**
* Creates a new `ConsoleLogger` instance with a specific title and subtitle, and an optional log level.
*
Expand Down

0 comments on commit e9f75a3

Please sign in to comment.