@kcutils/logger
Version:
Another Logger Service
189 lines • 6.79 kB
JavaScript
"use strict";
/**
* @packageDocumentation
* @module Logger.Builders
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.LoggerOptionBuilder = void 0;
var figures_1 = require("figures");
var LoggerOption_1 = require("../models/logger/LoggerOption");
var helper_1 = require("@kcutils/helper");
var LoggerOptionBuilder = /** @class */ (function () {
function LoggerOptionBuilder() {
this.debug = false;
this.output = ["console"];
this.json = false;
this.interactive = false;
this.disabled = false;
this.color = true;
this.level = "info";
this.datetime = "date";
this.censor = function () { return "secure"; };
this.separator = figures_1.arrowRight;
this.scopes = [];
this.secrets = [];
this.overrideStream = false;
this.streams = [];
this.types = undefined;
this.settings = undefined;
}
LoggerOptionBuilder.initial = function () {
return new LoggerOptionBuilder();
};
LoggerOptionBuilder.load = function (option) {
var builder = LoggerOptionBuilder.initial();
if (helper_1.generic.isExist(option.debug))
builder.withDebug(option.debug);
if (helper_1.generic.isExist(option.output))
builder.withOutput(option.output);
if (helper_1.generic.isExist(option.json))
builder.withJson(option.json);
if (helper_1.generic.isExist(option.interactive))
builder.withInteractive(option.interactive);
if (helper_1.generic.isExist(option.disabled))
builder.withDisabled(option.disabled);
if (helper_1.generic.isExist(option.color))
builder.withColor(option.color);
if (helper_1.generic.isExist(option.level))
builder.withLevel(option.level);
if (helper_1.generic.isExist(option.datetime))
builder.withDatetime(option.datetime);
if (helper_1.generic.isExist(option.censor))
builder.withCensor(option.censor);
if (helper_1.generic.isExist(option.separator))
builder.withSeparator(option.separator);
if (helper_1.generic.isExist(option.scopes))
builder.withScopes(option.scopes);
if (helper_1.generic.isExist(option.secrets))
builder.withSecrets(option.secrets);
if (helper_1.generic.isExist(option.streams))
builder.withOverrideStream(helper_1.array.toArray(option.streams));
return builder;
};
LoggerOptionBuilder.prototype.withDebug = function (toggle) {
if (toggle === void 0) { toggle = true; }
this.debug = toggle;
return this;
};
LoggerOptionBuilder.prototype.withJson = function (toggle) {
if (toggle === void 0) { toggle = true; }
this.json = toggle;
return this;
};
LoggerOptionBuilder.prototype.withInteractive = function (toggle) {
if (toggle === void 0) { toggle = true; }
this.interactive = toggle;
return this;
};
LoggerOptionBuilder.prototype.withDisabled = function (toggle) {
if (toggle === void 0) { toggle = true; }
this.disabled = toggle;
return this;
};
LoggerOptionBuilder.prototype.withColor = function (toggle) {
if (toggle === void 0) { toggle = true; }
this.color = toggle;
return this;
};
LoggerOptionBuilder.prototype.withoutColor = function () {
return this.withColor(false);
};
LoggerOptionBuilder.prototype.withLevel = function (level) {
this.level = level;
return this;
};
LoggerOptionBuilder.prototype.withDatetime = function (type) {
this.datetime = type;
return this;
};
LoggerOptionBuilder.prototype.withCensor = function (censor) {
this.censor = censor;
return this;
};
LoggerOptionBuilder.prototype.withSeparator = function (separator) {
this.separator = separator;
return this;
};
LoggerOptionBuilder.prototype.withScopes = function (scopes) {
this.scopes = scopes;
return this;
};
LoggerOptionBuilder.prototype.withSecrets = function (secrets) {
this.secrets = secrets;
return this;
};
LoggerOptionBuilder.prototype.withOverrideStream = function (streams) {
this.overrideStream = true;
this.streams = streams;
return this;
};
LoggerOptionBuilder.prototype.withoutOverrideStream = function () {
this.overrideStream = false;
this.streams = [];
return this;
};
LoggerOptionBuilder.prototype.withOutput = function (output) {
this.output = output;
return this;
};
LoggerOptionBuilder.prototype.withType = function (name, builder) {
var _a;
if (helper_1.generic.noExist(this.types))
this.types = (_a = {},
_a[name] = builder.get(),
_a);
else
this.types[name] = builder.get();
return this;
};
LoggerOptionBuilder.prototype.withRawType = function (types) {
this.types = types;
return this;
};
LoggerOptionBuilder.prototype.withSetting = function (name, builder) {
var _a;
if (helper_1.generic.noExist(this.settings))
this.settings = (_a = {},
_a[name] = builder.get(),
_a);
else
this.settings[name] = builder.get();
return this;
};
LoggerOptionBuilder.prototype.withRawSetting = function (settings) {
this.settings = settings;
return this;
};
/**
* always create new object
*/
LoggerOptionBuilder.prototype.get = function () {
var opts = {};
if (helper_1.generic.nonEmpty(this.types))
opts["types"] = this.types;
if (helper_1.generic.nonEmpty(this.settings))
opts["settings"] = this.settings;
return new LoggerOption_1.LoggerOption(this.internalGet(), opts);
};
LoggerOptionBuilder.prototype.internalGet = function () {
return {
debug: this.debug,
output: this.output,
json: this.json,
interactive: this.interactive,
disabled: this.disabled,
color: this.color,
level: this.level,
datetime: this.datetime,
censor: this.censor,
separator: this.separator,
scopes: this.scopes,
secrets: this.secrets,
overrideStream: this.overrideStream,
streams: this.streams,
};
};
return LoggerOptionBuilder;
}());
exports.LoggerOptionBuilder = LoggerOptionBuilder;
//# sourceMappingURL=LoggerOptionBuilder.js.map