whatsauto.js
Version:
Easy WhatsApp Automation with Session
35 lines (34 loc) • 1.17 kB
JavaScript
import { blue, red, green, yellow, gray, cyan } from "colorette";
export default class Logger {
name;
autoWA;
constructor(name, autoWA) {
this.name = name;
this.autoWA = autoWA;
}
formatMessage(level, message) {
const levelColors = {
DEBUG: blue,
INFO: green,
WARN: yellow,
ERROR: red,
};
const timestamp = new Date().toISOString();
const tag = levelColors[level](`[${level}]`);
const scope = cyan(`[${this.name}]`);
const msg = typeof message === "string" ? message : JSON.stringify(message, null, 2);
return `${gray(timestamp)} ${tag} ${scope} ${msg}`;
}
debug(message) {
this.autoWA.options.logging && console.debug(this.formatMessage("DEBUG", message));
}
info(message) {
this.autoWA.options.logging && console.info(this.formatMessage("INFO", message));
}
warn(message) {
this.autoWA.options.logging && console.warn(this.formatMessage("WARN", message));
}
error(message) {
this.autoWA.options.logging && console.error(this.formatMessage("ERROR", message));
}
}