UNPKG

@thoshpathi/utils-core

Version:

A collection of core utility functions for data processing

45 lines (43 loc) 1.25 kB
// src/logger_utils.ts import { format } from "date-fns"; import createDebug from "debug"; var logLevels = [ "debug", "info", "alert", "warning", "error", "critical" ]; var Logger = class { constructor(namespace = "log", timestampFormat = "dd-MM-yyyy HH:mm:ss") { this.timestampFormat = timestampFormat; this.d = (...args) => this.log("debug", args); this.i = (...args) => this.log("info", args); this.a = (...args) => this.log("alert", args); this.w = (...args) => this.log("warning", args); this.e = (...args) => this.log("error", args); this.c = (...args) => this.log("critical", args); this.timestampFormat = timestampFormat; const logger2 = createDebug(namespace); this.loggers = logLevels.reduce((acc, level) => { acc[level] = logger2.extend(level); return acc; }, {}); } datetimeString() { return format(/* @__PURE__ */ new Date(), this.timestampFormat); } log(logLevel, args) { const logger2 = this.loggers[logLevel]; const level = logLevel.toUpperCase(); return logger2("[%s] %s %o", level, this.datetimeString(), ...args); } }; var logger = new Logger(); var logger_utils_default = logger; export { Logger, logger, logger_utils_default };