Skip to content

Commit

Permalink
refactor: only print caller file when logger is called from a named f…
Browse files Browse the repository at this point in the history
…unction
  • Loading branch information
iamkenos committed Sep 4, 2024
1 parent 539eb9c commit 398dbf1
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/core/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ export class Logger {
},
format(level, name, timestamp) {
const [, , , caller] = callsites();
const stack = caller.toString();
const from = caller.getFunctionName() || stack.substring(0, stack.indexOf("."));
return `${chalk.gray(`${timestamp}`)} ${COLORS[level.toUpperCase()](level)} ${chalk.yellow.bold(from)}:`;
const file = caller.toString();
const func = caller.getFunctionName();
const fn = func ? ` ${file.substring(0, file.indexOf("(")).trim()}:` : "";
return `${chalk.gray(timestamp)} ${COLORS[level.toUpperCase()](level)}${chalk.magenta(fn)}`;
}
});
}
Expand Down

0 comments on commit 398dbf1

Please sign in to comment.