@koreanpanda/inscriber
Version:
A Logger that can write logs, and print them, with full customization.
65 lines (64 loc) • 3.13 kB
JavaScript
;
/**========================================================================
* ? ABOUT
* @author : Cody Spratford
* @email : koreanpanda345@gmail.com
* @repo : https://github.com/koreanpanda345/Inscriber
* @createdOn : 11/14/2020
* @description : This is the Debug Class. This handles all debug type's
* methods
* @since : 11/15/2020
*========================================================================**/
Object.defineProperty(exports, "__esModule", { value: true });
exports.DebugClass = void 0;
var chalk = require("chalk");
var moment = require("moment");
var FileSystem_1 = require("../FileSystem");
var DebugClass = /** @class */ (function () {
function DebugClass(config, content, source) {
if (config["write-logs"]) {
if (config["one-file"]) {
if (typeof config["log-paths"].info !== "string")
throw new TypeError(
"Type Provided for Info's Log Path is not a string. The type must be a string.",
);
this.write(content.toString(), source, config["log-paths"].info, config);
} else {
if (typeof config["log-paths"].debug !== "string")
throw new TypeError(
"Type Provided for Error's Log Path is not a string. The type must be a string.",
);
this.write(content.toString(), source, config["log-paths"].debug, config);
}
}
this.print(content.toString(), source, config);
}
DebugClass.prototype.write = function (content, source, filepath, config) {
var message = this.formatString(config, source, content);
new FileSystem_1.FileSystem(config, moment().format("YYYY_MM_D") + ".log", message, "DEBUG").write();
};
DebugClass.prototype.print = function (content, source, config) {
var message = this.formatString(config, source, content);
console.log(this.formatColors(config, message));
};
DebugClass.prototype.formatColors = function (config, content) {
var color = config["log-colors"].debug;
if (color.background.startsWith("#")) {
if (color.text.startsWith("#")) return chalk.hex(color.text).bgKeyword(color.background)(content);
else return chalk.keyword(color.text).bgHex(color.background)(content);
} else {
if (color.text.startsWith("#")) return chalk.hex(color.text).bgKeyword(color.background)(content);
else return chalk.keyword(color.text).bgKeyword(color.background)(content);
}
};
DebugClass.prototype.formatString = function (config, source, content) {
var str = config["log-patterns"].debug;
str = str.replace("<time>", moment().format(config["time-pattern"]));
str = str.replace("<source>", source);
str = str.replace("<type>", "DEBUG");
str = str.replace("<message>", content);
return str;
};
return DebugClass;
})();
exports.DebugClass = DebugClass;