@visulima/pail
Version:
Highly configurable Logger for Node.js, Edge and Browser.
61 lines (57 loc) • 1.78 kB
JavaScript
;
var __defProp$1 = Object.defineProperty;
var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
const getCallerFilename = /* @__PURE__ */ __name$1(() => {
const errorStack = Error.prepareStackTrace;
try {
let result = [];
Error.prepareStackTrace = (_error, stack) => {
const callSitesWithoutCurrent = stack.slice(1);
result = callSitesWithoutCurrent;
return callSitesWithoutCurrent;
};
const callers = result.reduce((accumulator, x) => {
if (x.isNative() || x.getFileName()?.includes("pail/dist")) {
return accumulator;
}
accumulator.push({
columnNumber: x.getColumnNumber(),
fileName: x.getFileName(),
lineNumber: x.getLineNumber()
});
return accumulator;
}, []);
const firstExternalFilePath = callers[0];
if (firstExternalFilePath) {
return {
columnNumber: firstExternalFilePath.columnNumber ?? void 0,
fileName: firstExternalFilePath.fileName,
lineNumber: firstExternalFilePath.lineNumber ?? void 0
};
}
return {
fileName: "anonymous",
lineNumber: void 0
};
} finally {
Error.prepareStackTrace = errorStack;
}
}, "getCallerFilename");
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
class CallerProcessor {
static {
__name(this, "CallerProcessor");
}
// eslint-disable-next-line class-methods-use-this
process(meta) {
const { columnNumber, fileName, lineNumber } = getCallerFilename();
meta.file = {
column: columnNumber,
line: lineNumber,
name: fileName
};
return meta;
}
}
module.exports = CallerProcessor;