UNPKG

@visulima/pail

Version:

Highly configurable Logger for Node.js, Edge and Browser.

56 lines (53 loc) 1.67 kB
import { serializeError } from '@visulima/error/error'; import { E as EMPTY_SYMBOL } from './constants-BYYZ5WNW.mjs'; 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, 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 === EMPTY_SYMBOL) { rest.message = void 0; } else { rest.message = message; } if (error) { rest.error = serializeError(error, this.errorOptions); } if (context) { const newContext = []; for (const item of context) { if (item === EMPTY_SYMBOL) { continue; } if (item instanceof Error) { newContext.push(serializeError(item, this.errorOptions)); } else { newContext.push(item); } } rest.context = newContext; } this._log(this.stringify(rest), type.level); } } export { AbstractJsonReporter as A };