@koreanpanda/inscriber
Version:
A Logger that can write logs, and print them, with full customization.
182 lines (181 loc) • 6.88 kB
JavaScript
;
/**========================================================================
* ? ABOUT
* @author : Cody Spratford
* @email : koreanpanda345@gmail.com
* @repo : https://github.com/koreanpanda345/Inscriber
* @createdOn : 11/14/2020
* @description : This is Inscriber. Inscriber is NPM Logging Package
* that is fully customizable.
* @since : 11/21/2020
* @license
* Copyright 2020 Cody Spratford. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file in the root directory of this source tree.
*========================================================================**/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Inscriber = void 0;
/**======================
* IMPORTS
*========================**/
var exports_1 = require("./classes/exports");
var Log_1 = require("./classes/Log");
var InscriberConfig_1 = require("./InscriberConfig");
/**======================
* END OF IMPORTS
*========================**/
/**========================================================================
* Inscriber
* This is the main class of Inscriber. This handles all methods
* that the users will be using.
* TODO Add warn and debug methods.
*========================================================================**/
var Inscriber = /** @class */ (function () {
/**========================================================================
* Defining Configurations for the First time.
* @example <caption>Using Default settings for the first time.</caption>
*
* ```js
* const inscriber = new Inscriber();
* ```
* @example <caption>Using Config Builder for the first time.</caption>
*
* ```js
* const inscriber = new Inscriber(new InscriberConfigBuilder().build);
* ```
* NOTE : InscriberConfigBuilder will overwrite the current config file.
*
*========================================================================**/
function Inscriber(config) {
if (config != undefined) {
var _config = new InscriberConfig_1.InscriberConfig();
_config.UseBuilder(config);
_config.loadConfig();
}
}
/**==============================================
*
* @param content the error.
* @example <caption>String Error</caption>
* inscriber.error("This is a error");
* @example <caption>Object Error</caption>
* const error = { success: false, code: 404, errorType: "NOT_FOUND" };
* inscriber.error(error);
* @example <caption>Error Constructor</caption>
* inscriber.error(new Error("This is an error."));
* @example <caption>Type Error Constructor</caption>
* inscriber.error(new TypeError("This is a type error."));
* @example <caption>Syntax Error</caption>
* inscriber.error(new SyntaxError("This is a syntax error."));
* @example <caption>Eval Error</caption>
* inscriber.error(new EvalError("This is a eval error."));
*
* NOTE Not all Errors are supported. I only added
* the common JS errors, or Javascript only Errors.
*
* TODO Add Support for other error types.
*=============================================**/
Inscriber.prototype.error = function (content) {
var _a, _b;
new exports_1.ErrorClass(
new InscriberConfig_1.InscriberConfig().loadConfig(),
content,
((_a = require.main) === null || _a === void 0 ? void 0 : _a.filename) == undefined
? ""
: (_b = require.main) === null || _b === void 0
? void 0
: _b.filename,
);
};
/**==============================================
*
* @param content the info.
* @example <caption>String Info</caption>
* inscriber.info("This is a info log");
* @example <caption>Object Info</caption>
* const info = {desc: "Something", name: "Name"};
* inscriber.info(info);
*
*=============================================**/
Inscriber.prototype.info = function (content) {
var _a, _b;
new exports_1.InfoClass(
new InscriberConfig_1.InscriberConfig().loadConfig(),
content,
((_a = require.main) === null || _a === void 0 ? void 0 : _a.filename) == undefined
? ""
: (_b = require.main) === null || _b === void 0
? void 0
: _b.filename,
);
};
/**==============================================
*
* @param content the debug.
* @example <caption>String Debug</caption>
*
* ```js
* inscriber.debug("This is a debug log.");
* ```
* @example <caption>Object Debug</caption>
*
* ```js
* const debug = {process: "something", next: () => dosomething()};
* inscriber.debug(debug);
* ```
*=============================================**/
Inscriber.prototype.debug = function (content) {
var _a, _b;
new exports_1.DebugClass(
new InscriberConfig_1.InscriberConfig().loadConfig(),
content,
((_a = require.main) === null || _a === void 0 ? void 0 : _a.filename) == undefined
? ""
: (_b = require.main) === null || _b === void 0
? void 0
: _b.filename,
);
};
/**==============================================
*
* @param content the warn
* @example
*
* ```js
* inscriber.warn("This is a warn log.");
* ```
*
* @example
*
* ```js
* const warn = {warn: "Waring", reason: "Something"};
* inscriber.warn(warn);
* ```
*=============================================**/
Inscriber.prototype.warn = function (content) {
var _a, _b;
new exports_1.WarnClass(
new InscriberConfig_1.InscriberConfig().loadConfig(),
content,
((_a = require.main) === null || _a === void 0 ? void 0 : _a.filename) == undefined
? ""
: (_b = require.main) === null || _b === void 0
? void 0
: _b.filename,
);
};
Inscriber.prototype.log = function (content, type) {
var _a, _b;
new Log_1.LogMethod(
new InscriberConfig_1.InscriberConfig().loadConfig(),
content,
(_b = (_a = require.main) === null || _a === void 0 ? void 0 : _a.filename) !== null && _b !== void 0
? _b
: "",
type,
);
};
return Inscriber;
})();
exports.Inscriber = Inscriber;