apitally
Version:
Simple API monitoring & analytics for REST APIs built with Express, Fastify, NestJS, AdonisJS, Hono, H3, Elysia, Hapi, and Koa.
71 lines • 1.78 kB
JavaScript
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
import { formatMessage } from "./utils.js";
const MAX_BUFFER_SIZE = 1e3;
let isPatched = false;
let globalLogsContext;
async function patchNestLogger(logsContext) {
globalLogsContext = logsContext;
if (isPatched) {
return;
}
try {
const { Logger } = await import(
/* webpackIgnore: true */
"@nestjs/common"
);
const logMethods = [
"log",
"error",
"warn",
"debug",
"verbose",
"fatal"
];
logMethods.forEach((method) => {
const originalMethod = Logger[method];
Logger[method] = function(message, ...args) {
captureLog(method, [
message,
...args
]);
return originalMethod.apply(Logger, [
message,
...args
]);
};
});
logMethods.forEach((method) => {
const originalMethod = Logger.prototype[method];
Logger.prototype[method] = function(message, ...args) {
captureLog(method, [
message,
...args
], this.context);
return originalMethod.apply(this, [
message,
...args
]);
};
});
isPatched = true;
} catch {
}
}
__name(patchNestLogger, "patchNestLogger");
function captureLog(level, args, context) {
const logs = globalLogsContext == null ? void 0 : globalLogsContext.getStore();
if (logs && logs.length < MAX_BUFFER_SIZE) {
logs.push({
timestamp: Date.now() / 1e3,
logger: context,
level,
message: formatMessage(args[0], ...args.slice(1))
});
}
}
__name(captureLog, "captureLog");
export {
patchNestLogger
};
//# sourceMappingURL=nestjs.js.map