Skip to content

Commit

Permalink
PR#92 <- feat/logger-mocking
Browse files Browse the repository at this point in the history
[PR#92 <- feat/logger-mocking] Add a mock mode to Logger (see CUTS), misc. fixes & adjustments
  • Loading branch information
daniwasonline authored May 28, 2024
2 parents f252c36 + 09ffa67 commit 6b62c9e
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 6b62c9e

Please sign in to comment.