apitally
Version:
Simple API monitoring & analytics for REST APIs built with Express, Fastify, NestJS, AdonisJS, Hono, H3, Elysia, Hapi, and Koa.
1 lines • 1.58 kB
Source Map (JSON)
{"version":3,"sources":["../../src/loggers/hapi.ts"],"sourcesContent":["import type { RequestEvent } from \"@hapi/hapi\";\nimport { AsyncLocalStorage } from \"node:async_hooks\";\nimport { format } from \"node:util\";\n\nimport type { LogRecord } from \"../common/requestLogger.js\";\n\nconst MAX_BUFFER_SIZE = 1000;\nconst VALID_LOG_LEVELS = new Set<string>([\n \"trace\",\n \"debug\",\n \"info\",\n \"warn\",\n \"warning\",\n \"error\",\n \"fatal\",\n]);\n\nexport function handleHapiRequestEvent(\n event: RequestEvent,\n logsContext: AsyncLocalStorage<LogRecord[]>,\n) {\n const logs = logsContext.getStore();\n if (!logs || logs.length >= MAX_BUFFER_SIZE) {\n return;\n }\n\n logs.push({\n timestamp: Number(event.timestamp) / 1000,\n level:\n event.tags.find((tag) => VALID_LOG_LEVELS.has(tag.toLowerCase())) ||\n \"log\",\n message: format(event.data),\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAEA;;;;;uBAAuB;AAIvB,IAAMA,kBAAkB;AACxB,IAAMC,mBAAmB,oBAAIC,IAAY;EACvC;EACA;EACA;EACA;EACA;EACA;EACA;CACD;AAEM,SAASC,uBACdC,OACAC,aAA2C;AAE3C,QAAMC,OAAOD,YAAYE,SAAQ;AACjC,MAAI,CAACD,QAAQA,KAAKE,UAAUR,iBAAiB;AAC3C;EACF;AAEAM,OAAKG,KAAK;IACRC,WAAWC,OAAOP,MAAMM,SAAS,IAAI;IACrCE,OACER,MAAMS,KAAKC,KAAK,CAACC,QAAQd,iBAAiBe,IAAID,IAAIE,YAAW,CAAA,CAAA,KAC7D;IACFC,aAASC,yBAAOf,MAAMgB,IAAI;EAC5B,CAAA;AACF;AAhBgBjB;","names":["MAX_BUFFER_SIZE","VALID_LOG_LEVELS","Set","handleHapiRequestEvent","event","logsContext","logs","getStore","length","push","timestamp","Number","level","tags","find","tag","has","toLowerCase","message","format","data"]}