UNPKG

apitally

Version:

Simple API monitoring & analytics for REST APIs built with Express, Fastify, NestJS, AdonisJS, Hono, H3, Elysia, Hapi, and Koa.

46 lines (45 loc) 1.13 kB
var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); // src/loggers/console.ts import { format } from "util"; var MAX_BUFFER_SIZE = 1e3; var isPatched = false; var globalLogsContext; function patchConsole(logsContext) { globalLogsContext = logsContext; if (isPatched) { return; } const logMethods = [ "log", "warn", "error", "info", "debug" ]; logMethods.forEach((method) => { const originalMethod = console[method]; console[method] = function(...args) { captureLog(method, args); return originalMethod.apply(console, args); }; }); isPatched = true; } __name(patchConsole, "patchConsole"); function captureLog(level, args) { const logs = globalLogsContext == null ? void 0 : globalLogsContext.getStore(); if (logs && logs.length < MAX_BUFFER_SIZE) { logs.push({ timestamp: Date.now() / 1e3, logger: "console", level, message: format(...args) }); } } __name(captureLog, "captureLog"); export { patchConsole }; //# sourceMappingURL=console.js.map