Skip to content

Commit

Permalink
✨ Add mock option to logger, call proper console functions depending …
Browse files Browse the repository at this point in the history
…on log level
  • Loading branch information
daniwasonline committed May 28, 2024
1 parent 456ab6e commit 09ffa67
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,26 @@ export class Logger {
return `${levelCaller(levelName)} ${moduleCaller(moduleName)} ${formatted}`;
}

log(message, { module = "default", level = "default" }) {
log(message, { module = "default", level = "default", mock = false }) {
const formatted = this.fmt(message, level, module);
console.log(formatted);

if (mock === true) return formatted;

switch (level) {
case "info":
console.info(formatted);
break;
case "error":
console.error(formatted);
break;
case "warn":
console.warn(formatted);
break;
default:
console.log(formatted);
break;
}

return formatted;
}

Expand Down

0 comments on commit 09ffa67

Please sign in to comment.