UNPKG

@koreanpanda/inscriber

Version:

A Logger that can write logs, and print them, with full customization.

214 lines (213 loc) 7.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.InscriberConfigBuilder = void 0; var InscriberConfig_1 = require("../InscriberConfig"); /**======================= * END OF IMPORTS *========================**/ /**============================================== * InscriberConfigBuilder * @classdesc This is to build the config * to be used when making the config file. * *=============================================**/ var InscriberConfigBuilder = /** @class */ (function () { /**======================= * END OF CONSTANT *========================**/ /**============================================== * CONSTRUCTOR *=============================================**/ function InscriberConfigBuilder() { this.config = new InscriberConfig_1.InscriberConfig()._config; this.config["overwrite-config"] = true; } /**============================================== * END OF CONSTRUCTOR *=============================================**/ // SECTION Time Pattern /**============================================== * Time Pattern * @summary Sets the time pattern that the log types should be using * for <time> property in the logs. * @param pattern The time pattern. *=============================================**/ InscriberConfigBuilder.prototype.timePattern = function (pattern) { if (pattern === void 0) { pattern = "MMMM Do YYYY, h:mm:ss a"; } this.config["time-pattern"] = pattern; return this; }; // !SECTION Time Pattern // SECTION One File /**============================================== * One File * @summary Sets the one file option in the config * file. This will force all the log types to write * logs to one file, for that day. * * @param on - Whether to be on or not. By Default * its off. *=============================================**/ InscriberConfigBuilder.prototype.oneFile = function (on) { if (on === void 0) { on = true; } this.config["one-file"] = on; return this; }; // !SECTION One File // SECTION Write File /**============================================== * Write File * @summary Sets the write file option in the config * file. This will make Inscriber to write logs * for each of the log types. * * @param on - Whether to be on or not. By Default * its off. *=============================================**/ InscriberConfigBuilder.prototype.writeFile = function (on) { if (on === void 0) { on = true; } this.config["write-logs"] = on; return this; }; // !SECTION Write File // SECTION Log Patterns /**============================================== * Log Patterns * @summary Sets the log patterns option in the * config. This will set what the log types will * display when executed. * * @param patterns - The patterns for each of the log types. *=============================================**/ InscriberConfigBuilder.prototype.logPatterns = function (_a) { var _b = _a.error, error = _b === void 0 ? "(<time>) => [<source>]: <message>" : _b, _c = _a.info, info = _c === void 0 ? "(<time>) => [<source>]: <message>" : _c, _d = _a.debug, debug = _d === void 0 ? "(<time>) => [<source>]: <message>" : _d, _e = _a.warn, warn = _e === void 0 ? "(<time>) => [<source>]: <message>" : _e; this.config["log-patterns"] = { error: error, info: info, debug: debug, warn: warn, }; return this; }; // !SECTION Log Patterns // SECTION Log Colors /**============================================== * Log Colors * @summary Sets the log colors option in the * config. This will change the colors of the log * types, when being displayed on in the console. * * @param colors - The colors of the log types. *=============================================**/ InscriberConfigBuilder.prototype.logColors = function (_a) { var _b = _a.error, error = _b === void 0 ? { text: "black", background: "red", } : _b, _c = _a.info, info = _c === void 0 ? { text: "black", background: "white", } : _c, _d = _a.debug, debug = _d === void 0 ? { text: "black", background: "green", } : _d, _e = _a.warn, warn = _e === void 0 ? { text: "black", background: "yellow", } : _e; this.config["log-colors"] = { error: error, info: info, debug: debug, warn: warn, }; return this; }; // !SECTION Log Colors // SECTION Log Paths /**============================================== * Log Paths * @summary This will set the log paths option * in the config file. This will direct all the * log files for the certain log type to that * location, unless the one file option is enabled, * then it will direct it to the info type's path. * * @param paths - The paths of each of the log types. * *=============================================**/ InscriberConfigBuilder.prototype.logPaths = function (_a) { var _b = _a.error, error = _b === void 0 ? "./Logs/error" : _b, _c = _a.info, info = _c === void 0 ? "./Logs/info" : _c, _d = _a.debug, debug = _d === void 0 ? "./Logs/debug" : _d, _e = _a.warn, warn = _e === void 0 ? "./Logs/warn" : _e; this.config["log-paths"] = { error: error, info: info, debug: debug, warn: warn, }; return this; }; InscriberConfigBuilder.prototype.addCustomLog = function (logConfig) { this.config["custom-logs"].push({ name: logConfig.name, aliases: logConfig.aliases, path: logConfig.path, color: logConfig.color, pattern: logConfig.pattern, }); return this; }; // !SECTION Log Paths // SECTION Build /**======================================================================== * Build * @summary Builds the Config. * @example <caption>How the builder works.</caption> * * ```js * new InscriberConfigBuilder.logPaths({error: "./src/Logs/errors"}).build(); * ``` * @returns {Config} - the config that will be used when creating the file. *========================================================================**/ InscriberConfigBuilder.prototype.build = function () { return this.config; }; return InscriberConfigBuilder; })(); exports.InscriberConfigBuilder = InscriberConfigBuilder;