whatsauto.js
Version:
Easy WhatsApp Automation with Session
55 lines (54 loc) • 2.43 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const colorette_1 = require("colorette");
class Logger {
constructor(name, autoWA) {
this.name = name;
this.autoWA = autoWA;
}
formatMessage(level, message) {
return __awaiter(this, void 0, void 0, function* () {
const levelColors = {
DEBUG: colorette_1.blue,
INFO: colorette_1.green,
WARN: colorette_1.yellow,
ERROR: colorette_1.red,
};
const timestamp = new Date().toISOString();
const tag = levelColors[level](`[${level}]`);
const scope = (0, colorette_1.cyan)(`[${this.name}]`);
const msg = typeof message === "string" ? message : JSON.stringify(message, null, 2);
return `${(0, colorette_1.gray)(timestamp)} ${tag} ${scope} ${msg}`;
});
}
debug(message) {
return __awaiter(this, void 0, void 0, function* () {
this.autoWA.options.logging && console.debug(yield this.formatMessage("DEBUG", message));
});
}
info(message) {
return __awaiter(this, void 0, void 0, function* () {
this.autoWA.options.logging && console.info(yield this.formatMessage("INFO", message));
});
}
warn(message) {
return __awaiter(this, void 0, void 0, function* () {
this.autoWA.options.logging && console.warn(yield this.formatMessage("WARN", message));
});
}
error(message) {
return __awaiter(this, void 0, void 0, function* () {
this.autoWA.options.logging && console.error(yield this.formatMessage("ERROR", message));
});
}
}
exports.default = Logger;