@visulima/pail
Version:
Highly configurable Logger for Node.js, Edge and Browser.
58 lines (54 loc) • 1.73 kB
JavaScript
;
const error = require('@visulima/error/error');
const constants = require('./constants-DHfYGxxG.cjs');
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
class AbstractJsonReporter {
static {
__name(this, "AbstractJsonReporter");
}
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
stringify;
errorOptions;
constructor(options = {}) {
this.errorOptions = options.error ?? {};
}
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
setStringify(function_) {
this.stringify = function_;
}
// eslint-disable-next-line sonarjs/cognitive-complexity
log(meta) {
const { context, error: error$1, file, message, type, ...rest } = meta;
if (rest.label) {
rest.label = rest.label.trim();
}
if (file) {
rest.file = file.name + ":" + file.line + (file.column ? ":" + file.column : "");
}
if (message === constants.EMPTY_SYMBOL) {
rest.message = void 0;
} else {
rest.message = message;
}
if (error$1) {
rest.error = error.serializeError(error$1, this.errorOptions);
}
if (context) {
const newContext = [];
for (const item of context) {
if (item === constants.EMPTY_SYMBOL) {
continue;
}
if (item instanceof Error) {
newContext.push(error.serializeError(item, this.errorOptions));
} else {
newContext.push(item);
}
}
rest.context = newContext;
}
this._log(this.stringify(rest), type.level);
}
}
exports.AbstractJsonReporter = AbstractJsonReporter;