Init
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
"use strict";
|
||||
// from crepesr
|
||||
// logger
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.VerboseLevel = void 0;
|
||||
require("colorts/lib/string");
|
||||
var VerboseLevel;
|
||||
(function (VerboseLevel) {
|
||||
VerboseLevel[VerboseLevel["NONE"] = 0] = "NONE";
|
||||
VerboseLevel[VerboseLevel["WARNS"] = 1] = "WARNS";
|
||||
VerboseLevel[VerboseLevel["ALL"] = 2] = "ALL";
|
||||
VerboseLevel[VerboseLevel["VERBL"] = 3] = "VERBL";
|
||||
VerboseLevel[VerboseLevel["VERBH"] = 4] = "VERBH";
|
||||
})(VerboseLevel || (exports.VerboseLevel = VerboseLevel = {}));
|
||||
class Logger {
|
||||
constructor(name = 'CLIENT', color = 'blue') {
|
||||
this.name = name;
|
||||
this.color = color;
|
||||
this.name = name;
|
||||
this.color = color;
|
||||
}
|
||||
getDate() {
|
||||
return new Date().toLocaleTimeString();
|
||||
}
|
||||
raw(...args) {
|
||||
// @ts-ignore - Element implicitly has an 'any' type because index expression is not of type 'number'
|
||||
console.log(`[${this.getDate().white.bold}] <${this.name[this.color].bold}>`, ...args);
|
||||
}
|
||||
log(...args) {
|
||||
this.raw(...args);
|
||||
}
|
||||
trail(...args) {
|
||||
console.log(`\t↳ ${args.join(' ').gray}`);
|
||||
}
|
||||
error(e, stack = true) {
|
||||
if (typeof e === 'string')
|
||||
e = new Error(e);
|
||||
console.log(`[${this.getDate().white.bold}] ${`ERROR<${this.name}>`.bgRed.bold}`, e.message);
|
||||
if (e.stack && stack)
|
||||
this.trail(e.stack);
|
||||
}
|
||||
warn(...args) {
|
||||
if (Logger.VERBOSE_LEVEL < VerboseLevel.WARNS)
|
||||
return;
|
||||
console.log(`[${this.getDate().white.bold}] ${`WARN<${this.name}>`.bgYellow.bold}`, ...args);
|
||||
}
|
||||
debug(...args) {
|
||||
if (Logger.VERBOSE_LEVEL < VerboseLevel.ALL)
|
||||
return;
|
||||
console.log(`[${this.getDate().white.bold}] ${`DEBUG<${this.name}>`.bgBlue.bold}`, ...args);
|
||||
this.trail(new Error().stack.split('\n').slice(2).join('\n'));
|
||||
}
|
||||
verbL(...args) {
|
||||
if (Logger.VERBOSE_LEVEL < VerboseLevel.VERBL)
|
||||
return;
|
||||
console.log(`[${this.getDate().white.bold}] ${`VERBL<${this.name}>`.bgCyan.bold}`, ...args);
|
||||
this.trail(new Error().stack.split('\n').slice(2).join('\n'));
|
||||
}
|
||||
verbH(...args) {
|
||||
if (Logger.VERBOSE_LEVEL < VerboseLevel.VERBH)
|
||||
return;
|
||||
console.log(`[${this.getDate().white.bold}] ${`VERBH<${this.name}>`.bgCyan.bold}`, ...args);
|
||||
this.trail(new Error().stack.split('\n').slice(2).join('\n'));
|
||||
}
|
||||
}
|
||||
Logger.VERBOSE_LEVEL = 1;
|
||||
exports.default = Logger;
|
||||
Reference in New Issue
Block a user