@tanngo11/log 0.6.1 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/bullmq.cjs.map +1 -1
  3. package/dist/bullmq.d.cts +1 -1
  4. package/dist/bullmq.d.ts +1 -1
  5. package/dist/bullmq.js +2 -2
  6. package/dist/{chunk-URPHVC4Y.js → chunk-2IIUQFMK.js} +2 -2
  7. package/dist/{chunk-AF4YR4Y4.js → chunk-BFMFXDIJ.js} +5 -9
  8. package/dist/chunk-BFMFXDIJ.js.map +1 -0
  9. package/dist/{chunk-UOIJCSP5.js → chunk-EZCIMEVL.js} +3 -3
  10. package/dist/{chunk-UDS6S22P.js → chunk-JKCR57WJ.js} +25 -9
  11. package/dist/chunk-JKCR57WJ.js.map +1 -0
  12. package/dist/{chunk-2WNGXGP7.js → chunk-MGAEY7UZ.js} +2 -2
  13. package/dist/{chunk-RVETZAK5.js → chunk-RQWNJJIT.js} +3 -3
  14. package/dist/express.cjs +23 -16
  15. package/dist/express.cjs.map +1 -1
  16. package/dist/express.d.cts +2 -2
  17. package/dist/express.d.ts +2 -2
  18. package/dist/express.js +3 -3
  19. package/dist/fastify.cjs +23 -16
  20. package/dist/fastify.cjs.map +1 -1
  21. package/dist/fastify.d.cts +2 -2
  22. package/dist/fastify.d.ts +2 -2
  23. package/dist/fastify.js +3 -3
  24. package/dist/{http-44ztBSXk.d.ts → http-Dp6Qtr9M.d.ts} +1 -1
  25. package/dist/{http-BQJkHBwQ.d.cts → http-eeog5tR8.d.cts} +1 -1
  26. package/dist/index.cjs +27 -14
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +11 -4
  29. package/dist/index.d.ts +11 -4
  30. package/dist/index.js +4 -4
  31. package/dist/{logger-3Co9eVJf.d.cts → logger-CtlC9SUE.d.cts} +3 -2
  32. package/dist/{logger-3Co9eVJf.d.ts → logger-CtlC9SUE.d.ts} +3 -2
  33. package/dist/nest.cjs +23 -16
  34. package/dist/nest.cjs.map +1 -1
  35. package/dist/nest.d.cts +2 -2
  36. package/dist/nest.d.ts +2 -2
  37. package/dist/nest.js +4 -4
  38. package/dist/next.cjs +23 -16
  39. package/dist/next.cjs.map +1 -1
  40. package/dist/next.d.cts +2 -2
  41. package/dist/next.d.ts +2 -2
  42. package/dist/next.js +3 -3
  43. package/dist/prisma.d.cts +1 -1
  44. package/dist/prisma.d.ts +1 -1
  45. package/dist/strapi.cjs +23 -11
  46. package/dist/strapi.cjs.map +1 -1
  47. package/dist/strapi.d.cts +2 -2
  48. package/dist/strapi.d.ts +2 -2
  49. package/dist/strapi.js +2 -2
  50. package/package.json +1 -1
  51. package/dist/chunk-AF4YR4Y4.js.map +0 -1
  52. package/dist/chunk-UDS6S22P.js.map +0 -1
  53. /package/dist/{chunk-URPHVC4Y.js.map → chunk-2IIUQFMK.js.map} +0 -0
  54. /package/dist/{chunk-UOIJCSP5.js.map → chunk-EZCIMEVL.js.map} +0 -0
  55. /package/dist/{chunk-2WNGXGP7.js.map → chunk-MGAEY7UZ.js.map} +0 -0
  56. /package/dist/{chunk-RVETZAK5.js.map → chunk-RQWNJJIT.js.map} +0 -0
package/dist/nest.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/nest.ts","../src/context.ts","../src/global.ts","../src/redact.ts","../src/error.ts","../src/normalize.ts","../src/request-id.ts","../src/http.ts","../src/express.ts","../src/fastify.ts"],"sourcesContent":["import type { CallHandler, ExecutionContext, LoggerService, NestInterceptor } from \"@nestjs/common\";\nimport { catchError, throwError, type Observable } from \"rxjs\";\nimport { currentStore, recordError, recordErrorIn, storeOf } from \"./context\";\nimport { requestLogger as expressRequestLogger } from \"./express\";\nimport { fastifyLogger } from \"./fastify\";\nimport type { HttpLogOptions } from \"./http\";\nimport type { Level } from \"./levels\";\nimport type { Logger } from \"./logger\";\nimport type { Fields } from \"./normalize\";\n\nexport { requestLogger } from \"./express\";\nexport { fastifyLogger } from \"./fastify\";\n\nconst STACK_RE = /\\n\\s+at /;\n\n/** Routes Nest's own logs (bootstrap, ExceptionsHandler, Logger calls) into the JSON logger. */\nexport class NestLogger implements LoggerService {\n constructor(private readonly logger: Logger) {}\n\n log(message: unknown, ...params: unknown[]): void {\n this.emit(\"info\", message, params);\n }\n error(message: unknown, ...params: unknown[]): void {\n this.emit(\"error\", message, params);\n }\n warn(message: unknown, ...params: unknown[]): void {\n this.emit(\"warn\", message, params);\n }\n debug(message: unknown, ...params: unknown[]): void {\n this.emit(\"debug\", message, params);\n }\n verbose(message: unknown, ...params: unknown[]): void {\n this.emit(\"trace\", message, params);\n }\n fatal(message: unknown, ...params: unknown[]): void {\n this.emit(\"fatal\", message, params);\n }\n\n private emit(level: Level, message: unknown, params: unknown[]): void {\n const rest = [...params];\n const last = rest[rest.length - 1];\n const nestContext = typeof last === \"string\" && !STACK_RE.test(last) ? (rest.pop() as string) : undefined;\n const stack = typeof rest[0] === \"string\" && STACK_RE.test(rest[0]) ? (rest.shift() as string) : undefined;\n\n // Nest's ExceptionsHandler logs unhandled errors; the http.request line already carries\n // them, so hand the error to the request instead of writing a second error line.\n const store = currentStore();\n if (nestContext === \"ExceptionsHandler\" && store?.fields.request_id !== undefined) {\n if (store.error === undefined) {\n const e = message instanceof Error ? message : Object.assign(new Error(String(message)), { stack });\n recordErrorIn(store, e);\n }\n return;\n }\n\n const fields: Fields = { nest_context: nestContext };\n // Extra arguments: objects become fields, errors become err, anything else goes to nest_args.\n const extras: unknown[] = [];\n for (const arg of rest) {\n if (arg instanceof Error && fields.err === undefined) fields.err = arg;\n else if (typeof arg === \"object\" && arg !== null && !Array.isArray(arg)) Object.assign(fields, arg);\n else extras.push(arg);\n }\n if (extras.length > 0) fields.nest_args = extras;\n let text: string;\n if (message instanceof Error) {\n fields.err = message;\n text = message.message;\n } else if (typeof message === \"object\" && message !== null) {\n fields.nest_payload = message;\n text = \"nest log\";\n } else {\n text = String(message);\n }\n if (stack !== undefined) fields.err_stack = stack;\n this.logger[level](text, fields);\n }\n}\n\n/** Records request errors for the http.request line, then rethrows to Nest's exception filters. */\nexport class ErrorRecorderInterceptor implements NestInterceptor {\n intercept(context: ExecutionContext, next: CallHandler): Observable<unknown> {\n return next.handle().pipe(\n catchError((err: unknown) => {\n const store = storeOf(context.switchToHttp().getResponse());\n if (store) recordErrorIn(store, err);\n else recordError(err);\n return throwError(() => err);\n }),\n );\n }\n}\n\n\n/** The parts of a Nest application that setupNestLogging needs, for either HTTP adapter. */\nexport interface NestAppLike {\n getHttpAdapter(): { getType(): string };\n useGlobalInterceptors(...interceptors: NestInterceptor[]): unknown;\n use?(...args: unknown[]): unknown;\n register?(...args: unknown[]): Promise<unknown>;\n}\n\n/**\n * One-call setup for Express and Fastify Nest apps: request context, the http.request line and\n * error recording. Call before `app.listen()`.\n */\nexport async function setupNestLogging(app: NestAppLike, log: Logger, opts: HttpLogOptions = {}): Promise<void> {\n const type = app.getHttpAdapter().getType();\n if (type === \"fastify\") {\n if (!app.register) throw new Error(\"setupNestLogging: Fastify app has no register()\");\n await app.register(fastifyLogger, { ...opts, log });\n } else {\n if (!app.use) throw new Error(\"setupNestLogging: app has no use()\");\n app.use(expressRequestLogger(log, opts));\n }\n app.useGlobalInterceptors(new ErrorRecorderInterceptor());\n}\n","import { AsyncLocalStorage } from \"node:async_hooks\";\nimport { globalSingleton } from \"./global\";\nimport type { Fields } from \"./normalize\";\n\nexport interface ContextStore {\n fields: Fields;\n error?: unknown;\n /** Route template captured while the router still knew it (Express error path). */\n route?: string;\n parent?: ContextStore;\n}\n\nconst als = globalSingleton(\"als\", () => new AsyncLocalStorage<ContextStore>());\n\nexport const STORE_KEY: symbol = Symbol.for(\"@tanngo11/log.store\");\n\nexport function runWithStore<T>(fields: Fields, fn: (store: ContextStore) => T): T {\n const parent = als.getStore();\n const store: ContextStore = { fields: { ...parent?.fields, ...fields }, parent };\n return als.run(store, () => fn(store));\n}\n\nexport function withContext<T>(fields: Fields, fn: () => T): T {\n return runWithStore(fields, () => fn());\n}\n\nexport function currentStore(): ContextStore | undefined {\n return als.getStore();\n}\n\nexport function getContext(): Fields {\n return als.getStore()?.fields ?? {};\n}\n\n// Applies to the current context and every enclosing one, so a field added inside a nested\n// withContext/runJob still reaches the request's http.request line.\nexport function addContext(fields: Fields): void {\n for (let s = als.getStore(); s; s = s.parent) Object.assign(s.fields, fields);\n}\n\n// Sets the error on the store and on enclosing stores that have none yet.\nexport function recordErrorIn(store: ContextStore, err: unknown): void {\n store.error = err;\n for (let s = store.parent; s; s = s.parent) if (s.error === undefined) s.error = err;\n}\n\n// Marks the error that the current request/job summary line should carry. Does not write a line.\nexport function recordError(err: unknown): void {\n const store = als.getStore();\n if (store) recordErrorIn(store, err);\n}\n\nexport function attachStore(target: object, store: ContextStore): void {\n (target as Record<symbol, ContextStore>)[STORE_KEY] = store;\n}\n\nexport function storeOf(target: unknown): ContextStore | undefined {\n if (typeof target !== \"object\" || target === null) return undefined;\n return (target as Record<symbol, ContextStore | undefined>)[STORE_KEY];\n}\n","// Singletons shared by every copy of this package loaded in the process (ESM and CJS builds,\n// or duplicated installs), so context and dedupe state never split.\nexport function globalSingleton<T>(name: string, make: () => T): T {\n const key = Symbol.for(`@tanngo11/log.${name}`);\n const g = globalThis as unknown as Record<symbol, T | undefined>;\n let value = g[key];\n if (value === undefined) {\n value = make();\n g[key] = value;\n }\n return value;\n}\n","// Redaction shared by the logger and the error serializer. The collector redacts again,\n// but it cannot see secrets inside JSON-encoded strings, so the app side must catch them.\n\nexport const DEFAULT_REDACT_KEYS = [\n \"password\", \"passwd\", \"pwd\", \"passphrase\", \"secret\", \"client_secret\",\n \"token\", \"access_token\", \"refresh_token\", \"id_token\", \"auth_token\",\n \"api_key\", \"apikey\", \"access_key\", \"secret_key\", \"private_key\",\n \"authorization\", \"cookie\", \"set_cookie\", \"session_id\", \"sessionid\",\n \"credential\", \"credentials\", \"dsn\", \"connection_string\", \"conn_string\", \"jwt\", \"bearer\",\n];\n\n/** Opt-in value patterns for `redactValues`. Not on by default: they can hit ordinary numbers. */\nexport const REDACT_PATTERNS = {\n /**\n * Vietnamese mobile numbers: 0912345678, +84912345678, 84912345678. Letters on either side\n * rule a match out, so hex ids (a UUID segment such as 0912345678e0) are left alone.\n */\n phoneVN: /(?<![\\dA-Za-z+])(?:\\+?84|0)[35789]\\d{8}(?![\\dA-Za-z])/g,\n /** Visa, Mastercard, Amex, Discover-like card numbers, with optional spaces or dashes. */\n paymentCard: /(?<!\\d)(?:4\\d{3}|5[1-5]\\d{2}|2[2-7]\\d{2}|3[47]\\d{2}|6(?:011|5\\d{2}))(?:[ -]?\\d{4}){2}[ -]?\\d{1,4}(?!\\d)/g,\n /** IPv4 addresses. */\n ipv4: /(?<![\\d.])(?:\\d{1,3}\\.){3}\\d{1,3}(?![\\d.])/g,\n} as const;\n\n// Keys that only describe a secret (count, type, timestamps, flags) stay readable.\nconst SAFE_SUFFIXES = [\"_count\", \"_type\", \"_length\", \"_expires_at\", \"_expires_in\", \"_ttl\", \"_at\", \"_ms\", \"_enabled\"];\n\nexport const REDACTED = \"[REDACTED]\";\n\nexport function toSnakeCase(key: string): string {\n return key\n .replace(/([a-z0-9])([A-Z])/g, \"$1_$2\")\n .replace(/([A-Z]+)([A-Z][a-z])/g, \"$1_$2\")\n .replace(/[^A-Za-z0-9_]+/g, \"_\")\n .toLowerCase();\n}\n\nconst URL_CREDENTIALS_RE = /([a-z][a-z0-9+.-]*:\\/\\/)[^\\s/@:\"']+:[^\\s/@\"']+@/gi;\nconst BEARER_RE = /\\bBearer\\s+[A-Za-z0-9._~+/=-]+/gi;\nconst JWT_RE = /\\beyJ[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+/g;\nconst EMAIL_RE = /[A-Za-z0-9._%+-]+@([A-Za-z0-9-]+(?:\\.[A-Za-z0-9-]+)*\\.[A-Za-z]{2,})/g;\n\nexport type KeyPattern = string | RegExp;\n\nexport interface RedactorOptions {\n /** Extra sensitive keys: names (matched like the defaults) or patterns tested on the snake_case key. */\n keys?: readonly KeyPattern[];\n /** Extra value patterns; every match inside any string becomes [REDACTED]. */\n values?: readonly RegExp[];\n}\n\nexport interface Redactor {\n isSensitive(key: string): boolean;\n /** Masks secrets and emails that appear inside free text. */\n scrub(s: string): string;\n /** JSON.stringify that redacts sensitive keys at any depth and never throws. */\n json(value: unknown): string;\n}\n\nfunction globalize(re: RegExp): RegExp {\n return re.flags.includes(\"g\") ? new RegExp(re.source, re.flags) : new RegExp(re.source, `${re.flags}g`);\n}\n\nexport function createRedactor(opts: RedactorOptions = {}): Redactor {\n const words = [...DEFAULT_REDACT_KEYS];\n const keyPatterns: RegExp[] = [];\n for (const k of opts.keys ?? []) {\n if (typeof k === \"string\") words.push(toSnakeCase(k));\n else keyPatterns.push(new RegExp(k.source, k.flags.replace(\"g\", \"\")));\n }\n const valuePatterns = (opts.values ?? []).map(globalize);\n\n const isSensitive = (key: string): boolean => {\n const k = toSnakeCase(key);\n if (keyPatterns.some((re) => re.test(k))) return true;\n if (!words.includes(k) && SAFE_SUFFIXES.some((s) => k.endsWith(s))) return false;\n return words.some((w) => k === w || k.startsWith(`${w}_`) || k.endsWith(`_${w}`) || k.includes(`_${w}_`));\n };\n\n const scrub = (s: string): string => {\n let out = s\n .replace(URL_CREDENTIALS_RE, `$1${REDACTED}@`)\n .replace(BEARER_RE, `Bearer ${REDACTED}`)\n .replace(JWT_RE, \"[REDACTED_JWT]\")\n .replace(EMAIL_RE, \"***@$1\");\n for (const re of valuePatterns) out = out.replace(re, REDACTED);\n return out;\n };\n\n const json = (value: unknown): string => {\n if (typeof value === \"string\") return value;\n try {\n const text = JSON.stringify(value, (key, val: unknown) => {\n if (key && val !== null && val !== undefined && isSensitive(key)) return REDACTED;\n if (typeof val === \"bigint\") return val.toString();\n if (val instanceof Error) return { name: val.name, message: val.message };\n return val;\n });\n return text ?? String(value);\n } catch {\n return String(value);\n }\n };\n\n return { isSensitive, scrub, json };\n}\n\nexport const defaultRedactor: Redactor = createRedactor();\n","import { globalSingleton } from \"./global\";\nimport { defaultRedactor } from \"./redact\";\n\nexport interface ErrFields {\n err_type?: string;\n err_message?: string;\n err_code?: string;\n err_stack?: string;\n err_cause?: string;\n /** Database errors (pg): the table and constraint the server reported. */\n db_table?: string;\n db_constraint?: string;\n}\n\nconst MAX_CAUSE_DEPTH = 5;\n\nexport function isErrorLike(v: unknown): v is Error {\n if (v instanceof Error) return true;\n return (\n typeof v === \"object\" &&\n v !== null &&\n typeof (v as { message?: unknown }).message === \"string\" &&\n (\"stack\" in v || \"name\" in v)\n );\n}\n\nfunction errorType(e: Error): string {\n // pg's DatabaseError keeps the lowercase name \"error\"; its class name says more.\n if (e.name && e.name !== \"Error\" && e.name !== \"error\") return e.name;\n const ctor = (e as { constructor?: { name?: string } }).constructor?.name;\n return ctor && ctor !== \"Object\" ? ctor : \"Error\";\n}\n\nexport function serializeError(err: unknown): ErrFields {\n if (!isErrorLike(err)) {\n if (typeof err === \"string\") return { err_type: \"string\", err_message: err };\n return { err_type: typeof err, err_message: defaultRedactor.json(err) };\n }\n const e = err as Error & { code?: unknown; cause?: unknown; table?: unknown; constraint?: unknown };\n const out: ErrFields = { err_type: errorType(e), err_message: String(e.message ?? \"\") };\n if (e.code !== undefined && e.code !== null) out.err_code = String(e.code);\n if (isSqlState(out.err_code)) {\n out.err_message = stripSql(out.err_message ?? \"\");\n if (typeof e.table === \"string\" && e.table) out.db_table = e.table;\n if (typeof e.constraint === \"string\" && e.constraint) out.db_constraint = e.constraint;\n }\n if (typeof e.stack === \"string\") out.err_stack = e.stack;\n\n const causes: string[] = [];\n let cause = e.cause;\n while (cause !== undefined && cause !== null && causes.length < MAX_CAUSE_DEPTH) {\n if (isErrorLike(cause)) {\n causes.push(`${errorType(cause)}: ${cause.message}`);\n cause = (cause as { cause?: unknown }).cause;\n } else {\n causes.push(defaultRedactor.json(cause));\n cause = undefined;\n }\n }\n if (causes.length > 0) out.err_cause = causes.join(\" <- \");\n return out;\n}\n\n// Postgres SQLSTATE codes: five digits or uppercase letters (23505, 40P01, 25P02).\nfunction isSqlState(code: string | undefined): boolean {\n return code !== undefined && /^[0-9A-Z]{5}$/.test(code);\n}\n\nconst SQL_START_RE = /^\\s*(?:select|insert|update|delete|with|create|alter|drop|truncate|lock)\\b/i;\n\n/**\n * knex prefixes a failed query's message with the whole statement (\"update ... - deadlock\n * detected\"). A long statement filled err_message and the truncation cut off the server's reason,\n * the only part worth reading. Keeps the reason; the statement never reaches the log.\n */\nexport function stripSql(message: string): string {\n if (!SQL_START_RE.test(message)) return message;\n const at = message.lastIndexOf(\" - \");\n return at === -1 ? message : message.slice(at + 3);\n}\n\n// The client hung up or sent a malformed request: worth a warn, not an error on our side.\nexport function isClientDisconnect(err: unknown): boolean {\n const e = err as { code?: unknown; message?: unknown } | null;\n const code = typeof e?.code === \"string\" ? e.code : \"\";\n return (\n code === \"ECONNRESET\" ||\n code === \"ECONNABORTED\" ||\n code === \"EPIPE\" ||\n code === \"ERR_STREAM_PREMATURE_CLOSE\" ||\n code.startsWith(\"HPE_\") ||\n e?.message === \"aborted\"\n );\n}\n\nconst logged = globalSingleton(\"logged\", () => new WeakSet<object>());\n\n// Marks an error as already written, so a later boundary (e.g. Next's onRequestError)\n// does not log it a second time.\nexport function markLogged(err: unknown): void {\n if (typeof err === \"object\" && err !== null) logged.add(err);\n}\n\nexport function isLogged(err: unknown): boolean {\n return typeof err === \"object\" && err !== null && logged.has(err);\n}\n","import { isErrorLike, serializeError } from \"./error\";\nimport type { Level } from \"./levels\";\nimport { REDACTED, toSnakeCase, type Redactor } from \"./redact\";\n\nexport { DEFAULT_REDACT_KEYS, toSnakeCase } from \"./redact\";\n\n/** Final per-field hook: return a replacement, or undefined to drop the field. */\nexport type RedactHook = (key: string, value: Primitive) => unknown;\n\nexport type Fields = Record<string, unknown>;\nexport type Primitive = string | number | boolean | null;\nexport type LogRecord = Record<string, Primitive>;\n\nexport interface NormalizeOptions {\n snakeCase: boolean;\n redactor: Redactor;\n hook?: RedactHook;\n}\n\n// Fields the redact hook never sees, so every line keeps its level, message and event.\nconst HOOK_EXEMPT = new Set([\"level\", \"message\", \"event\"]);\n\n// Keys owned by Vector (overwritten or deleted on ingest) or by the logger itself.\nexport const RESERVED_KEYS = new Set([\n \"project\", \"service\", \"vps\", \"version\", \"container_name\", \"container_id\", \"image\", \"stream\",\n \"_timestamp\", \"label\", \"host\", \"source_type\", \"msg\", \"lvl\", \"severity\", \"level\", \"message\",\n]);\n\nexport const MAX_LINE_BYTES = 16000;\nconst MAX_MESSAGE = 500;\nconst MAX_STACK = 4000;\nconst MAX_STRING = 1000;\nconst MAX_DEPTH = 3;\nconst TRUNCATED = \"…[truncated]\";\n\n// Fields kept when a line is too large.\nconst KEEP_ON_SHRINK = new Set([\n \"level\", \"message\", \"event\", \"request_id\", \"trace_id\", \"span_id\", \"job_name\", \"job_id\", \"job_attempt\",\n \"user_id\", \"tenant_id\", \"err_type\", \"err_message\", \"err_code\",\n]);\n\nexport function stripUrl(url: string): string {\n const noQuery = url.split(/[?#]/, 1)[0] ?? \"\";\n return noQuery.replace(/^([a-z][a-z0-9+.-]*:\\/\\/)[^/@\\s]*@/i, \"$1\");\n}\n\nexport function truncate(s: string, max: number): string {\n return s.length > max ? s.slice(0, max - TRUNCATED.length) + TRUNCATED : s;\n}\n\nfunction isPlainObject(v: unknown): v is Fields {\n if (typeof v !== \"object\" || v === null) return false;\n const proto = Object.getPrototypeOf(v);\n return proto === Object.prototype || proto === null;\n}\n\nfunction isUrlKey(key: string): boolean {\n return key === \"http_path\" || key === \"http_url\" || key.endsWith(\"_url\");\n}\n\nfunction flattenInto(out: LogRecord, prefix: string, obj: Fields, depth: number, opts: NormalizeOptions): void {\n for (const [rawKey, value] of Object.entries(obj)) {\n const key = opts.snakeCase ? toSnakeCase(rawKey) : rawKey;\n const full = prefix ? `${prefix}_${key}` : key;\n if (value === undefined || typeof value === \"function\" || typeof value === \"symbol\") continue;\n if (value !== null && (opts.redactor.isSensitive(rawKey) || opts.redactor.isSensitive(full))) {\n out[full] = REDACTED;\n continue;\n }\n if (value === null || typeof value === \"string\" || typeof value === \"boolean\") {\n out[full] = value;\n } else if (typeof value === \"number\") {\n out[full] = Number.isFinite(value) ? value : String(value);\n } else if (typeof value === \"bigint\") {\n out[full] = value.toString();\n } else if (value instanceof Date) {\n out[full] = Number.isNaN(value.getTime()) ? \"Invalid Date\" : value.toISOString();\n } else if (isErrorLike(value)) {\n out[full] = `${value.name}: ${value.message}`;\n } else if (isPlainObject(value) && depth < MAX_DEPTH - 1) {\n flattenInto(out, full, value, depth + 1, opts);\n } else {\n // Arrays, deep objects, class instances: stringified with sensitive keys redacted.\n out[full] = opts.redactor.json(value);\n }\n }\n}\n\n// Correlation ids are opaque tokens: value patterns such as phoneVN can match inside a hex\n// segment and break the join between services, so a well-formed id is never scrubbed.\nconst ID_VALUE_RE = /^[A-Za-z0-9._:-]{1,128}$/;\n\nfunction isIdKey(key: string): boolean {\n return key === \"request_id\" || key === \"trace_id\" || key === \"span_id\" || key.endsWith(\"_request_id\");\n}\n\nfunction finalize(key: string, value: Primitive, opts: NormalizeOptions): Primitive {\n if (typeof value !== \"string\") return value;\n if (isIdKey(key) && ID_VALUE_RE.test(value)) return value;\n const v = opts.redactor.scrub(isUrlKey(key) ? stripUrl(value) : value);\n return truncate(v, key === \"err_stack\" ? MAX_STACK : MAX_STRING);\n}\n\nexport function buildRecord(\n level: Level,\n message: unknown,\n sources: (Fields | undefined)[],\n opts: NormalizeOptions,\n): LogRecord {\n const merged: Fields = {};\n for (const source of sources) if (source) Object.assign(merged, source);\n\n let err: unknown;\n if (merged.err !== undefined && merged.err !== null) {\n err = merged.err;\n delete merged.err;\n } else if (isErrorLike(merged.error)) {\n err = merged.error;\n delete merged.error;\n }\n\n const flat: LogRecord = {};\n flattenInto(flat, \"\", merged, 0, opts);\n if (err !== undefined) Object.assign(flat, serializeError(err));\n\n const text = typeof message === \"string\" ? message : opts.redactor.json(message);\n const out: LogRecord = { level, message: truncate(opts.redactor.scrub(text), MAX_MESSAGE) };\n for (const [k, v] of Object.entries(flat)) {\n const key = RESERVED_KEYS.has(k) ? `app_${k}` : k;\n let value = finalize(key, v, opts);\n if (opts.hook && !HOOK_EXEMPT.has(key)) {\n const replaced = opts.hook(key, value);\n if (replaced === undefined) continue;\n value = typeof replaced === \"object\" && replaced !== null ? opts.redactor.json(replaced) : (replaced as Primitive);\n }\n out[key] = value;\n }\n return out;\n}\n\nfunction byteLength(s: string): number {\n // UTF-8 uses at most 3 bytes per UTF-16 code unit: skip encoding short lines.\n if (s.length * 3 <= MAX_LINE_BYTES) return s.length;\n return new TextEncoder().encode(s).length;\n}\n\nexport function serializeRecord(record: LogRecord): string {\n const line = JSON.stringify(record);\n if (byteLength(line) <= MAX_LINE_BYTES) return line;\n const small: LogRecord = {};\n for (const [k, v] of Object.entries(record)) {\n if (KEEP_ON_SHRINK.has(k) || k.startsWith(\"http_\")) small[k] = v;\n }\n small.log_truncated = true;\n return JSON.stringify(small);\n}\n","// No imports: this module is shared with the edge entry (next-edge).\nexport const REQUEST_ID_RE = /^[A-Za-z0-9._-]{1,64}$/;\nconst TRACEPARENT_RE = /^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/;\n\nexport function newRequestId(): string {\n return globalThis.crypto.randomUUID();\n}\n\nfunction first(header?: string | string[] | null): string | undefined {\n return Array.isArray(header) ? header[0] : (header ?? undefined);\n}\n\nexport function resolveRequestId(header?: string | string[] | null): string {\n const value = first(header);\n return value && REQUEST_ID_RE.test(value) ? value : newRequestId();\n}\n\nexport function parseTraceparent(header?: string | string[] | null): { trace_id: string; span_id: string } | undefined {\n const value = first(header)?.trim().toLowerCase();\n const m = value ? TRACEPARENT_RE.exec(value) : null;\n if (!m) return undefined;\n const [, version, traceId, spanId] = m as unknown as [string, string, string, string];\n if (version === \"ff\" || /^0+$/.test(traceId) || /^0+$/.test(spanId)) return undefined;\n return { trace_id: traceId, span_id: spanId };\n}\n","import { getContext } from \"./context\";\nimport { isClientDisconnect, markLogged, serializeError } from \"./error\";\nimport type { Logger } from \"./logger\";\nimport { stripUrl, type Fields } from \"./normalize\";\nimport { parseTraceparent, resolveRequestId } from \"./request-id\";\n\nexport { newRequestId, parseTraceparent, REQUEST_ID_RE, resolveRequestId } from \"./request-id\";\n\nexport type HeaderSource = Headers | Record<string, string | string[] | undefined>;\n\nfunction header(headers: HeaderSource, name: string): string | string[] | undefined {\n if (typeof (headers as Headers).get === \"function\") return (headers as Headers).get(name) ?? undefined;\n return (headers as Record<string, string | string[] | undefined>)[name];\n}\n\nexport function requestContextFields(headers: HeaderSource): { request_id: string; trace_id?: string; span_id?: string } {\n const out: { request_id: string; trace_id?: string; span_id?: string } = {\n request_id: resolveRequestId(header(headers, \"x-request-id\")),\n };\n const tp = parseTraceparent(header(headers, \"traceparent\"));\n if (tp) Object.assign(out, tp);\n return out;\n}\n\n// Headers to forward to services we own, so their logs share request_id / trace_id.\nexport function propagationHeaders(): Record<string, string> {\n const ctx = getContext();\n const out: Record<string, string> = {};\n if (typeof ctx.request_id === \"string\") out[\"x-request-id\"] = ctx.request_id;\n if (typeof ctx.trace_id === \"string\" && typeof ctx.span_id === \"string\") {\n out.traceparent = `00-${ctx.trace_id}-${ctx.span_id}-01`;\n }\n return out;\n}\n\nexport const DEFAULT_SKIP_PATHS: (string | RegExp)[] = [\n // Also under a prefix such as /api/v1/health.\n /(^|\\/)(health|healthz|ready|readyz|livez)\\/?$/,\n \"/favicon.ico\",\n /^\\/_next\\/static\\//,\n];\n\nexport interface HttpLogOptions {\n skipPaths?: (string | RegExp)[];\n}\n\nexport interface HttpRequestInfo {\n method: string;\n route?: string;\n path: string;\n status: number;\n duration_ms?: number;\n err?: unknown;\n fields?: Fields;\n}\n\nexport function shouldSkip(method: string, path: string, skipPaths: (string | RegExp)[] = DEFAULT_SKIP_PATHS): boolean {\n if (method.toUpperCase() === \"OPTIONS\") return true;\n const p = stripUrl(path);\n return skipPaths.some((s) => (typeof s === \"string\" ? p === s : s.test(p)));\n}\n\n// Writes the one `http.request` summary line for an inbound request. Skipped paths are still\n// logged when they fail with a 5xx, so a failing health check stays visible.\nexport function logHttpRequest(log: Logger, info: HttpRequestInfo, opts: HttpLogOptions = {}): void {\n if (info.status < 500 && shouldSkip(info.method, info.path, opts.skipPaths)) return;\n const hasErr = info.err !== undefined && info.err !== null;\n // A client that hung up mid-request is not a server failure, whatever status the app set.\n const clientGone = hasErr && isClientDisconnect(info.err);\n const level = info.status >= 500 && !clientGone ? \"error\" : info.status >= 400 ? \"warn\" : \"info\";\n const path = stripUrl(info.path);\n const errFields: Fields = {};\n if (hasErr) {\n Object.assign(errFields, serializeError(info.err));\n if (info.status < 500 || clientGone) delete errFields.err_stack;\n if (clientGone) errFields.client_disconnect = true;\n markLogged(info.err);\n }\n // Route templates keep the message bounded; the raw path would make one message per URL.\n const message = info.route ? `${info.method} ${info.route} ${info.status}` : `${info.method} ${info.status}`;\n log[level](message, {\n ...info.fields,\n event: \"http.request\",\n http_method: info.method,\n http_route: info.route,\n http_path: path,\n http_status: info.status,\n duration_ms: info.duration_ms === undefined ? undefined : Math.round(info.duration_ms),\n ...errFields,\n });\n}\n","import type { ErrorRequestHandler, RequestHandler } from \"express\";\nimport { attachStore, recordErrorIn, runWithStore, storeOf, type ContextStore } from \"./context\";\nimport { logHttpRequest, requestContextFields, type HttpLogOptions } from \"./http\";\nimport type { Logger } from \"./logger\";\n\nfunction joinRoute(baseUrl: string | undefined, path: unknown): string {\n return `${baseUrl ?? \"\"}${String(path)}` || \"/\";\n}\n\n// Express assigns req.route when a route matches, while req.baseUrl still holds the mount\n// path. It resets baseUrl before the response ends, so capture the full template here.\nfunction captureRoute(req: { baseUrl?: string }, store: ContextStore): void {\n let value: unknown;\n Object.defineProperty(req, \"route\", {\n configurable: true,\n enumerable: true,\n get: () => value,\n set: (route: { path?: unknown } | undefined) => {\n value = route;\n if (route?.path !== undefined) store.route = joinRoute(req.baseUrl, route.path);\n },\n });\n}\n\n/** Mount before routes. Opens the request context and writes the http.request line. */\nexport function requestLogger(log: Logger, opts: HttpLogOptions = {}): RequestHandler {\n return (req, res, next) => {\n const ctx = requestContextFields(req.headers);\n res.setHeader(\"x-request-id\", ctx.request_id);\n const start = performance.now();\n runWithStore(ctx, (store) => {\n attachStore(res, store);\n captureRoute(req, store);\n let done = false;\n const finish = () => {\n if (done) return;\n done = true;\n logHttpRequest(\n log,\n {\n method: req.method,\n route: store.route,\n path: req.originalUrl,\n status: res.writableFinished || res.headersSent ? res.statusCode : 499,\n duration_ms: performance.now() - start,\n err: store.error,\n fields: store.fields,\n },\n opts,\n );\n };\n res.once(\"finish\", finish);\n res.once(\"close\", finish);\n next();\n });\n };\n}\n\n/** Mount after routes, before your own error handler. Records the error for the summary line. */\nexport function errorRecorder(): ErrorRequestHandler {\n return (err, _req, res, next) => {\n const store = storeOf(res);\n if (store) recordErrorIn(store, err);\n next(err);\n };\n}\n","import type { FastifyPluginCallback, FastifyRequest } from \"fastify\";\nimport { attachStore, recordErrorIn, runWithStore, storeOf } from \"./context\";\nimport { logHttpRequest, requestContextFields, type HttpLogOptions } from \"./http\";\nimport type { Logger } from \"./logger\";\n\nexport interface FastifyLoggerOptions extends HttpLogOptions {\n log: Logger;\n}\n\nconst starts = new WeakMap<object, number>();\nconst finished = new WeakSet<object>();\n\nconst plugin: FastifyPluginCallback<FastifyLoggerOptions> = (app, opts, done) => {\n const summary = (req: FastifyRequest, status: number) => {\n if (finished.has(req)) return;\n finished.add(req);\n const store = storeOf(req);\n const start = starts.get(req);\n logHttpRequest(\n opts.log,\n {\n method: req.method,\n route: req.routeOptions?.url,\n path: req.url,\n status,\n duration_ms: start === undefined ? undefined : performance.now() - start,\n err: store?.error,\n fields: store?.fields,\n },\n opts,\n );\n };\n\n app.addHook(\"onRequest\", (req, reply, next) => {\n const ctx = requestContextFields(req.headers);\n reply.header(\"x-request-id\", ctx.request_id);\n starts.set(req, performance.now());\n runWithStore(ctx, (store) => {\n attachStore(req, store);\n attachStore(reply, store);\n next();\n });\n });\n app.addHook(\"onError\", (_req, reply, err, next) => {\n const store = storeOf(reply);\n if (store) recordErrorIn(store, err);\n next();\n });\n app.addHook(\"onResponse\", (req, reply, next) => {\n summary(req, reply.statusCode);\n next();\n });\n // Client closed the connection before the response (Fastify >= 4.21).\n app.addHook(\"onRequestAbort\", (req, next) => {\n summary(req, 499);\n next();\n });\n done();\n};\n\n// Same effect as fastify-plugin: hooks apply to the whole app, not an encapsulated child.\n(plugin as unknown as Record<symbol, boolean>)[Symbol.for(\"skip-override\")] = true;\n\nexport const fastifyLogger = plugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAAwD;;;ACDxD,8BAAkC;;;ACE3B,SAAS,gBAAmB,MAAc,MAAkB;AACjE,QAAM,MAAM,uBAAO,IAAI,iBAAiB,IAAI,EAAE;AAC9C,QAAM,IAAI;AACV,MAAI,QAAQ,EAAE,GAAG;AACjB,MAAI,UAAU,QAAW;AACvB,YAAQ,KAAK;AACb,MAAE,GAAG,IAAI;AAAA,EACX;AACA,SAAO;AACT;;;ADCA,IAAM,MAAM,gBAAgB,OAAO,MAAM,IAAI,0CAAgC,CAAC;AAEvE,IAAM,YAAoB,uBAAO,IAAI,qBAAqB;AAE1D,SAAS,aAAgB,QAAgB,IAAmC;AACjF,QAAM,SAAS,IAAI,SAAS;AAC5B,QAAM,QAAsB,EAAE,QAAQ,EAAE,GAAG,QAAQ,QAAQ,GAAG,OAAO,GAAG,OAAO;AAC/E,SAAO,IAAI,IAAI,OAAO,MAAM,GAAG,KAAK,CAAC;AACvC;AAMO,SAAS,eAAyC;AACvD,SAAO,IAAI,SAAS;AACtB;AAaO,SAAS,cAAc,OAAqB,KAAoB;AACrE,QAAM,QAAQ;AACd,WAAS,IAAI,MAAM,QAAQ,GAAG,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tB;AACA,QAAI,OAAO,SAAS,EAAG,QAAO,YAAY;AAC1C,QAAI;AACJ,QAAI,mBAAmB,OAAO;AAC5B,aAAO,MAAM;AACb,aAAO,QAAQ;AAAA,IACjB,WAAW,OAAO,YAAY,YAAY,YAAY,MAAM;AAC1D,aAAO,eAAe;AACtB,aAAO;AAAA,IACT,OAAO;AACL,aAAO,OAAO,OAAO;AAAA,IACvB;AACA,QAAI,UAAU,OAAW,QAAO,YAAY;AAC5C,SAAK,OAAO,KAAK,EAAE,MAAM,MAAM;AAAA,EACjC;AACF;AAGO,IAAM,2BAAN,MAA0D;AAAA,EAC/D,UAAU,SAA2B,MAAwC;AAC3E,WAAO,KAAK,OAAO,EAAE;AAAA,UACnB,wBAAW,CAAC,QAAiB;AAC3B,cAAM,QAAQ,QAAQ,QAAQ,aAAa,EAAE,YAAY,CAAC;AAC1D,YAAI,MAAO,eAAc,OAAO,GAAG;AAAA,YAC9B,aAAY,GAAG;AACpB,mBAAO,wBAAW,MAAM,GAAG;AAAA,MAC7B,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAeA,eAAsB,iBAAiB,KAAkB,KAAa,OAAuB,CAAC,GAAkB;AAC9G,QAAM,OAAO,IAAI,eAAe,EAAE,QAAQ;AAC1C,MAAI,SAAS,WAAW;AACtB,QAAI,CAAC,IAAI,SAAU,OAAM,IAAI,MAAM,iDAAiD;AACpF,UAAM,IAAI,SAAS,eAAe,EAAE,GAAG,MAAM,IAAI,CAAC;AAAA,EACpD,OAAO;AACL,QAAI,CAAC,IAAI,IAAK,OAAM,IAAI,MAAM,oCAAoC;AAClE,QAAI,IAAI,cAAqB,KAAK,IAAI,CAAC;AAAA,EACzC;AACA,MAAI,sBAAsB,IAAI,yBAAyB,CAAC;AAC1D;","names":["header"]}
1
+ {"version":3,"sources":["../src/nest.ts","../src/context.ts","../src/global.ts","../src/redact.ts","../src/error.ts","../src/normalize.ts","../src/request-id.ts","../src/http.ts","../src/express.ts","../src/fastify.ts"],"sourcesContent":["import type { CallHandler, ExecutionContext, LoggerService, NestInterceptor } from \"@nestjs/common\";\nimport { catchError, throwError, type Observable } from \"rxjs\";\nimport { currentStore, recordError, recordErrorIn, storeOf } from \"./context\";\nimport { requestLogger as expressRequestLogger } from \"./express\";\nimport { fastifyLogger } from \"./fastify\";\nimport type { HttpLogOptions } from \"./http\";\nimport type { Level } from \"./levels\";\nimport type { Logger } from \"./logger\";\nimport type { Fields } from \"./normalize\";\n\nexport { requestLogger } from \"./express\";\nexport { fastifyLogger } from \"./fastify\";\n\nconst STACK_RE = /\\n\\s+at /;\n\n/** Routes Nest's own logs (bootstrap, ExceptionsHandler, Logger calls) into the JSON logger. */\nexport class NestLogger implements LoggerService {\n constructor(private readonly logger: Logger) {}\n\n log(message: unknown, ...params: unknown[]): void {\n this.emit(\"info\", message, params);\n }\n error(message: unknown, ...params: unknown[]): void {\n this.emit(\"error\", message, params);\n }\n warn(message: unknown, ...params: unknown[]): void {\n this.emit(\"warn\", message, params);\n }\n debug(message: unknown, ...params: unknown[]): void {\n this.emit(\"debug\", message, params);\n }\n verbose(message: unknown, ...params: unknown[]): void {\n this.emit(\"trace\", message, params);\n }\n fatal(message: unknown, ...params: unknown[]): void {\n this.emit(\"fatal\", message, params);\n }\n\n private emit(level: Level, message: unknown, params: unknown[]): void {\n const rest = [...params];\n const last = rest[rest.length - 1];\n const nestContext = typeof last === \"string\" && !STACK_RE.test(last) ? (rest.pop() as string) : undefined;\n const stack = typeof rest[0] === \"string\" && STACK_RE.test(rest[0]) ? (rest.shift() as string) : undefined;\n\n // Nest's ExceptionsHandler logs unhandled errors; the http.request line already carries\n // them, so hand the error to the request instead of writing a second error line.\n const store = currentStore();\n if (nestContext === \"ExceptionsHandler\" && store?.fields.request_id !== undefined) {\n if (store.error === undefined) {\n const e = message instanceof Error ? message : Object.assign(new Error(String(message)), { stack });\n recordErrorIn(store, e);\n }\n return;\n }\n\n const fields: Fields = { nest_context: nestContext };\n // Extra arguments: objects become fields, errors become err, anything else goes to nest_args.\n const extras: unknown[] = [];\n for (const arg of rest) {\n if (arg instanceof Error && fields.err === undefined) fields.err = arg;\n else if (typeof arg === \"object\" && arg !== null && !Array.isArray(arg)) Object.assign(fields, arg);\n else extras.push(arg);\n }\n if (extras.length > 0) fields.nest_args = extras;\n let text: string;\n if (message instanceof Error) {\n fields.err = message;\n text = message.message;\n } else if (typeof message === \"object\" && message !== null) {\n fields.nest_payload = message;\n text = \"nest log\";\n } else {\n text = String(message);\n }\n if (stack !== undefined) fields.err_stack = stack;\n this.logger[level](text, fields);\n }\n}\n\n/** Records request errors for the http.request line, then rethrows to Nest's exception filters. */\nexport class ErrorRecorderInterceptor implements NestInterceptor {\n intercept(context: ExecutionContext, next: CallHandler): Observable<unknown> {\n return next.handle().pipe(\n catchError((err: unknown) => {\n const store = storeOf(context.switchToHttp().getResponse());\n if (store) recordErrorIn(store, err);\n else recordError(err);\n return throwError(() => err);\n }),\n );\n }\n}\n\n\n/** The parts of a Nest application that setupNestLogging needs, for either HTTP adapter. */\nexport interface NestAppLike {\n getHttpAdapter(): { getType(): string };\n useGlobalInterceptors(...interceptors: NestInterceptor[]): unknown;\n use?(...args: unknown[]): unknown;\n register?(...args: unknown[]): Promise<unknown>;\n}\n\n/**\n * One-call setup for Express and Fastify Nest apps: request context, the http.request line and\n * error recording. Call before `app.listen()`.\n */\nexport async function setupNestLogging(app: NestAppLike, log: Logger, opts: HttpLogOptions = {}): Promise<void> {\n const type = app.getHttpAdapter().getType();\n if (type === \"fastify\") {\n if (!app.register) throw new Error(\"setupNestLogging: Fastify app has no register()\");\n await app.register(fastifyLogger, { ...opts, log });\n } else {\n if (!app.use) throw new Error(\"setupNestLogging: app has no use()\");\n app.use(expressRequestLogger(log, opts));\n }\n app.useGlobalInterceptors(new ErrorRecorderInterceptor());\n}\n","import { AsyncLocalStorage } from \"node:async_hooks\";\nimport { globalSingleton } from \"./global\";\nimport type { Fields } from \"./normalize\";\n\nexport interface ContextStore {\n fields: Fields;\n error?: unknown;\n /** Route template captured while the router still knew it (Express error path). */\n route?: string;\n parent?: ContextStore;\n}\n\nconst als = globalSingleton(\"als\", () => new AsyncLocalStorage<ContextStore>());\n\nexport const STORE_KEY: symbol = Symbol.for(\"@tanngo11/log.store\");\n\nexport function runWithStore<T>(fields: Fields, fn: (store: ContextStore) => T): T {\n const parent = als.getStore();\n const store: ContextStore = { fields: { ...parent?.fields, ...fields }, parent };\n return als.run(store, () => fn(store));\n}\n\nexport function withContext<T>(fields: Fields, fn: () => T): T {\n return runWithStore(fields, () => fn());\n}\n\nexport function currentStore(): ContextStore | undefined {\n return als.getStore();\n}\n\nexport function getContext(): Fields {\n return als.getStore()?.fields ?? {};\n}\n\n// Applies to the current context and every enclosing one, so a field added inside a nested\n// withContext/runJob still reaches the request's http.request line.\nexport function addContext(fields: Fields): void {\n for (let s = als.getStore(); s; s = s.parent) Object.assign(s.fields, fields);\n}\n\n// Sets the error on the store and on enclosing stores that have none yet.\nexport function recordErrorIn(store: ContextStore, err: unknown): void {\n store.error = err;\n for (let s = store.parent; s; s = s.parent) if (s.error === undefined) s.error = err;\n}\n\n// Marks the error that the current request/job summary line should carry. Does not write a line.\nexport function recordError(err: unknown): void {\n const store = als.getStore();\n if (store) recordErrorIn(store, err);\n}\n\nexport function attachStore(target: object, store: ContextStore): void {\n (target as Record<symbol, ContextStore>)[STORE_KEY] = store;\n}\n\nexport function storeOf(target: unknown): ContextStore | undefined {\n if (typeof target !== \"object\" || target === null) return undefined;\n return (target as Record<symbol, ContextStore | undefined>)[STORE_KEY];\n}\n","// Singletons shared by every copy of this package loaded in the process (ESM and CJS builds,\n// or duplicated installs), so context and dedupe state never split.\nexport function globalSingleton<T>(name: string, make: () => T): T {\n const key = Symbol.for(`@tanngo11/log.${name}`);\n const g = globalThis as unknown as Record<symbol, T | undefined>;\n let value = g[key];\n if (value === undefined) {\n value = make();\n g[key] = value;\n }\n return value;\n}\n","// Redaction shared by the logger and the error serializer. The collector redacts again,\n// but it cannot see secrets inside JSON-encoded strings, so the app side must catch them.\n\nexport const DEFAULT_REDACT_KEYS = [\n \"password\", \"passwd\", \"pwd\", \"passphrase\", \"secret\", \"client_secret\",\n \"token\", \"access_token\", \"refresh_token\", \"id_token\", \"auth_token\",\n \"api_key\", \"apikey\", \"access_key\", \"secret_key\", \"private_key\",\n \"authorization\", \"cookie\", \"set_cookie\", \"session_id\", \"sessionid\",\n \"credential\", \"credentials\", \"dsn\", \"connection_string\", \"conn_string\", \"jwt\", \"bearer\",\n];\n\n/** Opt-in value patterns for `redactValues`. Not on by default: they can hit ordinary numbers. */\nexport const REDACT_PATTERNS = {\n /**\n * Vietnamese mobile numbers: 0912345678, +84912345678, 84912345678, also \"SDT0912345678\". A\n * hex letter (a-f) on either side rules a match out, so hex ids (a UUID segment such as\n * 0912345678e0) are left alone.\n */\n phoneVN: /(?<![\\dA-Fa-f+])(?:\\+?84|0)[35789]\\d{8}(?![\\dA-Fa-f])/g,\n /** Visa, Mastercard, Amex, Discover-like card numbers, with optional spaces or dashes. */\n paymentCard: /(?<!\\d)(?:4\\d{3}|5[1-5]\\d{2}|2[2-7]\\d{2}|3[47]\\d{2}|6(?:011|5\\d{2}))(?:[ -]?\\d{4}){2}[ -]?\\d{1,4}(?!\\d)/g,\n /** IPv4 addresses. */\n ipv4: /(?<![\\d.])(?:\\d{1,3}\\.){3}\\d{1,3}(?![\\d.])/g,\n} as const;\n\n// Keys that only describe a secret (count, type, timestamps, flags) stay readable.\nconst SAFE_SUFFIXES = [\"_count\", \"_type\", \"_length\", \"_expires_at\", \"_expires_in\", \"_ttl\", \"_at\", \"_ms\", \"_enabled\"];\n\nexport const REDACTED = \"[REDACTED]\";\n\nexport function toSnakeCase(key: string): string {\n return key\n .replace(/([a-z0-9])([A-Z])/g, \"$1_$2\")\n .replace(/([A-Z]+)([A-Z][a-z])/g, \"$1_$2\")\n .replace(/[^A-Za-z0-9_]+/g, \"_\")\n .toLowerCase();\n}\n\nconst URL_CREDENTIALS_RE = /([a-z][a-z0-9+.-]*:\\/\\/)[^\\s/@:\"']+:[^\\s/@\"']+@/gi;\nconst BEARER_RE = /\\bBearer\\s+[A-Za-z0-9._~+/=-]+/gi;\nconst JWT_RE = /\\beyJ[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+/g;\nconst EMAIL_RE = /[A-Za-z0-9._%+-]+@([A-Za-z0-9-]+(?:\\.[A-Za-z0-9-]+)*\\.[A-Za-z]{2,})/g;\n\nexport type KeyPattern = string | RegExp;\n\nexport interface RedactorOptions {\n /** Extra sensitive keys: names (matched like the defaults) or patterns tested on the snake_case key. */\n keys?: readonly KeyPattern[];\n /** Extra value patterns; every match inside any string becomes [REDACTED]. */\n values?: readonly RegExp[];\n}\n\nexport interface Redactor {\n isSensitive(key: string): boolean;\n /** Masks secrets and emails that appear inside free text. */\n scrub(s: string): string;\n /** JSON.stringify that redacts sensitive keys at any depth and never throws. */\n json(value: unknown): string;\n}\n\nfunction globalize(re: RegExp): RegExp {\n return re.flags.includes(\"g\") ? new RegExp(re.source, re.flags) : new RegExp(re.source, `${re.flags}g`);\n}\n\nexport function createRedactor(opts: RedactorOptions = {}): Redactor {\n const words = [...DEFAULT_REDACT_KEYS];\n const keyPatterns: RegExp[] = [];\n for (const k of opts.keys ?? []) {\n if (typeof k === \"string\") words.push(toSnakeCase(k));\n else keyPatterns.push(new RegExp(k.source, k.flags.replace(\"g\", \"\")));\n }\n const valuePatterns = (opts.values ?? []).map(globalize);\n\n const isSensitive = (key: string): boolean => {\n const k = toSnakeCase(key);\n if (keyPatterns.some((re) => re.test(k))) return true;\n if (!words.includes(k) && SAFE_SUFFIXES.some((s) => k.endsWith(s))) return false;\n return words.some((w) => k === w || k.startsWith(`${w}_`) || k.endsWith(`_${w}`) || k.includes(`_${w}_`));\n };\n\n const scrub = (s: string): string => {\n let out = s\n .replace(URL_CREDENTIALS_RE, `$1${REDACTED}@`)\n .replace(BEARER_RE, `Bearer ${REDACTED}`)\n .replace(JWT_RE, \"[REDACTED_JWT]\")\n .replace(EMAIL_RE, \"***@$1\");\n for (const re of valuePatterns) out = out.replace(re, REDACTED);\n return out;\n };\n\n const json = (value: unknown): string => {\n if (typeof value === \"string\") return value;\n try {\n const text = JSON.stringify(value, (key, val: unknown) => {\n if (key && val !== null && val !== undefined && isSensitive(key)) return REDACTED;\n if (typeof val === \"bigint\") return val.toString();\n if (val instanceof Error) return { name: val.name, message: val.message };\n return val;\n });\n return text ?? String(value);\n } catch {\n return String(value);\n }\n };\n\n return { isSensitive, scrub, json };\n}\n\nexport const defaultRedactor: Redactor = createRedactor();\n","import { globalSingleton } from \"./global\";\nimport { defaultRedactor } from \"./redact\";\n\nexport interface ErrFields {\n err_type?: string;\n err_message?: string;\n err_code?: string;\n err_stack?: string;\n err_cause?: string;\n /** Database errors (pg): the table and constraint the server reported. */\n db_table?: string;\n db_constraint?: string;\n}\n\nconst MAX_CAUSE_DEPTH = 5;\n\nexport function isErrorLike(v: unknown): v is Error {\n if (v instanceof Error) return true;\n return (\n typeof v === \"object\" &&\n v !== null &&\n typeof (v as { message?: unknown }).message === \"string\" &&\n (\"stack\" in v || \"name\" in v)\n );\n}\n\nfunction errorType(e: Error): string {\n // pg's DatabaseError keeps the lowercase name \"error\"; its class name says more.\n if (e.name && e.name !== \"Error\" && e.name !== \"error\") return e.name;\n const ctor = (e as { constructor?: { name?: string } }).constructor?.name;\n return ctor && ctor !== \"Object\" ? ctor : \"Error\";\n}\n\nexport function serializeError(err: unknown): ErrFields {\n if (!isErrorLike(err)) {\n if (typeof err === \"string\") return { err_type: \"string\", err_message: err };\n return { err_type: typeof err, err_message: defaultRedactor.json(err) };\n }\n const e = err as Error & { code?: unknown; cause?: unknown; table?: unknown; constraint?: unknown };\n const message = String(e.message ?? \"\");\n const out: ErrFields = { err_type: errorType(e), err_message: message };\n if (e.code !== undefined && e.code !== null) out.err_code = String(e.code);\n out.err_message = cleanMessage(message, out.err_code);\n if (isSqlState(out.err_code)) {\n if (typeof e.table === \"string\" && e.table) out.db_table = e.table;\n if (typeof e.constraint === \"string\" && e.constraint) out.db_constraint = e.constraint;\n }\n if (typeof e.stack === \"string\") out.err_stack = replaceOnce(e.stack, message, out.err_message);\n\n const causes: string[] = [];\n let cause = e.cause;\n while (cause !== undefined && cause !== null && causes.length < MAX_CAUSE_DEPTH) {\n if (isErrorLike(cause)) {\n const code = (cause as { code?: unknown }).code;\n const causeCode = code === undefined || code === null ? undefined : String(code);\n causes.push(`${errorType(cause)}: ${cleanMessage(String(cause.message ?? \"\"), causeCode)}`);\n cause = (cause as { cause?: unknown }).cause;\n } else {\n causes.push(defaultRedactor.json(cause));\n cause = undefined;\n }\n }\n if (causes.length > 0) out.err_cause = causes.join(\" <- \");\n return out;\n}\n\n// Postgres SQLSTATE codes: five digits or uppercase letters (23505, 40P01, 25P02).\nfunction isSqlState(code: string | undefined): boolean {\n return code !== undefined && /^[0-9A-Z]{5}$/.test(code);\n}\n\n// A statement, optionally behind comments or opening parentheses (\"(select ...) union ...\").\nconst SQL_START_RE = /^\\s*(?:\\/\\*[\\s\\S]*?\\*\\/\\s*)*\\(*\\s*(?:select|insert|update|delete|with|create|alter|drop|truncate|lock)\\b/i;\n// Without a SQLSTATE code, the part before \" - \" must also read like SQL, so a message such as\n// \"Update failed - retry later\" stays whole.\nconst SQL_BODY_RE = /[\"`]|\\b(?:from|into|set|values|where|table|returning)\\b/i;\n\n/**\n * knex prefixes every failed query's message with the statement, whatever the driver or error\n * (pg with or without a SQLSTATE, MySQL ER_*, SQLite, \"Connection terminated\"). Drops it.\n */\nfunction cleanMessage(message: string, code: string | undefined): string {\n const at = message.lastIndexOf(\" - \");\n if (at === -1 || !SQL_START_RE.test(message)) return message;\n if (!isSqlState(code) && !SQL_BODY_RE.test(message.slice(0, at))) return message;\n return stripSql(message);\n}\n\n// V8 renders the stack's first line from the message when .stack is first read. For knex errors\n// that is after the statement was prefixed, so the stack repeats it.\nfunction replaceOnce(text: string, find: string, replacement: string | undefined): string {\n if (replacement === undefined || find === replacement || find === \"\") return text;\n const at = text.indexOf(find);\n return at === -1 ? text : text.slice(0, at) + replacement + text.slice(at + find.length);\n}\n\n/**\n * knex prefixes a failed query's message with the whole statement (\"update ... - deadlock\n * detected\"). A long statement filled err_message and the truncation cut off the server's reason,\n * the only part worth reading. Keeps the reason; the statement never reaches the log. Cuts at the\n * last \" - \": a reason that contains \" - \" loses its start, which is safer than keeping part of a\n * statement that contains one (arithmetic, string literals).\n */\nexport function stripSql(message: string): string {\n if (!SQL_START_RE.test(message)) return message;\n const at = message.lastIndexOf(\" - \");\n return at === -1 ? message : message.slice(at + 3);\n}\n\n/**\n * For errors Koa emits on the inbound socket (strapiServerErrors): the client hung up or sent a\n * malformed request. Not valid for errors in general: knex's pool rejects with Error(\"aborted\")\n * when it is destroyed, and pg or outbound sockets reset with ECONNRESET.\n */\nexport function isClientDisconnect(err: unknown): boolean {\n const e = err as { code?: unknown; message?: unknown } | null;\n const code = typeof e?.code === \"string\" ? e.code : \"\";\n return (\n code === \"ECONNRESET\" ||\n code === \"ECONNABORTED\" ||\n code === \"EPIPE\" ||\n code === \"ERR_STREAM_PREMATURE_CLOSE\" ||\n code.startsWith(\"HPE_\") ||\n e?.message === \"aborted\"\n );\n}\n\nconst logged = globalSingleton(\"logged\", () => new WeakSet<object>());\n\n// Marks an error as already written, so a later boundary (e.g. Next's onRequestError)\n// does not log it a second time.\nexport function markLogged(err: unknown): void {\n if (typeof err === \"object\" && err !== null) logged.add(err);\n}\n\nexport function isLogged(err: unknown): boolean {\n return typeof err === \"object\" && err !== null && logged.has(err);\n}\n","import { isErrorLike, serializeError } from \"./error\";\nimport type { Level } from \"./levels\";\nimport { REDACTED, toSnakeCase, type Redactor } from \"./redact\";\n\nexport { DEFAULT_REDACT_KEYS, toSnakeCase } from \"./redact\";\n\n/** Final per-field hook: return a replacement, or undefined to drop the field. */\nexport type RedactHook = (key: string, value: Primitive) => unknown;\n\nexport type Fields = Record<string, unknown>;\nexport type Primitive = string | number | boolean | null;\nexport type LogRecord = Record<string, Primitive>;\n\nexport interface NormalizeOptions {\n snakeCase: boolean;\n redactor: Redactor;\n hook?: RedactHook;\n}\n\n// Fields the redact hook never sees, so every line keeps its level, message and event.\nconst HOOK_EXEMPT = new Set([\"level\", \"message\", \"event\"]);\n\n// Keys owned by Vector (overwritten or deleted on ingest) or by the logger itself.\nexport const RESERVED_KEYS = new Set([\n \"project\", \"service\", \"vps\", \"version\", \"container_name\", \"container_id\", \"image\", \"stream\",\n \"_timestamp\", \"label\", \"host\", \"source_type\", \"msg\", \"lvl\", \"severity\", \"level\", \"message\",\n]);\n\nexport const MAX_LINE_BYTES = 16000;\nconst MAX_MESSAGE = 500;\nconst MAX_STACK = 4000;\nconst MAX_STRING = 1000;\nconst MAX_DEPTH = 3;\nconst TRUNCATED = \"…[truncated]\";\n\n// Fields kept when a line is too large.\nconst KEEP_ON_SHRINK = new Set([\n \"level\", \"message\", \"event\", \"request_id\", \"trace_id\", \"span_id\", \"job_name\", \"job_id\", \"job_attempt\",\n \"user_id\", \"tenant_id\", \"err_type\", \"err_message\", \"err_code\",\n]);\n\nexport function stripUrl(url: string): string {\n const noQuery = url.split(/[?#]/, 1)[0] ?? \"\";\n return noQuery.replace(/^([a-z][a-z0-9+.-]*:\\/\\/)[^/@\\s]*@/i, \"$1\");\n}\n\nexport function truncate(s: string, max: number): string {\n return s.length > max ? s.slice(0, max - TRUNCATED.length) + TRUNCATED : s;\n}\n\nfunction isPlainObject(v: unknown): v is Fields {\n if (typeof v !== \"object\" || v === null) return false;\n const proto = Object.getPrototypeOf(v);\n return proto === Object.prototype || proto === null;\n}\n\nfunction isUrlKey(key: string): boolean {\n return key === \"http_path\" || key === \"http_url\" || key.endsWith(\"_url\");\n}\n\nfunction flattenInto(out: LogRecord, prefix: string, obj: Fields, depth: number, opts: NormalizeOptions): void {\n for (const [rawKey, value] of Object.entries(obj)) {\n const key = opts.snakeCase ? toSnakeCase(rawKey) : rawKey;\n const full = prefix ? `${prefix}_${key}` : key;\n if (value === undefined || typeof value === \"function\" || typeof value === \"symbol\") continue;\n if (value !== null && (opts.redactor.isSensitive(rawKey) || opts.redactor.isSensitive(full))) {\n out[full] = REDACTED;\n continue;\n }\n if (value === null || typeof value === \"string\" || typeof value === \"boolean\") {\n out[full] = value;\n } else if (typeof value === \"number\") {\n out[full] = Number.isFinite(value) ? value : String(value);\n } else if (typeof value === \"bigint\") {\n out[full] = value.toString();\n } else if (value instanceof Date) {\n out[full] = Number.isNaN(value.getTime()) ? \"Invalid Date\" : value.toISOString();\n } else if (isErrorLike(value)) {\n out[full] = `${value.name}: ${value.message}`;\n } else if (isPlainObject(value) && depth < MAX_DEPTH - 1) {\n flattenInto(out, full, value, depth + 1, opts);\n } else {\n // Arrays, deep objects, class instances: stringified with sensitive keys redacted.\n out[full] = opts.redactor.json(value);\n }\n }\n}\n\n// Correlation ids are opaque tokens: value patterns such as phoneVN can match inside a hex\n// segment and break the join between services, so a well-formed id is never scrubbed.\nconst ID_VALUE_RE = /^[A-Za-z0-9._:-]{1,128}$/;\n\nfunction isIdKey(key: string): boolean {\n return key === \"request_id\" || key === \"trace_id\" || key === \"span_id\" || key.endsWith(\"_request_id\");\n}\n\nfunction finalize(key: string, value: Primitive, opts: NormalizeOptions): Primitive {\n if (typeof value !== \"string\") return value;\n if (isIdKey(key) && ID_VALUE_RE.test(value)) return value;\n const v = opts.redactor.scrub(isUrlKey(key) ? stripUrl(value) : value);\n return truncate(v, key === \"err_stack\" ? MAX_STACK : MAX_STRING);\n}\n\nexport function buildRecord(\n level: Level,\n message: unknown,\n sources: (Fields | undefined)[],\n opts: NormalizeOptions,\n): LogRecord {\n const merged: Fields = {};\n for (const source of sources) if (source) Object.assign(merged, source);\n\n let err: unknown;\n if (merged.err !== undefined && merged.err !== null) {\n err = merged.err;\n delete merged.err;\n } else if (isErrorLike(merged.error)) {\n err = merged.error;\n delete merged.error;\n }\n\n const flat: LogRecord = {};\n flattenInto(flat, \"\", merged, 0, opts);\n if (err !== undefined) Object.assign(flat, serializeError(err));\n\n const text = typeof message === \"string\" ? message : opts.redactor.json(message);\n const out: LogRecord = { level, message: truncate(opts.redactor.scrub(text), MAX_MESSAGE) };\n for (const [k, v] of Object.entries(flat)) {\n const key = RESERVED_KEYS.has(k) ? `app_${k}` : k;\n let value = finalize(key, v, opts);\n if (opts.hook && !HOOK_EXEMPT.has(key)) {\n const replaced = opts.hook(key, value);\n if (replaced === undefined) continue;\n value = typeof replaced === \"object\" && replaced !== null ? opts.redactor.json(replaced) : (replaced as Primitive);\n }\n out[key] = value;\n }\n return out;\n}\n\nfunction byteLength(s: string): number {\n // UTF-8 uses at most 3 bytes per UTF-16 code unit: skip encoding short lines.\n if (s.length * 3 <= MAX_LINE_BYTES) return s.length;\n return new TextEncoder().encode(s).length;\n}\n\nexport function serializeRecord(record: LogRecord): string {\n const line = JSON.stringify(record);\n if (byteLength(line) <= MAX_LINE_BYTES) return line;\n const small: LogRecord = {};\n for (const [k, v] of Object.entries(record)) {\n if (KEEP_ON_SHRINK.has(k) || k.startsWith(\"http_\")) small[k] = v;\n }\n small.log_truncated = true;\n return JSON.stringify(small);\n}\n","// No imports: this module is shared with the edge entry (next-edge).\nexport const REQUEST_ID_RE = /^[A-Za-z0-9._-]{1,64}$/;\nconst TRACEPARENT_RE = /^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/;\n\nexport function newRequestId(): string {\n return globalThis.crypto.randomUUID();\n}\n\nfunction first(header?: string | string[] | null): string | undefined {\n return Array.isArray(header) ? header[0] : (header ?? undefined);\n}\n\nexport function resolveRequestId(header?: string | string[] | null): string {\n const value = first(header);\n return value && REQUEST_ID_RE.test(value) ? value : newRequestId();\n}\n\nexport function parseTraceparent(header?: string | string[] | null): { trace_id: string; span_id: string } | undefined {\n const value = first(header)?.trim().toLowerCase();\n const m = value ? TRACEPARENT_RE.exec(value) : null;\n if (!m) return undefined;\n const [, version, traceId, spanId] = m as unknown as [string, string, string, string];\n if (version === \"ff\" || /^0+$/.test(traceId) || /^0+$/.test(spanId)) return undefined;\n return { trace_id: traceId, span_id: spanId };\n}\n","import { getContext } from \"./context\";\nimport { markLogged, serializeError } from \"./error\";\nimport type { Logger } from \"./logger\";\nimport { stripUrl, type Fields } from \"./normalize\";\nimport { parseTraceparent, resolveRequestId } from \"./request-id\";\n\nexport { newRequestId, parseTraceparent, REQUEST_ID_RE, resolveRequestId } from \"./request-id\";\n\nexport type HeaderSource = Headers | Record<string, string | string[] | undefined>;\n\nfunction header(headers: HeaderSource, name: string): string | string[] | undefined {\n if (typeof (headers as Headers).get === \"function\") return (headers as Headers).get(name) ?? undefined;\n return (headers as Record<string, string | string[] | undefined>)[name];\n}\n\nexport function requestContextFields(headers: HeaderSource): { request_id: string; trace_id?: string; span_id?: string } {\n const out: { request_id: string; trace_id?: string; span_id?: string } = {\n request_id: resolveRequestId(header(headers, \"x-request-id\")),\n };\n const tp = parseTraceparent(header(headers, \"traceparent\"));\n if (tp) Object.assign(out, tp);\n return out;\n}\n\n// Headers to forward to services we own, so their logs share request_id / trace_id.\nexport function propagationHeaders(): Record<string, string> {\n const ctx = getContext();\n const out: Record<string, string> = {};\n if (typeof ctx.request_id === \"string\") out[\"x-request-id\"] = ctx.request_id;\n if (typeof ctx.trace_id === \"string\" && typeof ctx.span_id === \"string\") {\n out.traceparent = `00-${ctx.trace_id}-${ctx.span_id}-01`;\n }\n return out;\n}\n\nexport const DEFAULT_SKIP_PATHS: (string | RegExp)[] = [\n // Also under a prefix such as /api/v1/health.\n /(^|\\/)(health|healthz|ready|readyz|livez)\\/?$/,\n \"/favicon.ico\",\n /^\\/_next\\/static\\//,\n];\n\nexport interface HttpLogOptions {\n skipPaths?: (string | RegExp)[];\n}\n\nexport interface HttpRequestInfo {\n method: string;\n route?: string;\n path: string;\n status: number;\n duration_ms?: number;\n err?: unknown;\n fields?: Fields;\n}\n\nexport function shouldSkip(method: string, path: string, skipPaths: (string | RegExp)[] = DEFAULT_SKIP_PATHS): boolean {\n if (method.toUpperCase() === \"OPTIONS\") return true;\n const p = stripUrl(path);\n return skipPaths.some((s) => (typeof s === \"string\" ? p === s : s.test(p)));\n}\n\n// Writes the one `http.request` summary line for an inbound request. Skipped paths are still\n// logged when they fail with a 5xx, so a failing health check stays visible.\nexport function logHttpRequest(log: Logger, info: HttpRequestInfo, opts: HttpLogOptions = {}): void {\n if (info.status < 500 && shouldSkip(info.method, info.path, opts.skipPaths)) return;\n // The level follows the status only. An error's shape cannot tell a client hang-up apart:\n // knex's pool (tarn) rejects in-flight queries with Error(\"aborted\") when it is destroyed on\n // shutdown, and a pg or outbound socket reset is ECONNRESET too. Both are server-side failures.\n const level = info.status >= 500 ? \"error\" : info.status >= 400 ? \"warn\" : \"info\";\n const path = stripUrl(info.path);\n const errFields: Fields = {};\n if (info.err !== undefined && info.err !== null) {\n Object.assign(errFields, serializeError(info.err));\n if (info.status < 500) delete errFields.err_stack;\n markLogged(info.err);\n }\n // Route templates keep the message bounded; the raw path would make one message per URL.\n const message = info.route ? `${info.method} ${info.route} ${info.status}` : `${info.method} ${info.status}`;\n log[level](message, {\n ...info.fields,\n event: \"http.request\",\n http_method: info.method,\n http_route: info.route,\n http_path: path,\n http_status: info.status,\n duration_ms: info.duration_ms === undefined ? undefined : Math.round(info.duration_ms),\n ...errFields,\n });\n}\n","import type { ErrorRequestHandler, RequestHandler } from \"express\";\nimport { attachStore, recordErrorIn, runWithStore, storeOf, type ContextStore } from \"./context\";\nimport { logHttpRequest, requestContextFields, type HttpLogOptions } from \"./http\";\nimport type { Logger } from \"./logger\";\n\nfunction joinRoute(baseUrl: string | undefined, path: unknown): string {\n return `${baseUrl ?? \"\"}${String(path)}` || \"/\";\n}\n\n// Express assigns req.route when a route matches, while req.baseUrl still holds the mount\n// path. It resets baseUrl before the response ends, so capture the full template here.\nfunction captureRoute(req: { baseUrl?: string }, store: ContextStore): void {\n let value: unknown;\n Object.defineProperty(req, \"route\", {\n configurable: true,\n enumerable: true,\n get: () => value,\n set: (route: { path?: unknown } | undefined) => {\n value = route;\n if (route?.path !== undefined) store.route = joinRoute(req.baseUrl, route.path);\n },\n });\n}\n\n/** Mount before routes. Opens the request context and writes the http.request line. */\nexport function requestLogger(log: Logger, opts: HttpLogOptions = {}): RequestHandler {\n return (req, res, next) => {\n const ctx = requestContextFields(req.headers);\n res.setHeader(\"x-request-id\", ctx.request_id);\n const start = performance.now();\n runWithStore(ctx, (store) => {\n attachStore(res, store);\n captureRoute(req, store);\n let done = false;\n const finish = () => {\n if (done) return;\n done = true;\n logHttpRequest(\n log,\n {\n method: req.method,\n route: store.route,\n path: req.originalUrl,\n status: res.writableFinished || res.headersSent ? res.statusCode : 499,\n duration_ms: performance.now() - start,\n err: store.error,\n fields: store.fields,\n },\n opts,\n );\n };\n res.once(\"finish\", finish);\n res.once(\"close\", finish);\n next();\n });\n };\n}\n\n/** Mount after routes, before your own error handler. Records the error for the summary line. */\nexport function errorRecorder(): ErrorRequestHandler {\n return (err, _req, res, next) => {\n const store = storeOf(res);\n if (store) recordErrorIn(store, err);\n next(err);\n };\n}\n","import type { FastifyPluginCallback, FastifyRequest } from \"fastify\";\nimport { attachStore, recordErrorIn, runWithStore, storeOf } from \"./context\";\nimport { logHttpRequest, requestContextFields, type HttpLogOptions } from \"./http\";\nimport type { Logger } from \"./logger\";\n\nexport interface FastifyLoggerOptions extends HttpLogOptions {\n log: Logger;\n}\n\nconst starts = new WeakMap<object, number>();\nconst finished = new WeakSet<object>();\n\nconst plugin: FastifyPluginCallback<FastifyLoggerOptions> = (app, opts, done) => {\n const summary = (req: FastifyRequest, status: number) => {\n if (finished.has(req)) return;\n finished.add(req);\n const store = storeOf(req);\n const start = starts.get(req);\n logHttpRequest(\n opts.log,\n {\n method: req.method,\n route: req.routeOptions?.url,\n path: req.url,\n status,\n duration_ms: start === undefined ? undefined : performance.now() - start,\n err: store?.error,\n fields: store?.fields,\n },\n opts,\n );\n };\n\n app.addHook(\"onRequest\", (req, reply, next) => {\n const ctx = requestContextFields(req.headers);\n reply.header(\"x-request-id\", ctx.request_id);\n starts.set(req, performance.now());\n runWithStore(ctx, (store) => {\n attachStore(req, store);\n attachStore(reply, store);\n next();\n });\n });\n app.addHook(\"onError\", (_req, reply, err, next) => {\n const store = storeOf(reply);\n if (store) recordErrorIn(store, err);\n next();\n });\n app.addHook(\"onResponse\", (req, reply, next) => {\n summary(req, reply.statusCode);\n next();\n });\n // Client closed the connection before the response (Fastify >= 4.21).\n app.addHook(\"onRequestAbort\", (req, next) => {\n summary(req, 499);\n next();\n });\n done();\n};\n\n// Same effect as fastify-plugin: hooks apply to the whole app, not an encapsulated child.\n(plugin as unknown as Record<symbol, boolean>)[Symbol.for(\"skip-override\")] = true;\n\nexport const fastifyLogger = plugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAAwD;;;ACDxD,8BAAkC;;;ACE3B,SAAS,gBAAmB,MAAc,MAAkB;AACjE,QAAM,MAAM,uBAAO,IAAI,iBAAiB,IAAI,EAAE;AAC9C,QAAM,IAAI;AACV,MAAI,QAAQ,EAAE,GAAG;AACjB,MAAI,UAAU,QAAW;AACvB,YAAQ,KAAK;AACb,MAAE,GAAG,IAAI;AAAA,EACX;AACA,SAAO;AACT;;;ADCA,IAAM,MAAM,gBAAgB,OAAO,MAAM,IAAI,0CAAgC,CAAC;AAEvE,IAAM,YAAoB,uBAAO,IAAI,qBAAqB;AAE1D,SAAS,aAAgB,QAAgB,IAAmC;AACjF,QAAM,SAAS,IAAI,SAAS;AAC5B,QAAM,QAAsB,EAAE,QAAQ,EAAE,GAAG,QAAQ,QAAQ,GAAG,OAAO,GAAG,OAAO;AAC/E,SAAO,IAAI,IAAI,OAAO,MAAM,GAAG,KAAK,CAAC;AACvC;AAMO,SAAS,eAAyC;AACvD,SAAO,IAAI,SAAS;AACtB;AAaO,SAAS,cAAc,OAAqB,KAAoB;AACrE,QAA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AAC,IAAI,SAAU,OAAM,IAAI,MAAM,iDAAiD;AACpF,UAAM,IAAI,SAAS,eAAe,EAAE,GAAG,MAAM,IAAI,CAAC;AAAA,EACpD,OAAO;AACL,QAAI,CAAC,IAAI,IAAK,OAAM,IAAI,MAAM,oCAAoC;AAClE,QAAI,IAAI,cAAqB,KAAK,IAAI,CAAC;AAAA,EACzC;AACA,MAAI,sBAAsB,IAAI,yBAAyB,CAAC;AAC1D;","names":["header"]}
package/dist/nest.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { NestInterceptor, ExecutionContext, CallHandler, LoggerService } from '@nestjs/common';
2
2
  import { Observable } from 'rxjs';
3
- import { H as HttpLogOptions } from './http-BQJkHBwQ.cjs';
4
- import { L as Logger } from './logger-3Co9eVJf.cjs';
3
+ import { H as HttpLogOptions } from './http-eeog5tR8.cjs';
4
+ import { L as Logger } from './logger-CtlC9SUE.cjs';
5
5
  export { requestLogger } from './express.cjs';
6
6
  export { fastifyLogger } from './fastify.cjs';
7
7
  import 'express';
package/dist/nest.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { NestInterceptor, ExecutionContext, CallHandler, LoggerService } from '@nestjs/common';
2
2
  import { Observable } from 'rxjs';
3
- import { H as HttpLogOptions } from './http-44ztBSXk.js';
4
- import { L as Logger } from './logger-3Co9eVJf.js';
3
+ import { H as HttpLogOptions } from './http-Dp6Qtr9M.js';
4
+ import { L as Logger } from './logger-CtlC9SUE.js';
5
5
  export { requestLogger } from './express.js';
6
6
  export { fastifyLogger } from './fastify.js';
7
7
  import 'express';
package/dist/nest.js CHANGED
@@ -1,17 +1,17 @@
1
1
  import {
2
2
  requestLogger
3
- } from "./chunk-UOIJCSP5.js";
3
+ } from "./chunk-EZCIMEVL.js";
4
4
  import {
5
5
  fastifyLogger
6
- } from "./chunk-RVETZAK5.js";
7
- import "./chunk-AF4YR4Y4.js";
6
+ } from "./chunk-RQWNJJIT.js";
7
+ import "./chunk-BFMFXDIJ.js";
8
8
  import "./chunk-KLBL7QEN.js";
9
9
  import {
10
10
  currentStore,
11
11
  recordError,
12
12
  recordErrorIn,
13
13
  storeOf
14
- } from "./chunk-UDS6S22P.js";
14
+ } from "./chunk-JKCR57WJ.js";
15
15
 
16
16
  // src/nest.ts
17
17
  import { catchError, throwError } from "rxjs";
package/dist/next.cjs CHANGED
@@ -159,19 +159,22 @@ function serializeError(err) {
159
159
  return { err_type: typeof err, err_message: defaultRedactor.json(err) };
160
160
  }
161
161
  const e = err;
162
- const out = { err_type: errorType(e), err_message: String(e.message ?? "") };
162
+ const message = String(e.message ?? "");
163
+ const out = { err_type: errorType(e), err_message: message };
163
164
  if (e.code !== void 0 && e.code !== null) out.err_code = String(e.code);
165
+ out.err_message = cleanMessage(message, out.err_code);
164
166
  if (isSqlState(out.err_code)) {
165
- out.err_message = stripSql(out.err_message ?? "");
166
167
  if (typeof e.table === "string" && e.table) out.db_table = e.table;
167
168
  if (typeof e.constraint === "string" && e.constraint) out.db_constraint = e.constraint;
168
169
  }
169
- if (typeof e.stack === "string") out.err_stack = e.stack;
170
+ if (typeof e.stack === "string") out.err_stack = replaceOnce(e.stack, message, out.err_message);
170
171
  const causes = [];
171
172
  let cause = e.cause;
172
173
  while (cause !== void 0 && cause !== null && causes.length < MAX_CAUSE_DEPTH) {
173
174
  if (isErrorLike(cause)) {
174
- causes.push(`${errorType(cause)}: ${cause.message}`);
175
+ const code = cause.code;
176
+ const causeCode = code === void 0 || code === null ? void 0 : String(code);
177
+ causes.push(`${errorType(cause)}: ${cleanMessage(String(cause.message ?? ""), causeCode)}`);
175
178
  cause = cause.cause;
176
179
  } else {
177
180
  causes.push(defaultRedactor.json(cause));
@@ -184,17 +187,24 @@ function serializeError(err) {
184
187
  function isSqlState(code) {
185
188
  return code !== void 0 && /^[0-9A-Z]{5}$/.test(code);
186
189
  }
187
- var SQL_START_RE = /^\s*(?:select|insert|update|delete|with|create|alter|drop|truncate|lock)\b/i;
190
+ var SQL_START_RE = /^\s*(?:\/\*[\s\S]*?\*\/\s*)*\(*\s*(?:select|insert|update|delete|with|create|alter|drop|truncate|lock)\b/i;
191
+ var SQL_BODY_RE = /["`]|\b(?:from|into|set|values|where|table|returning)\b/i;
192
+ function cleanMessage(message, code) {
193
+ const at = message.lastIndexOf(" - ");
194
+ if (at === -1 || !SQL_START_RE.test(message)) return message;
195
+ if (!isSqlState(code) && !SQL_BODY_RE.test(message.slice(0, at))) return message;
196
+ return stripSql(message);
197
+ }
198
+ function replaceOnce(text, find, replacement) {
199
+ if (replacement === void 0 || find === replacement || find === "") return text;
200
+ const at = text.indexOf(find);
201
+ return at === -1 ? text : text.slice(0, at) + replacement + text.slice(at + find.length);
202
+ }
188
203
  function stripSql(message) {
189
204
  if (!SQL_START_RE.test(message)) return message;
190
205
  const at = message.lastIndexOf(" - ");
191
206
  return at === -1 ? message : message.slice(at + 3);
192
207
  }
193
- function isClientDisconnect(err) {
194
- const e = err;
195
- const code = typeof e?.code === "string" ? e.code : "";
196
- return code === "ECONNRESET" || code === "ECONNABORTED" || code === "EPIPE" || code === "ERR_STREAM_PREMATURE_CLOSE" || code.startsWith("HPE_") || e?.message === "aborted";
197
- }
198
208
  var logged = globalSingleton("logged", () => /* @__PURE__ */ new WeakSet());
199
209
  function markLogged(err) {
200
210
  if (typeof err === "object" && err !== null) logged.add(err);
@@ -257,15 +267,12 @@ function shouldSkip(method, path, skipPaths = DEFAULT_SKIP_PATHS) {
257
267
  }
258
268
  function logHttpRequest(log, info, opts = {}) {
259
269
  if (info.status < 500 && shouldSkip(info.method, info.path, opts.skipPaths)) return;
260
- const hasErr = info.err !== void 0 && info.err !== null;
261
- const clientGone = hasErr && isClientDisconnect(info.err);
262
- const level = info.status >= 500 && !clientGone ? "error" : info.status >= 400 ? "warn" : "info";
270
+ const level = info.status >= 500 ? "error" : info.status >= 400 ? "warn" : "info";
263
271
  const path = stripUrl(info.path);
264
272
  const errFields = {};
265
- if (hasErr) {
273
+ if (info.err !== void 0 && info.err !== null) {
266
274
  Object.assign(errFields, serializeError(info.err));
267
- if (info.status < 500 || clientGone) delete errFields.err_stack;
268
- if (clientGone) errFields.client_disconnect = true;
275
+ if (info.status < 500) delete errFields.err_stack;
269
276
  markLogged(info.err);
270
277
  }
271
278
  const message = info.route ? `${info.method} ${info.route} ${info.status}` : `${info.method} ${info.status}`;
package/dist/next.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/next.ts","../src/context.ts","../src/global.ts","../src/redact.ts","../src/error.ts","../src/normalize.ts","../src/request-id.ts","../src/http.ts","../src/process.ts"],"sourcesContent":["import { runWithStore } from \"./context\";\nimport { isErrorLike, isLogged, markLogged } from \"./error\";\nimport { logHttpRequest, requestContextFields, type HeaderSource, type HttpLogOptions } from \"./http\";\nimport type { Logger } from \"./logger\";\nimport type { Fields } from \"./normalize\";\nimport { installProcessHandlers, logProcessWarnings, logStartup } from \"./process\";\n\nexport interface WithLoggingOptions extends HttpLogOptions {\n /** Route template, e.g. \"/api/orders/[id]\". Left empty when not given. */\n route?: string;\n}\n\n/** Status for Next's control-flow errors (redirect(), notFound(), forbidden()...), else undefined. */\nexport function nextControlStatus(err: unknown): number | undefined {\n const digest = (err as { digest?: unknown } | null)?.digest;\n if (typeof digest !== \"string\") return undefined;\n if (digest.startsWith(\"NEXT_REDIRECT\")) {\n const status = Number(digest.split(\";\")[3]);\n return Number.isInteger(status) && status >= 300 ? status : 307;\n }\n if (digest === \"NEXT_NOT_FOUND\") return 404;\n if (digest.startsWith(\"NEXT_HTTP_ERROR_FALLBACK;\")) return Number(digest.split(\";\")[1]) || 404;\n return undefined;\n}\n\nfunction asError(value: unknown): unknown {\n if (typeof value === \"object\" && value !== null) return value;\n return Object.assign(new Error(String(value)), { name: \"NonErrorThrown\", thrown: value });\n}\n\nfunction trySetHeader(res: Response, name: string, value: string): void {\n try {\n res.headers.set(name, value);\n } catch {\n // Some responses (Response.redirect, proxied fetch responses) have immutable headers.\n }\n}\n\n/** Any App Router route handler: `()`, `(request)` or `(request, { params })`. */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type RouteHandler = (...args: any[]) => Response | Promise<Response>;\n\n/**\n * Wraps an App Router route handler: request context + one http.request line. The returned\n * function has exactly the handler's parameters, so Next's route type checks still pass.\n */\nexport function withLogging<H extends RouteHandler>(\n log: Logger,\n handler: H,\n opts: WithLoggingOptions = {},\n): (...args: Parameters<H>) => Promise<Awaited<ReturnType<H>>> {\n return async (...args): Promise<Awaited<ReturnType<H>>> => {\n const request: unknown = args[0];\n // Next always passes the request; direct calls in unit tests may not.\n if (!(request instanceof Request)) return (await handler(...args)) as Awaited<ReturnType<H>>;\n const ctx = requestContextFields(request.headers);\n const path = new URL(request.url).pathname;\n const start = performance.now();\n return await runWithStore(ctx, async (store): Promise<Awaited<ReturnType<H>>> => {\n const summary = (status: number, err: unknown) =>\n logHttpRequest(\n log,\n {\n method: request.method,\n route: opts.route,\n path,\n status,\n duration_ms: performance.now() - start,\n err,\n fields: store.fields,\n },\n opts,\n );\n try {\n const res = (await handler(...args)) as Awaited<ReturnType<H>>;\n summary((res as Response).status, store.error);\n trySetHeader(res as Response, \"x-request-id\", ctx.request_id);\n return res;\n } catch (caught) {\n const control = nextControlStatus(caught);\n // Non-objects cannot be marked as logged, so onRequestError would log them again.\n const err = control === undefined ? asError(caught) : caught;\n summary(control ?? 500, control === undefined ? err : store.error);\n throw err;\n }\n });\n };\n}\n\n/**\n * patchConsole skip predicate for Next.js: Next prints a render error with console.error right\n * before calling onRequestError, by then the error carries a digest. Dropping that console\n * call leaves the single, richer onRequestError line.\n */\nexport function nextConsoleSkip(args: unknown[]): boolean {\n return args.some((arg) => isErrorLike(arg) && typeof (arg as { digest?: unknown }).digest === \"string\");\n}\n\nexport interface NextRequestInfo {\n path?: string;\n method?: string;\n headers?: Record<string, string | string[] | undefined>;\n}\n\nexport interface NextErrorContext {\n routerKind?: string;\n routePath?: string;\n routeType?: string;\n}\n\n/** `export const onRequestError = nextOnRequestError(log)` in instrumentation.ts. */\nexport function nextOnRequestError(log: Logger, opts: HttpLogOptions = {}) {\n return async (err: unknown, request: NextRequestInfo, context: NextErrorContext): Promise<void> => {\n if (isLogged(err) || nextControlStatus(err) !== undefined) return;\n const digest = (err as { digest?: unknown } | null)?.digest;\n logHttpRequest(\n log,\n {\n method: request?.method ?? \"GET\",\n route: context?.routePath,\n path: request?.path ?? \"\",\n status: 500,\n err,\n fields: {\n ...requestContextFields(request?.headers ?? {}),\n next_route_type: context?.routeType,\n next_router_kind: context?.routerKind,\n next_digest: typeof digest === \"string\" ? digest : undefined,\n },\n },\n opts,\n );\n };\n}\n\n/** Call from `register()` in instrumentation.ts. Does nothing on the edge runtime. */\nexport function registerNext(log: Logger, fields?: Fields): void {\n if (process.env.NEXT_RUNTIME && process.env.NEXT_RUNTIME !== \"nodejs\") return;\n // Next keeps serving after an unhandled rejection, so do not exit.\n installProcessHandlers(log, { exitOnCrash: false });\n logProcessWarnings(log);\n logStartup(log, { port: process.env.PORT ? Number(process.env.PORT) : undefined, ...fields });\n}\n\nexport interface WithActionOptions {\n /** Request headers source. Defaults to `headers()` from next/headers. */\n headers?: () => HeaderSource | Promise<HeaderSource>;\n}\n\nasync function nextHeaders(): Promise<HeaderSource> {\n try {\n const mod = (await import(\"next/headers\")) as { headers: () => HeaderSource | Promise<HeaderSource> };\n return await mod.headers();\n } catch {\n // Called outside a request (tests, scripts) or Next is not installed.\n return {};\n }\n}\n\n/**\n * Wraps a server action: request context (request_id from x-request-id) plus one\n * `action.completed` / `action.failed` line. redirect()/notFound() count as completed.\n */\nexport function withAction<A extends unknown[], R>(\n log: Logger,\n name: string,\n action: (...args: A) => Promise<R>,\n opts: WithActionOptions = {},\n): (...args: A) => Promise<R> {\n return async (...args) => {\n const headers = await (opts.headers ?? nextHeaders)();\n const start = performance.now();\n return runWithStore({ ...requestContextFields(headers), action_name: name }, async (store) => {\n const fields = () => ({ ...store.fields, duration_ms: Math.round(performance.now() - start) });\n try {\n const result = await action(...args);\n log.info(\"server action completed\", { ...fields(), event: \"action.completed\", err: store.error });\n return result;\n } catch (caught) {\n const control = nextControlStatus(caught);\n if (control !== undefined) {\n log.info(\"server action completed\", { ...fields(), event: \"action.completed\", next_control_status: control });\n throw caught;\n }\n const err = asError(caught);\n log.error(\"server action failed\", { ...fields(), event: \"action.failed\", err });\n markLogged(err);\n throw err;\n }\n });\n };\n}\n","import { AsyncLocalStorage } from \"node:async_hooks\";\nimport { globalSingleton } from \"./global\";\nimport type { Fields } from \"./normalize\";\n\nexport interface ContextStore {\n fields: Fields;\n error?: unknown;\n /** Route template captured while the router still knew it (Express error path). */\n route?: string;\n parent?: ContextStore;\n}\n\nconst als = globalSingleton(\"als\", () => new AsyncLocalStorage<ContextStore>());\n\nexport const STORE_KEY: symbol = Symbol.for(\"@tanngo11/log.store\");\n\nexport function runWithStore<T>(fields: Fields, fn: (store: ContextStore) => T): T {\n const parent = als.getStore();\n const store: ContextStore = { fields: { ...parent?.fields, ...fields }, parent };\n return als.run(store, () => fn(store));\n}\n\nexport function withContext<T>(fields: Fields, fn: () => T): T {\n return runWithStore(fields, () => fn());\n}\n\nexport function currentStore(): ContextStore | undefined {\n return als.getStore();\n}\n\nexport function getContext(): Fields {\n return als.getStore()?.fields ?? {};\n}\n\n// Applies to the current context and every enclosing one, so a field added inside a nested\n// withContext/runJob still reaches the request's http.request line.\nexport function addContext(fields: Fields): void {\n for (let s = als.getStore(); s; s = s.parent) Object.assign(s.fields, fields);\n}\n\n// Sets the error on the store and on enclosing stores that have none yet.\nexport function recordErrorIn(store: ContextStore, err: unknown): void {\n store.error = err;\n for (let s = store.parent; s; s = s.parent) if (s.error === undefined) s.error = err;\n}\n\n// Marks the error that the current request/job summary line should carry. Does not write a line.\nexport function recordError(err: unknown): void {\n const store = als.getStore();\n if (store) recordErrorIn(store, err);\n}\n\nexport function attachStore(target: object, store: ContextStore): void {\n (target as Record<symbol, ContextStore>)[STORE_KEY] = store;\n}\n\nexport function storeOf(target: unknown): ContextStore | undefined {\n if (typeof target !== \"object\" || target === null) return undefined;\n return (target as Record<symbol, ContextStore | undefined>)[STORE_KEY];\n}\n","// Singletons shared by every copy of this package loaded in the process (ESM and CJS builds,\n// or duplicated installs), so context and dedupe state never split.\nexport function globalSingleton<T>(name: string, make: () => T): T {\n const key = Symbol.for(`@tanngo11/log.${name}`);\n const g = globalThis as unknown as Record<symbol, T | undefined>;\n let value = g[key];\n if (value === undefined) {\n value = make();\n g[key] = value;\n }\n return value;\n}\n","// Redaction shared by the logger and the error serializer. The collector redacts again,\n// but it cannot see secrets inside JSON-encoded strings, so the app side must catch them.\n\nexport const DEFAULT_REDACT_KEYS = [\n \"password\", \"passwd\", \"pwd\", \"passphrase\", \"secret\", \"client_secret\",\n \"token\", \"access_token\", \"refresh_token\", \"id_token\", \"auth_token\",\n \"api_key\", \"apikey\", \"access_key\", \"secret_key\", \"private_key\",\n \"authorization\", \"cookie\", \"set_cookie\", \"session_id\", \"sessionid\",\n \"credential\", \"credentials\", \"dsn\", \"connection_string\", \"conn_string\", \"jwt\", \"bearer\",\n];\n\n/** Opt-in value patterns for `redactValues`. Not on by default: they can hit ordinary numbers. */\nexport const REDACT_PATTERNS = {\n /**\n * Vietnamese mobile numbers: 0912345678, +84912345678, 84912345678. Letters on either side\n * rule a match out, so hex ids (a UUID segment such as 0912345678e0) are left alone.\n */\n phoneVN: /(?<![\\dA-Za-z+])(?:\\+?84|0)[35789]\\d{8}(?![\\dA-Za-z])/g,\n /** Visa, Mastercard, Amex, Discover-like card numbers, with optional spaces or dashes. */\n paymentCard: /(?<!\\d)(?:4\\d{3}|5[1-5]\\d{2}|2[2-7]\\d{2}|3[47]\\d{2}|6(?:011|5\\d{2}))(?:[ -]?\\d{4}){2}[ -]?\\d{1,4}(?!\\d)/g,\n /** IPv4 addresses. */\n ipv4: /(?<![\\d.])(?:\\d{1,3}\\.){3}\\d{1,3}(?![\\d.])/g,\n} as const;\n\n// Keys that only describe a secret (count, type, timestamps, flags) stay readable.\nconst SAFE_SUFFIXES = [\"_count\", \"_type\", \"_length\", \"_expires_at\", \"_expires_in\", \"_ttl\", \"_at\", \"_ms\", \"_enabled\"];\n\nexport const REDACTED = \"[REDACTED]\";\n\nexport function toSnakeCase(key: string): string {\n return key\n .replace(/([a-z0-9])([A-Z])/g, \"$1_$2\")\n .replace(/([A-Z]+)([A-Z][a-z])/g, \"$1_$2\")\n .replace(/[^A-Za-z0-9_]+/g, \"_\")\n .toLowerCase();\n}\n\nconst URL_CREDENTIALS_RE = /([a-z][a-z0-9+.-]*:\\/\\/)[^\\s/@:\"']+:[^\\s/@\"']+@/gi;\nconst BEARER_RE = /\\bBearer\\s+[A-Za-z0-9._~+/=-]+/gi;\nconst JWT_RE = /\\beyJ[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+/g;\nconst EMAIL_RE = /[A-Za-z0-9._%+-]+@([A-Za-z0-9-]+(?:\\.[A-Za-z0-9-]+)*\\.[A-Za-z]{2,})/g;\n\nexport type KeyPattern = string | RegExp;\n\nexport interface RedactorOptions {\n /** Extra sensitive keys: names (matched like the defaults) or patterns tested on the snake_case key. */\n keys?: readonly KeyPattern[];\n /** Extra value patterns; every match inside any string becomes [REDACTED]. */\n values?: readonly RegExp[];\n}\n\nexport interface Redactor {\n isSensitive(key: string): boolean;\n /** Masks secrets and emails that appear inside free text. */\n scrub(s: string): string;\n /** JSON.stringify that redacts sensitive keys at any depth and never throws. */\n json(value: unknown): string;\n}\n\nfunction globalize(re: RegExp): RegExp {\n return re.flags.includes(\"g\") ? new RegExp(re.source, re.flags) : new RegExp(re.source, `${re.flags}g`);\n}\n\nexport function createRedactor(opts: RedactorOptions = {}): Redactor {\n const words = [...DEFAULT_REDACT_KEYS];\n const keyPatterns: RegExp[] = [];\n for (const k of opts.keys ?? []) {\n if (typeof k === \"string\") words.push(toSnakeCase(k));\n else keyPatterns.push(new RegExp(k.source, k.flags.replace(\"g\", \"\")));\n }\n const valuePatterns = (opts.values ?? []).map(globalize);\n\n const isSensitive = (key: string): boolean => {\n const k = toSnakeCase(key);\n if (keyPatterns.some((re) => re.test(k))) return true;\n if (!words.includes(k) && SAFE_SUFFIXES.some((s) => k.endsWith(s))) return false;\n return words.some((w) => k === w || k.startsWith(`${w}_`) || k.endsWith(`_${w}`) || k.includes(`_${w}_`));\n };\n\n const scrub = (s: string): string => {\n let out = s\n .replace(URL_CREDENTIALS_RE, `$1${REDACTED}@`)\n .replace(BEARER_RE, `Bearer ${REDACTED}`)\n .replace(JWT_RE, \"[REDACTED_JWT]\")\n .replace(EMAIL_RE, \"***@$1\");\n for (const re of valuePatterns) out = out.replace(re, REDACTED);\n return out;\n };\n\n const json = (value: unknown): string => {\n if (typeof value === \"string\") return value;\n try {\n const text = JSON.stringify(value, (key, val: unknown) => {\n if (key && val !== null && val !== undefined && isSensitive(key)) return REDACTED;\n if (typeof val === \"bigint\") return val.toString();\n if (val instanceof Error) return { name: val.name, message: val.message };\n return val;\n });\n return text ?? String(value);\n } catch {\n return String(value);\n }\n };\n\n return { isSensitive, scrub, json };\n}\n\nexport const defaultRedactor: Redactor = createRedactor();\n","import { globalSingleton } from \"./global\";\nimport { defaultRedactor } from \"./redact\";\n\nexport interface ErrFields {\n err_type?: string;\n err_message?: string;\n err_code?: string;\n err_stack?: string;\n err_cause?: string;\n /** Database errors (pg): the table and constraint the server reported. */\n db_table?: string;\n db_constraint?: string;\n}\n\nconst MAX_CAUSE_DEPTH = 5;\n\nexport function isErrorLike(v: unknown): v is Error {\n if (v instanceof Error) return true;\n return (\n typeof v === \"object\" &&\n v !== null &&\n typeof (v as { message?: unknown }).message === \"string\" &&\n (\"stack\" in v || \"name\" in v)\n );\n}\n\nfunction errorType(e: Error): string {\n // pg's DatabaseError keeps the lowercase name \"error\"; its class name says more.\n if (e.name && e.name !== \"Error\" && e.name !== \"error\") return e.name;\n const ctor = (e as { constructor?: { name?: string } }).constructor?.name;\n return ctor && ctor !== \"Object\" ? ctor : \"Error\";\n}\n\nexport function serializeError(err: unknown): ErrFields {\n if (!isErrorLike(err)) {\n if (typeof err === \"string\") return { err_type: \"string\", err_message: err };\n return { err_type: typeof err, err_message: defaultRedactor.json(err) };\n }\n const e = err as Error & { code?: unknown; cause?: unknown; table?: unknown; constraint?: unknown };\n const out: ErrFields = { err_type: errorType(e), err_message: String(e.message ?? \"\") };\n if (e.code !== undefined && e.code !== null) out.err_code = String(e.code);\n if (isSqlState(out.err_code)) {\n out.err_message = stripSql(out.err_message ?? \"\");\n if (typeof e.table === \"string\" && e.table) out.db_table = e.table;\n if (typeof e.constraint === \"string\" && e.constraint) out.db_constraint = e.constraint;\n }\n if (typeof e.stack === \"string\") out.err_stack = e.stack;\n\n const causes: string[] = [];\n let cause = e.cause;\n while (cause !== undefined && cause !== null && causes.length < MAX_CAUSE_DEPTH) {\n if (isErrorLike(cause)) {\n causes.push(`${errorType(cause)}: ${cause.message}`);\n cause = (cause as { cause?: unknown }).cause;\n } else {\n causes.push(defaultRedactor.json(cause));\n cause = undefined;\n }\n }\n if (causes.length > 0) out.err_cause = causes.join(\" <- \");\n return out;\n}\n\n// Postgres SQLSTATE codes: five digits or uppercase letters (23505, 40P01, 25P02).\nfunction isSqlState(code: string | undefined): boolean {\n return code !== undefined && /^[0-9A-Z]{5}$/.test(code);\n}\n\nconst SQL_START_RE = /^\\s*(?:select|insert|update|delete|with|create|alter|drop|truncate|lock)\\b/i;\n\n/**\n * knex prefixes a failed query's message with the whole statement (\"update ... - deadlock\n * detected\"). A long statement filled err_message and the truncation cut off the server's reason,\n * the only part worth reading. Keeps the reason; the statement never reaches the log.\n */\nexport function stripSql(message: string): string {\n if (!SQL_START_RE.test(message)) return message;\n const at = message.lastIndexOf(\" - \");\n return at === -1 ? message : message.slice(at + 3);\n}\n\n// The client hung up or sent a malformed request: worth a warn, not an error on our side.\nexport function isClientDisconnect(err: unknown): boolean {\n const e = err as { code?: unknown; message?: unknown } | null;\n const code = typeof e?.code === \"string\" ? e.code : \"\";\n return (\n code === \"ECONNRESET\" ||\n code === \"ECONNABORTED\" ||\n code === \"EPIPE\" ||\n code === \"ERR_STREAM_PREMATURE_CLOSE\" ||\n code.startsWith(\"HPE_\") ||\n e?.message === \"aborted\"\n );\n}\n\nconst logged = globalSingleton(\"logged\", () => new WeakSet<object>());\n\n// Marks an error as already written, so a later boundary (e.g. Next's onRequestError)\n// does not log it a second time.\nexport function markLogged(err: unknown): void {\n if (typeof err === \"object\" && err !== null) logged.add(err);\n}\n\nexport function isLogged(err: unknown): boolean {\n return typeof err === \"object\" && err !== null && logged.has(err);\n}\n","import { isErrorLike, serializeError } from \"./error\";\nimport type { Level } from \"./levels\";\nimport { REDACTED, toSnakeCase, type Redactor } from \"./redact\";\n\nexport { DEFAULT_REDACT_KEYS, toSnakeCase } from \"./redact\";\n\n/** Final per-field hook: return a replacement, or undefined to drop the field. */\nexport type RedactHook = (key: string, value: Primitive) => unknown;\n\nexport type Fields = Record<string, unknown>;\nexport type Primitive = string | number | boolean | null;\nexport type LogRecord = Record<string, Primitive>;\n\nexport interface NormalizeOptions {\n snakeCase: boolean;\n redactor: Redactor;\n hook?: RedactHook;\n}\n\n// Fields the redact hook never sees, so every line keeps its level, message and event.\nconst HOOK_EXEMPT = new Set([\"level\", \"message\", \"event\"]);\n\n// Keys owned by Vector (overwritten or deleted on ingest) or by the logger itself.\nexport const RESERVED_KEYS = new Set([\n \"project\", \"service\", \"vps\", \"version\", \"container_name\", \"container_id\", \"image\", \"stream\",\n \"_timestamp\", \"label\", \"host\", \"source_type\", \"msg\", \"lvl\", \"severity\", \"level\", \"message\",\n]);\n\nexport const MAX_LINE_BYTES = 16000;\nconst MAX_MESSAGE = 500;\nconst MAX_STACK = 4000;\nconst MAX_STRING = 1000;\nconst MAX_DEPTH = 3;\nconst TRUNCATED = \"…[truncated]\";\n\n// Fields kept when a line is too large.\nconst KEEP_ON_SHRINK = new Set([\n \"level\", \"message\", \"event\", \"request_id\", \"trace_id\", \"span_id\", \"job_name\", \"job_id\", \"job_attempt\",\n \"user_id\", \"tenant_id\", \"err_type\", \"err_message\", \"err_code\",\n]);\n\nexport function stripUrl(url: string): string {\n const noQuery = url.split(/[?#]/, 1)[0] ?? \"\";\n return noQuery.replace(/^([a-z][a-z0-9+.-]*:\\/\\/)[^/@\\s]*@/i, \"$1\");\n}\n\nexport function truncate(s: string, max: number): string {\n return s.length > max ? s.slice(0, max - TRUNCATED.length) + TRUNCATED : s;\n}\n\nfunction isPlainObject(v: unknown): v is Fields {\n if (typeof v !== \"object\" || v === null) return false;\n const proto = Object.getPrototypeOf(v);\n return proto === Object.prototype || proto === null;\n}\n\nfunction isUrlKey(key: string): boolean {\n return key === \"http_path\" || key === \"http_url\" || key.endsWith(\"_url\");\n}\n\nfunction flattenInto(out: LogRecord, prefix: string, obj: Fields, depth: number, opts: NormalizeOptions): void {\n for (const [rawKey, value] of Object.entries(obj)) {\n const key = opts.snakeCase ? toSnakeCase(rawKey) : rawKey;\n const full = prefix ? `${prefix}_${key}` : key;\n if (value === undefined || typeof value === \"function\" || typeof value === \"symbol\") continue;\n if (value !== null && (opts.redactor.isSensitive(rawKey) || opts.redactor.isSensitive(full))) {\n out[full] = REDACTED;\n continue;\n }\n if (value === null || typeof value === \"string\" || typeof value === \"boolean\") {\n out[full] = value;\n } else if (typeof value === \"number\") {\n out[full] = Number.isFinite(value) ? value : String(value);\n } else if (typeof value === \"bigint\") {\n out[full] = value.toString();\n } else if (value instanceof Date) {\n out[full] = Number.isNaN(value.getTime()) ? \"Invalid Date\" : value.toISOString();\n } else if (isErrorLike(value)) {\n out[full] = `${value.name}: ${value.message}`;\n } else if (isPlainObject(value) && depth < MAX_DEPTH - 1) {\n flattenInto(out, full, value, depth + 1, opts);\n } else {\n // Arrays, deep objects, class instances: stringified with sensitive keys redacted.\n out[full] = opts.redactor.json(value);\n }\n }\n}\n\n// Correlation ids are opaque tokens: value patterns such as phoneVN can match inside a hex\n// segment and break the join between services, so a well-formed id is never scrubbed.\nconst ID_VALUE_RE = /^[A-Za-z0-9._:-]{1,128}$/;\n\nfunction isIdKey(key: string): boolean {\n return key === \"request_id\" || key === \"trace_id\" || key === \"span_id\" || key.endsWith(\"_request_id\");\n}\n\nfunction finalize(key: string, value: Primitive, opts: NormalizeOptions): Primitive {\n if (typeof value !== \"string\") return value;\n if (isIdKey(key) && ID_VALUE_RE.test(value)) return value;\n const v = opts.redactor.scrub(isUrlKey(key) ? stripUrl(value) : value);\n return truncate(v, key === \"err_stack\" ? MAX_STACK : MAX_STRING);\n}\n\nexport function buildRecord(\n level: Level,\n message: unknown,\n sources: (Fields | undefined)[],\n opts: NormalizeOptions,\n): LogRecord {\n const merged: Fields = {};\n for (const source of sources) if (source) Object.assign(merged, source);\n\n let err: unknown;\n if (merged.err !== undefined && merged.err !== null) {\n err = merged.err;\n delete merged.err;\n } else if (isErrorLike(merged.error)) {\n err = merged.error;\n delete merged.error;\n }\n\n const flat: LogRecord = {};\n flattenInto(flat, \"\", merged, 0, opts);\n if (err !== undefined) Object.assign(flat, serializeError(err));\n\n const text = typeof message === \"string\" ? message : opts.redactor.json(message);\n const out: LogRecord = { level, message: truncate(opts.redactor.scrub(text), MAX_MESSAGE) };\n for (const [k, v] of Object.entries(flat)) {\n const key = RESERVED_KEYS.has(k) ? `app_${k}` : k;\n let value = finalize(key, v, opts);\n if (opts.hook && !HOOK_EXEMPT.has(key)) {\n const replaced = opts.hook(key, value);\n if (replaced === undefined) continue;\n value = typeof replaced === \"object\" && replaced !== null ? opts.redactor.json(replaced) : (replaced as Primitive);\n }\n out[key] = value;\n }\n return out;\n}\n\nfunction byteLength(s: string): number {\n // UTF-8 uses at most 3 bytes per UTF-16 code unit: skip encoding short lines.\n if (s.length * 3 <= MAX_LINE_BYTES) return s.length;\n return new TextEncoder().encode(s).length;\n}\n\nexport function serializeRecord(record: LogRecord): string {\n const line = JSON.stringify(record);\n if (byteLength(line) <= MAX_LINE_BYTES) return line;\n const small: LogRecord = {};\n for (const [k, v] of Object.entries(record)) {\n if (KEEP_ON_SHRINK.has(k) || k.startsWith(\"http_\")) small[k] = v;\n }\n small.log_truncated = true;\n return JSON.stringify(small);\n}\n","// No imports: this module is shared with the edge entry (next-edge).\nexport const REQUEST_ID_RE = /^[A-Za-z0-9._-]{1,64}$/;\nconst TRACEPARENT_RE = /^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/;\n\nexport function newRequestId(): string {\n return globalThis.crypto.randomUUID();\n}\n\nfunction first(header?: string | string[] | null): string | undefined {\n return Array.isArray(header) ? header[0] : (header ?? undefined);\n}\n\nexport function resolveRequestId(header?: string | string[] | null): string {\n const value = first(header);\n return value && REQUEST_ID_RE.test(value) ? value : newRequestId();\n}\n\nexport function parseTraceparent(header?: string | string[] | null): { trace_id: string; span_id: string } | undefined {\n const value = first(header)?.trim().toLowerCase();\n const m = value ? TRACEPARENT_RE.exec(value) : null;\n if (!m) return undefined;\n const [, version, traceId, spanId] = m as unknown as [string, string, string, string];\n if (version === \"ff\" || /^0+$/.test(traceId) || /^0+$/.test(spanId)) return undefined;\n return { trace_id: traceId, span_id: spanId };\n}\n","import { getContext } from \"./context\";\nimport { isClientDisconnect, markLogged, serializeError } from \"./error\";\nimport type { Logger } from \"./logger\";\nimport { stripUrl, type Fields } from \"./normalize\";\nimport { parseTraceparent, resolveRequestId } from \"./request-id\";\n\nexport { newRequestId, parseTraceparent, REQUEST_ID_RE, resolveRequestId } from \"./request-id\";\n\nexport type HeaderSource = Headers | Record<string, string | string[] | undefined>;\n\nfunction header(headers: HeaderSource, name: string): string | string[] | undefined {\n if (typeof (headers as Headers).get === \"function\") return (headers as Headers).get(name) ?? undefined;\n return (headers as Record<string, string | string[] | undefined>)[name];\n}\n\nexport function requestContextFields(headers: HeaderSource): { request_id: string; trace_id?: string; span_id?: string } {\n const out: { request_id: string; trace_id?: string; span_id?: string } = {\n request_id: resolveRequestId(header(headers, \"x-request-id\")),\n };\n const tp = parseTraceparent(header(headers, \"traceparent\"));\n if (tp) Object.assign(out, tp);\n return out;\n}\n\n// Headers to forward to services we own, so their logs share request_id / trace_id.\nexport function propagationHeaders(): Record<string, string> {\n const ctx = getContext();\n const out: Record<string, string> = {};\n if (typeof ctx.request_id === \"string\") out[\"x-request-id\"] = ctx.request_id;\n if (typeof ctx.trace_id === \"string\" && typeof ctx.span_id === \"string\") {\n out.traceparent = `00-${ctx.trace_id}-${ctx.span_id}-01`;\n }\n return out;\n}\n\nexport const DEFAULT_SKIP_PATHS: (string | RegExp)[] = [\n // Also under a prefix such as /api/v1/health.\n /(^|\\/)(health|healthz|ready|readyz|livez)\\/?$/,\n \"/favicon.ico\",\n /^\\/_next\\/static\\//,\n];\n\nexport interface HttpLogOptions {\n skipPaths?: (string | RegExp)[];\n}\n\nexport interface HttpRequestInfo {\n method: string;\n route?: string;\n path: string;\n status: number;\n duration_ms?: number;\n err?: unknown;\n fields?: Fields;\n}\n\nexport function shouldSkip(method: string, path: string, skipPaths: (string | RegExp)[] = DEFAULT_SKIP_PATHS): boolean {\n if (method.toUpperCase() === \"OPTIONS\") return true;\n const p = stripUrl(path);\n return skipPaths.some((s) => (typeof s === \"string\" ? p === s : s.test(p)));\n}\n\n// Writes the one `http.request` summary line for an inbound request. Skipped paths are still\n// logged when they fail with a 5xx, so a failing health check stays visible.\nexport function logHttpRequest(log: Logger, info: HttpRequestInfo, opts: HttpLogOptions = {}): void {\n if (info.status < 500 && shouldSkip(info.method, info.path, opts.skipPaths)) return;\n const hasErr = info.err !== undefined && info.err !== null;\n // A client that hung up mid-request is not a server failure, whatever status the app set.\n const clientGone = hasErr && isClientDisconnect(info.err);\n const level = info.status >= 500 && !clientGone ? \"error\" : info.status >= 400 ? \"warn\" : \"info\";\n const path = stripUrl(info.path);\n const errFields: Fields = {};\n if (hasErr) {\n Object.assign(errFields, serializeError(info.err));\n if (info.status < 500 || clientGone) delete errFields.err_stack;\n if (clientGone) errFields.client_disconnect = true;\n markLogged(info.err);\n }\n // Route templates keep the message bounded; the raw path would make one message per URL.\n const message = info.route ? `${info.method} ${info.route} ${info.status}` : `${info.method} ${info.status}`;\n log[level](message, {\n ...info.fields,\n event: \"http.request\",\n http_method: info.method,\n http_route: info.route,\n http_path: path,\n http_status: info.status,\n duration_ms: info.duration_ms === undefined ? undefined : Math.round(info.duration_ms),\n ...errFields,\n });\n}\n","import { globalSingleton } from \"./global\";\nimport type { Logger } from \"./logger\";\nimport type { Fields } from \"./normalize\";\n\nexport function logStartup(log: Logger, fields: Fields = {}): void {\n log.info(\"app started\", {\n event: \"app.started\",\n runtime_version: `node ${process.versions.node}`,\n log_level: log.level,\n ...fields,\n });\n}\n\n/** Call at the start of your own shutdown handler (e.g. on SIGTERM). The library never handles signals. */\nexport function logShutdown(log: Logger, fields: Fields = {}): void {\n log.info(\"app stopping\", { event: \"app.stopping\", ...fields });\n}\n\nexport interface ProcessHandlerOptions {\n /** Exit with code 1 after an uncaught error. Next.js keeps serving, so its adapter passes false. */\n exitOnCrash?: boolean;\n /** Time other crash handlers (Sentry, APM) get to flush before exit. Default 1000 ms. */\n exitDelayMs?: number;\n exit?: (code: number) => void;\n}\n\nexport function crashHandlers(log: Logger, opts: ProcessHandlerOptions = {}) {\n const exitOnCrash = opts.exitOnCrash ?? true;\n const exitDelayMs = opts.exitDelayMs ?? 1000;\n const exit = opts.exit ?? ((code: number) => process.exit(code));\n let exiting = false;\n const crash = (source: string, err: unknown) => {\n if (!exitOnCrash) {\n log.error(\"unhandled error\", { event: \"app.unhandled_error\", crash_source: source, err });\n return;\n }\n log.fatal(\"app crashed\", { event: \"app.crashed\", crash_source: source, err });\n if (exiting) return;\n exiting = true;\n if (typeof process !== \"undefined\") process.exitCode = 1;\n // Deferred so listeners registered after ours still run; unref so a process with nothing\n // left to do exits on its own (with exitCode 1) without waiting.\n const timer = setTimeout(() => exit(1), exitDelayMs);\n (timer as { unref?: () => void }).unref?.();\n };\n return {\n onUncaught: (err: unknown) => crash(\"uncaughtException\", err),\n onRejection: (reason: unknown) => crash(\"unhandledRejection\", reason),\n };\n}\n\nconst state = globalSingleton(\"process\", () => ({ installed: false }));\n\n/** Logs uncaught exceptions and unhandled rejections. Does not touch SIGTERM/SIGINT. */\nexport function installProcessHandlers(log: Logger, opts: ProcessHandlerOptions = {}): void {\n if (state.installed || typeof process === \"undefined\" || typeof process.on !== \"function\") return;\n state.installed = true;\n const h = crashHandlers(log, opts);\n process.on(\"uncaughtException\", h.onUncaught);\n process.on(\"unhandledRejection\", h.onRejection);\n}\n\nconst warningState = globalSingleton(\"warnings\", () => ({ installed: false }));\n\n/**\n * Node keeps 10 frames by default; ORM/framework frames (knex, Strapi, Prisma) often use all of\n * them, hiding the app code that triggered a warning or error. Only ever raises the limit.\n */\nexport function raiseStackTraceLimit(limit: number): void {\n if (Error.stackTraceLimit < limit) Error.stackTraceLimit = limit;\n}\n\nexport interface ProcessWarningOptions {\n stackTraceLimit?: number;\n /**\n * Remove Node's own stderr printer, so a warning is one JSON line instead of that line plus\n * \"(node:1) Warning: ...\" and \"(Use `node --trace-deprecation ...`...)\". Default true.\n */\n replaceDefault?: boolean;\n /**\n * A repeated warning is written at most once per window (default 1 hour). The next line carries\n * `suppressed_count`, the repeats dropped since the previous line, so the frequency stays visible.\n */\n repeatWindowMs?: number;\n now?: () => number;\n}\n\n// Distinct warnings tracked; past this a new kind is logged every time instead of throttled.\nconst MAX_TRACKED_WARNINGS = 200;\n\n/**\n * Logs Node process warnings (deprecations, MaxListeners...) as `process.warning` lines whose\n * err_stack points at the code that triggered them. Repeats are throttled (see repeatWindowMs).\n * Also raises Error.stackTraceLimit (default 30) so the stack reaches past framework frames.\n */\nexport function logProcessWarnings(log: Logger, opts: ProcessWarningOptions = {}): void {\n if (warningState.installed || typeof process === \"undefined\" || typeof process.on !== \"function\") return;\n warningState.installed = true;\n raiseStackTraceLimit(opts.stackTraceLimit ?? 30);\n if (opts.replaceDefault ?? true) {\n for (const l of process.listeners(\"warning\")) if (l.name === \"onWarning\") process.off(\"warning\", l);\n }\n const windowMs = opts.repeatWindowMs ?? 60 * 60 * 1000;\n const now = opts.now ?? Date.now;\n const tracked = new Map<string, { loggedAt: number; suppressed: number }>();\n process.on(\"warning\", (warning: Error) => {\n const key = `${warning?.name}:${(warning as { code?: unknown })?.code ?? \"\"}:${warning?.message}`;\n const t = now();\n const entry = tracked.get(key);\n if (entry && t - entry.loggedAt < windowMs) {\n entry.suppressed += 1;\n return;\n }\n if (entry) tracked.set(key, { loggedAt: t, suppressed: 0 });\n else if (tracked.size < MAX_TRACKED_WARNINGS) tracked.set(key, { loggedAt: t, suppressed: 0 });\n log.warn(\"process warning\", {\n event: \"process.warning\",\n suppressed_count: entry ? entry.suppressed : undefined,\n err: warning,\n });\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,8BAAkC;;;ACE3B,SAAS,gBAAmB,MAAc,MAAkB;AACjE,QAAM,MAAM,uBAAO,IAAI,iBAAiB,IAAI,EAAE;AAC9C,QAAM,IAAI;AACV,MAAI,QAAQ,EAAE,GAAG;AACjB,MAAI,UAAU,QAAW;AACvB,YAAQ,KAAK;AACb,MAAE,GAAG,IAAI;AAAA,EACX;AACA,SAAO;AACT;;;ADCA,IAAM,MAAM,gBAAgB,OAAO,MAAM,IAAI,0CAAgC,CAAC;AAIvE,SAAS,aAAgB,QAAgB,IAAmC;AACjF,QAAM,SAAS,IAAI,SAAS;AAC5B,QAAM,QAAsB,EAAE,QAAQ,EAAE,GAAG,QAAQ,QAAQ,GAAG,OAAO,GAAG,OAAO;AAC/E,SAAO,IAAI,IAAI,OAAO,MAAM,GAAG,KAAK,CAAC;AACvC;;;AEjBO,IAAM,sBAAsB;AAAA,EACjC;AAAA,EAAY;AAAA,EAAU;AAAA,EAAO;AAAA,EAAc;AAAA,EAAU;AAAA,EACrD;AAAA,EAAS;AAAA,EAAgB;AAAA,EAAiB;AAAA,EAAY;AAAA,EACtD;AAA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G,OAAO,oBAAoB,KAAK,MAAM,MAAM,CAAC;AAChG,eAAO;AAAA,MACT,SAAS,QAAQ;AACf,cAAM,UAAU,kBAAkB,MAAM;AACxC,YAAI,YAAY,QAAW;AACzB,cAAI,KAAK,2BAA2B,EAAE,GAAG,OAAO,GAAG,OAAO,oBAAoB,qBAAqB,QAAQ,CAAC;AAC5G,gBAAM;AAAA,QACR;AACA,cAAM,MAAM,QAAQ,MAAM;AAC1B,YAAI,MAAM,wBAAwB,EAAE,GAAG,OAAO,GAAG,OAAO,iBAAiB,IAAI,CAAC;AAC9E,mBAAW,GAAG;AACd,cAAM;AAAA,MACR;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":["header"]}
1
+ {"version":3,"sources":["../src/next.ts","../src/context.ts","../src/global.ts","../src/redact.ts","../src/error.ts","../src/normalize.ts","../src/request-id.ts","../src/http.ts","../src/process.ts"],"sourcesContent":["import { runWithStore } from \"./context\";\nimport { isErrorLike, isLogged, markLogged } from \"./error\";\nimport { logHttpRequest, requestContextFields, type HeaderSource, type HttpLogOptions } from \"./http\";\nimport type { Logger } from \"./logger\";\nimport type { Fields } from \"./normalize\";\nimport { installProcessHandlers, logProcessWarnings, logStartup } from \"./process\";\n\nexport interface WithLoggingOptions extends HttpLogOptions {\n /** Route template, e.g. \"/api/orders/[id]\". Left empty when not given. */\n route?: string;\n}\n\n/** Status for Next's control-flow errors (redirect(), notFound(), forbidden()...), else undefined. */\nexport function nextControlStatus(err: unknown): number | undefined {\n const digest = (err as { digest?: unknown } | null)?.digest;\n if (typeof digest !== \"string\") return undefined;\n if (digest.startsWith(\"NEXT_REDIRECT\")) {\n const status = Number(digest.split(\";\")[3]);\n return Number.isInteger(status) && status >= 300 ? status : 307;\n }\n if (digest === \"NEXT_NOT_FOUND\") return 404;\n if (digest.startsWith(\"NEXT_HTTP_ERROR_FALLBACK;\")) return Number(digest.split(\";\")[1]) || 404;\n return undefined;\n}\n\nfunction asError(value: unknown): unknown {\n if (typeof value === \"object\" && value !== null) return value;\n return Object.assign(new Error(String(value)), { name: \"NonErrorThrown\", thrown: value });\n}\n\nfunction trySetHeader(res: Response, name: string, value: string): void {\n try {\n res.headers.set(name, value);\n } catch {\n // Some responses (Response.redirect, proxied fetch responses) have immutable headers.\n }\n}\n\n/** Any App Router route handler: `()`, `(request)` or `(request, { params })`. */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type RouteHandler = (...args: any[]) => Response | Promise<Response>;\n\n/**\n * Wraps an App Router route handler: request context + one http.request line. The returned\n * function has exactly the handler's parameters, so Next's route type checks still pass.\n */\nexport function withLogging<H extends RouteHandler>(\n log: Logger,\n handler: H,\n opts: WithLoggingOptions = {},\n): (...args: Parameters<H>) => Promise<Awaited<ReturnType<H>>> {\n return async (...args): Promise<Awaited<ReturnType<H>>> => {\n const request: unknown = args[0];\n // Next always passes the request; direct calls in unit tests may not.\n if (!(request instanceof Request)) return (await handler(...args)) as Awaited<ReturnType<H>>;\n const ctx = requestContextFields(request.headers);\n const path = new URL(request.url).pathname;\n const start = performance.now();\n return await runWithStore(ctx, async (store): Promise<Awaited<ReturnType<H>>> => {\n const summary = (status: number, err: unknown) =>\n logHttpRequest(\n log,\n {\n method: request.method,\n route: opts.route,\n path,\n status,\n duration_ms: performance.now() - start,\n err,\n fields: store.fields,\n },\n opts,\n );\n try {\n const res = (await handler(...args)) as Awaited<ReturnType<H>>;\n summary((res as Response).status, store.error);\n trySetHeader(res as Response, \"x-request-id\", ctx.request_id);\n return res;\n } catch (caught) {\n const control = nextControlStatus(caught);\n // Non-objects cannot be marked as logged, so onRequestError would log them again.\n const err = control === undefined ? asError(caught) : caught;\n summary(control ?? 500, control === undefined ? err : store.error);\n throw err;\n }\n });\n };\n}\n\n/**\n * patchConsole skip predicate for Next.js: Next prints a render error with console.error right\n * before calling onRequestError, by then the error carries a digest. Dropping that console\n * call leaves the single, richer onRequestError line.\n */\nexport function nextConsoleSkip(args: unknown[]): boolean {\n return args.some((arg) => isErrorLike(arg) && typeof (arg as { digest?: unknown }).digest === \"string\");\n}\n\nexport interface NextRequestInfo {\n path?: string;\n method?: string;\n headers?: Record<string, string | string[] | undefined>;\n}\n\nexport interface NextErrorContext {\n routerKind?: string;\n routePath?: string;\n routeType?: string;\n}\n\n/** `export const onRequestError = nextOnRequestError(log)` in instrumentation.ts. */\nexport function nextOnRequestError(log: Logger, opts: HttpLogOptions = {}) {\n return async (err: unknown, request: NextRequestInfo, context: NextErrorContext): Promise<void> => {\n if (isLogged(err) || nextControlStatus(err) !== undefined) return;\n const digest = (err as { digest?: unknown } | null)?.digest;\n logHttpRequest(\n log,\n {\n method: request?.method ?? \"GET\",\n route: context?.routePath,\n path: request?.path ?? \"\",\n status: 500,\n err,\n fields: {\n ...requestContextFields(request?.headers ?? {}),\n next_route_type: context?.routeType,\n next_router_kind: context?.routerKind,\n next_digest: typeof digest === \"string\" ? digest : undefined,\n },\n },\n opts,\n );\n };\n}\n\n/** Call from `register()` in instrumentation.ts. Does nothing on the edge runtime. */\nexport function registerNext(log: Logger, fields?: Fields): void {\n if (process.env.NEXT_RUNTIME && process.env.NEXT_RUNTIME !== \"nodejs\") return;\n // Next keeps serving after an unhandled rejection, so do not exit.\n installProcessHandlers(log, { exitOnCrash: false });\n logProcessWarnings(log);\n logStartup(log, { port: process.env.PORT ? Number(process.env.PORT) : undefined, ...fields });\n}\n\nexport interface WithActionOptions {\n /** Request headers source. Defaults to `headers()` from next/headers. */\n headers?: () => HeaderSource | Promise<HeaderSource>;\n}\n\nasync function nextHeaders(): Promise<HeaderSource> {\n try {\n const mod = (await import(\"next/headers\")) as { headers: () => HeaderSource | Promise<HeaderSource> };\n return await mod.headers();\n } catch {\n // Called outside a request (tests, scripts) or Next is not installed.\n return {};\n }\n}\n\n/**\n * Wraps a server action: request context (request_id from x-request-id) plus one\n * `action.completed` / `action.failed` line. redirect()/notFound() count as completed.\n */\nexport function withAction<A extends unknown[], R>(\n log: Logger,\n name: string,\n action: (...args: A) => Promise<R>,\n opts: WithActionOptions = {},\n): (...args: A) => Promise<R> {\n return async (...args) => {\n const headers = await (opts.headers ?? nextHeaders)();\n const start = performance.now();\n return runWithStore({ ...requestContextFields(headers), action_name: name }, async (store) => {\n const fields = () => ({ ...store.fields, duration_ms: Math.round(performance.now() - start) });\n try {\n const result = await action(...args);\n log.info(\"server action completed\", { ...fields(), event: \"action.completed\", err: store.error });\n return result;\n } catch (caught) {\n const control = nextControlStatus(caught);\n if (control !== undefined) {\n log.info(\"server action completed\", { ...fields(), event: \"action.completed\", next_control_status: control });\n throw caught;\n }\n const err = asError(caught);\n log.error(\"server action failed\", { ...fields(), event: \"action.failed\", err });\n markLogged(err);\n throw err;\n }\n });\n };\n}\n","import { AsyncLocalStorage } from \"node:async_hooks\";\nimport { globalSingleton } from \"./global\";\nimport type { Fields } from \"./normalize\";\n\nexport interface ContextStore {\n fields: Fields;\n error?: unknown;\n /** Route template captured while the router still knew it (Express error path). */\n route?: string;\n parent?: ContextStore;\n}\n\nconst als = globalSingleton(\"als\", () => new AsyncLocalStorage<ContextStore>());\n\nexport const STORE_KEY: symbol = Symbol.for(\"@tanngo11/log.store\");\n\nexport function runWithStore<T>(fields: Fields, fn: (store: ContextStore) => T): T {\n const parent = als.getStore();\n const store: ContextStore = { fields: { ...parent?.fields, ...fields }, parent };\n return als.run(store, () => fn(store));\n}\n\nexport function withContext<T>(fields: Fields, fn: () => T): T {\n return runWithStore(fields, () => fn());\n}\n\nexport function currentStore(): ContextStore | undefined {\n return als.getStore();\n}\n\nexport function getContext(): Fields {\n return als.getStore()?.fields ?? {};\n}\n\n// Applies to the current context and every enclosing one, so a field added inside a nested\n// withContext/runJob still reaches the request's http.request line.\nexport function addContext(fields: Fields): void {\n for (let s = als.getStore(); s; s = s.parent) Object.assign(s.fields, fields);\n}\n\n// Sets the error on the store and on enclosing stores that have none yet.\nexport function recordErrorIn(store: ContextStore, err: unknown): void {\n store.error = err;\n for (let s = store.parent; s; s = s.parent) if (s.error === undefined) s.error = err;\n}\n\n// Marks the error that the current request/job summary line should carry. Does not write a line.\nexport function recordError(err: unknown): void {\n const store = als.getStore();\n if (store) recordErrorIn(store, err);\n}\n\nexport function attachStore(target: object, store: ContextStore): void {\n (target as Record<symbol, ContextStore>)[STORE_KEY] = store;\n}\n\nexport function storeOf(target: unknown): ContextStore | undefined {\n if (typeof target !== \"object\" || target === null) return undefined;\n return (target as Record<symbol, ContextStore | undefined>)[STORE_KEY];\n}\n","// Singletons shared by every copy of this package loaded in the process (ESM and CJS builds,\n// or duplicated installs), so context and dedupe state never split.\nexport function globalSingleton<T>(name: string, make: () => T): T {\n const key = Symbol.for(`@tanngo11/log.${name}`);\n const g = globalThis as unknown as Record<symbol, T | undefined>;\n let value = g[key];\n if (value === undefined) {\n value = make();\n g[key] = value;\n }\n return value;\n}\n","// Redaction shared by the logger and the error serializer. The collector redacts again,\n// but it cannot see secrets inside JSON-encoded strings, so the app side must catch them.\n\nexport const DEFAULT_REDACT_KEYS = [\n \"password\", \"passwd\", \"pwd\", \"passphrase\", \"secret\", \"client_secret\",\n \"token\", \"access_token\", \"refresh_token\", \"id_token\", \"auth_token\",\n \"api_key\", \"apikey\", \"access_key\", \"secret_key\", \"private_key\",\n \"authorization\", \"cookie\", \"set_cookie\", \"session_id\", \"sessionid\",\n \"credential\", \"credentials\", \"dsn\", \"connection_string\", \"conn_string\", \"jwt\", \"bearer\",\n];\n\n/** Opt-in value patterns for `redactValues`. Not on by default: they can hit ordinary numbers. */\nexport const REDACT_PATTERNS = {\n /**\n * Vietnamese mobile numbers: 0912345678, +84912345678, 84912345678, also \"SDT0912345678\". A\n * hex letter (a-f) on either side rules a match out, so hex ids (a UUID segment such as\n * 0912345678e0) are left alone.\n */\n phoneVN: /(?<![\\dA-Fa-f+])(?:\\+?84|0)[35789]\\d{8}(?![\\dA-Fa-f])/g,\n /** Visa, Mastercard, Amex, Discover-like card numbers, with optional spaces or dashes. */\n paymentCard: /(?<!\\d)(?:4\\d{3}|5[1-5]\\d{2}|2[2-7]\\d{2}|3[47]\\d{2}|6(?:011|5\\d{2}))(?:[ -]?\\d{4}){2}[ -]?\\d{1,4}(?!\\d)/g,\n /** IPv4 addresses. */\n ipv4: /(?<![\\d.])(?:\\d{1,3}\\.){3}\\d{1,3}(?![\\d.])/g,\n} as const;\n\n// Keys that only describe a secret (count, type, timestamps, flags) stay readable.\nconst SAFE_SUFFIXES = [\"_count\", \"_type\", \"_length\", \"_expires_at\", \"_expires_in\", \"_ttl\", \"_at\", \"_ms\", \"_enabled\"];\n\nexport const REDACTED = \"[REDACTED]\";\n\nexport function toSnakeCase(key: string): string {\n return key\n .replace(/([a-z0-9])([A-Z])/g, \"$1_$2\")\n .replace(/([A-Z]+)([A-Z][a-z])/g, \"$1_$2\")\n .replace(/[^A-Za-z0-9_]+/g, \"_\")\n .toLowerCase();\n}\n\nconst URL_CREDENTIALS_RE = /([a-z][a-z0-9+.-]*:\\/\\/)[^\\s/@:\"']+:[^\\s/@\"']+@/gi;\nconst BEARER_RE = /\\bBearer\\s+[A-Za-z0-9._~+/=-]+/gi;\nconst JWT_RE = /\\beyJ[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+/g;\nconst EMAIL_RE = /[A-Za-z0-9._%+-]+@([A-Za-z0-9-]+(?:\\.[A-Za-z0-9-]+)*\\.[A-Za-z]{2,})/g;\n\nexport type KeyPattern = string | RegExp;\n\nexport interface RedactorOptions {\n /** Extra sensitive keys: names (matched like the defaults) or patterns tested on the snake_case key. */\n keys?: readonly KeyPattern[];\n /** Extra value patterns; every match inside any string becomes [REDACTED]. */\n values?: readonly RegExp[];\n}\n\nexport interface Redactor {\n isSensitive(key: string): boolean;\n /** Masks secrets and emails that appear inside free text. */\n scrub(s: string): string;\n /** JSON.stringify that redacts sensitive keys at any depth and never throws. */\n json(value: unknown): string;\n}\n\nfunction globalize(re: RegExp): RegExp {\n return re.flags.includes(\"g\") ? new RegExp(re.source, re.flags) : new RegExp(re.source, `${re.flags}g`);\n}\n\nexport function createRedactor(opts: RedactorOptions = {}): Redactor {\n const words = [...DEFAULT_REDACT_KEYS];\n const keyPatterns: RegExp[] = [];\n for (const k of opts.keys ?? []) {\n if (typeof k === \"string\") words.push(toSnakeCase(k));\n else keyPatterns.push(new RegExp(k.source, k.flags.replace(\"g\", \"\")));\n }\n const valuePatterns = (opts.values ?? []).map(globalize);\n\n const isSensitive = (key: string): boolean => {\n const k = toSnakeCase(key);\n if (keyPatterns.some((re) => re.test(k))) return true;\n if (!words.includes(k) && SAFE_SUFFIXES.some((s) => k.endsWith(s))) return false;\n return words.some((w) => k === w || k.startsWith(`${w}_`) || k.endsWith(`_${w}`) || k.includes(`_${w}_`));\n };\n\n const scrub = (s: string): string => {\n let out = s\n .replace(URL_CREDENTIALS_RE, `$1${REDACTED}@`)\n .replace(BEARER_RE, `Bearer ${REDACTED}`)\n .replace(JWT_RE, \"[REDACTED_JWT]\")\n .replace(EMAIL_RE, \"***@$1\");\n for (const re of valuePatterns) out = out.replace(re, REDACTED);\n return out;\n };\n\n const json = (value: unknown): string => {\n if (typeof value === \"string\") return value;\n try {\n const text = JSON.stringify(value, (key, val: unknown) => {\n if (key && val !== null && val !== undefined && isSensitive(key)) return REDACTED;\n if (typeof val === \"bigint\") return val.toString();\n if (val instanceof Error) return { name: val.name, message: val.message };\n return val;\n });\n return text ?? String(value);\n } catch {\n return String(value);\n }\n };\n\n return { isSensitive, scrub, json };\n}\n\nexport const defaultRedactor: Redactor = createRedactor();\n","import { globalSingleton } from \"./global\";\nimport { defaultRedactor } from \"./redact\";\n\nexport interface ErrFields {\n err_type?: string;\n err_message?: string;\n err_code?: string;\n err_stack?: string;\n err_cause?: string;\n /** Database errors (pg): the table and constraint the server reported. */\n db_table?: string;\n db_constraint?: string;\n}\n\nconst MAX_CAUSE_DEPTH = 5;\n\nexport function isErrorLike(v: unknown): v is Error {\n if (v instanceof Error) return true;\n return (\n typeof v === \"object\" &&\n v !== null &&\n typeof (v as { message?: unknown }).message === \"string\" &&\n (\"stack\" in v || \"name\" in v)\n );\n}\n\nfunction errorType(e: Error): string {\n // pg's DatabaseError keeps the lowercase name \"error\"; its class name says more.\n if (e.name && e.name !== \"Error\" && e.name !== \"error\") return e.name;\n const ctor = (e as { constructor?: { name?: string } }).constructor?.name;\n return ctor && ctor !== \"Object\" ? ctor : \"Error\";\n}\n\nexport function serializeError(err: unknown): ErrFields {\n if (!isErrorLike(err)) {\n if (typeof err === \"string\") return { err_type: \"string\", err_message: err };\n return { err_type: typeof err, err_message: defaultRedactor.json(err) };\n }\n const e = err as Error & { code?: unknown; cause?: unknown; table?: unknown; constraint?: unknown };\n const message = String(e.message ?? \"\");\n const out: ErrFields = { err_type: errorType(e), err_message: message };\n if (e.code !== undefined && e.code !== null) out.err_code = String(e.code);\n out.err_message = cleanMessage(message, out.err_code);\n if (isSqlState(out.err_code)) {\n if (typeof e.table === \"string\" && e.table) out.db_table = e.table;\n if (typeof e.constraint === \"string\" && e.constraint) out.db_constraint = e.constraint;\n }\n if (typeof e.stack === \"string\") out.err_stack = replaceOnce(e.stack, message, out.err_message);\n\n const causes: string[] = [];\n let cause = e.cause;\n while (cause !== undefined && cause !== null && causes.length < MAX_CAUSE_DEPTH) {\n if (isErrorLike(cause)) {\n const code = (cause as { code?: unknown }).code;\n const causeCode = code === undefined || code === null ? undefined : String(code);\n causes.push(`${errorType(cause)}: ${cleanMessage(String(cause.message ?? \"\"), causeCode)}`);\n cause = (cause as { cause?: unknown }).cause;\n } else {\n causes.push(defaultRedactor.json(cause));\n cause = undefined;\n }\n }\n if (causes.length > 0) out.err_cause = causes.join(\" <- \");\n return out;\n}\n\n// Postgres SQLSTATE codes: five digits or uppercase letters (23505, 40P01, 25P02).\nfunction isSqlState(code: string | undefined): boolean {\n return code !== undefined && /^[0-9A-Z]{5}$/.test(code);\n}\n\n// A statement, optionally behind comments or opening parentheses (\"(select ...) union ...\").\nconst SQL_START_RE = /^\\s*(?:\\/\\*[\\s\\S]*?\\*\\/\\s*)*\\(*\\s*(?:select|insert|update|delete|with|create|alter|drop|truncate|lock)\\b/i;\n// Without a SQLSTATE code, the part before \" - \" must also read like SQL, so a message such as\n// \"Update failed - retry later\" stays whole.\nconst SQL_BODY_RE = /[\"`]|\\b(?:from|into|set|values|where|table|returning)\\b/i;\n\n/**\n * knex prefixes every failed query's message with the statement, whatever the driver or error\n * (pg with or without a SQLSTATE, MySQL ER_*, SQLite, \"Connection terminated\"). Drops it.\n */\nfunction cleanMessage(message: string, code: string | undefined): string {\n const at = message.lastIndexOf(\" - \");\n if (at === -1 || !SQL_START_RE.test(message)) return message;\n if (!isSqlState(code) && !SQL_BODY_RE.test(message.slice(0, at))) return message;\n return stripSql(message);\n}\n\n// V8 renders the stack's first line from the message when .stack is first read. For knex errors\n// that is after the statement was prefixed, so the stack repeats it.\nfunction replaceOnce(text: string, find: string, replacement: string | undefined): string {\n if (replacement === undefined || find === replacement || find === \"\") return text;\n const at = text.indexOf(find);\n return at === -1 ? text : text.slice(0, at) + replacement + text.slice(at + find.length);\n}\n\n/**\n * knex prefixes a failed query's message with the whole statement (\"update ... - deadlock\n * detected\"). A long statement filled err_message and the truncation cut off the server's reason,\n * the only part worth reading. Keeps the reason; the statement never reaches the log. Cuts at the\n * last \" - \": a reason that contains \" - \" loses its start, which is safer than keeping part of a\n * statement that contains one (arithmetic, string literals).\n */\nexport function stripSql(message: string): string {\n if (!SQL_START_RE.test(message)) return message;\n const at = message.lastIndexOf(\" - \");\n return at === -1 ? message : message.slice(at + 3);\n}\n\n/**\n * For errors Koa emits on the inbound socket (strapiServerErrors): the client hung up or sent a\n * malformed request. Not valid for errors in general: knex's pool rejects with Error(\"aborted\")\n * when it is destroyed, and pg or outbound sockets reset with ECONNRESET.\n */\nexport function isClientDisconnect(err: unknown): boolean {\n const e = err as { code?: unknown; message?: unknown } | null;\n const code = typeof e?.code === \"string\" ? e.code : \"\";\n return (\n code === \"ECONNRESET\" ||\n code === \"ECONNABORTED\" ||\n code === \"EPIPE\" ||\n code === \"ERR_STREAM_PREMATURE_CLOSE\" ||\n code.startsWith(\"HPE_\") ||\n e?.message === \"aborted\"\n );\n}\n\nconst logged = globalSingleton(\"logged\", () => new WeakSet<object>());\n\n// Marks an error as already written, so a later boundary (e.g. Next's onRequestError)\n// does not log it a second time.\nexport function markLogged(err: unknown): void {\n if (typeof err === \"object\" && err !== null) logged.add(err);\n}\n\nexport function isLogged(err: unknown): boolean {\n return typeof err === \"object\" && err !== null && logged.has(err);\n}\n","import { isErrorLike, serializeError } from \"./error\";\nimport type { Level } from \"./levels\";\nimport { REDACTED, toSnakeCase, type Redactor } from \"./redact\";\n\nexport { DEFAULT_REDACT_KEYS, toSnakeCase } from \"./redact\";\n\n/** Final per-field hook: return a replacement, or undefined to drop the field. */\nexport type RedactHook = (key: string, value: Primitive) => unknown;\n\nexport type Fields = Record<string, unknown>;\nexport type Primitive = string | number | boolean | null;\nexport type LogRecord = Record<string, Primitive>;\n\nexport interface NormalizeOptions {\n snakeCase: boolean;\n redactor: Redactor;\n hook?: RedactHook;\n}\n\n// Fields the redact hook never sees, so every line keeps its level, message and event.\nconst HOOK_EXEMPT = new Set([\"level\", \"message\", \"event\"]);\n\n// Keys owned by Vector (overwritten or deleted on ingest) or by the logger itself.\nexport const RESERVED_KEYS = new Set([\n \"project\", \"service\", \"vps\", \"version\", \"container_name\", \"container_id\", \"image\", \"stream\",\n \"_timestamp\", \"label\", \"host\", \"source_type\", \"msg\", \"lvl\", \"severity\", \"level\", \"message\",\n]);\n\nexport const MAX_LINE_BYTES = 16000;\nconst MAX_MESSAGE = 500;\nconst MAX_STACK = 4000;\nconst MAX_STRING = 1000;\nconst MAX_DEPTH = 3;\nconst TRUNCATED = \"…[truncated]\";\n\n// Fields kept when a line is too large.\nconst KEEP_ON_SHRINK = new Set([\n \"level\", \"message\", \"event\", \"request_id\", \"trace_id\", \"span_id\", \"job_name\", \"job_id\", \"job_attempt\",\n \"user_id\", \"tenant_id\", \"err_type\", \"err_message\", \"err_code\",\n]);\n\nexport function stripUrl(url: string): string {\n const noQuery = url.split(/[?#]/, 1)[0] ?? \"\";\n return noQuery.replace(/^([a-z][a-z0-9+.-]*:\\/\\/)[^/@\\s]*@/i, \"$1\");\n}\n\nexport function truncate(s: string, max: number): string {\n return s.length > max ? s.slice(0, max - TRUNCATED.length) + TRUNCATED : s;\n}\n\nfunction isPlainObject(v: unknown): v is Fields {\n if (typeof v !== \"object\" || v === null) return false;\n const proto = Object.getPrototypeOf(v);\n return proto === Object.prototype || proto === null;\n}\n\nfunction isUrlKey(key: string): boolean {\n return key === \"http_path\" || key === \"http_url\" || key.endsWith(\"_url\");\n}\n\nfunction flattenInto(out: LogRecord, prefix: string, obj: Fields, depth: number, opts: NormalizeOptions): void {\n for (const [rawKey, value] of Object.entries(obj)) {\n const key = opts.snakeCase ? toSnakeCase(rawKey) : rawKey;\n const full = prefix ? `${prefix}_${key}` : key;\n if (value === undefined || typeof value === \"function\" || typeof value === \"symbol\") continue;\n if (value !== null && (opts.redactor.isSensitive(rawKey) || opts.redactor.isSensitive(full))) {\n out[full] = REDACTED;\n continue;\n }\n if (value === null || typeof value === \"string\" || typeof value === \"boolean\") {\n out[full] = value;\n } else if (typeof value === \"number\") {\n out[full] = Number.isFinite(value) ? value : String(value);\n } else if (typeof value === \"bigint\") {\n out[full] = value.toString();\n } else if (value instanceof Date) {\n out[full] = Number.isNaN(value.getTime()) ? \"Invalid Date\" : value.toISOString();\n } else if (isErrorLike(value)) {\n out[full] = `${value.name}: ${value.message}`;\n } else if (isPlainObject(value) && depth < MAX_DEPTH - 1) {\n flattenInto(out, full, value, depth + 1, opts);\n } else {\n // Arrays, deep objects, class instances: stringified with sensitive keys redacted.\n out[full] = opts.redactor.json(value);\n }\n }\n}\n\n// Correlation ids are opaque tokens: value patterns such as phoneVN can match inside a hex\n// segment and break the join between services, so a well-formed id is never scrubbed.\nconst ID_VALUE_RE = /^[A-Za-z0-9._:-]{1,128}$/;\n\nfunction isIdKey(key: string): boolean {\n return key === \"request_id\" || key === \"trace_id\" || key === \"span_id\" || key.endsWith(\"_request_id\");\n}\n\nfunction finalize(key: string, value: Primitive, opts: NormalizeOptions): Primitive {\n if (typeof value !== \"string\") return value;\n if (isIdKey(key) && ID_VALUE_RE.test(value)) return value;\n const v = opts.redactor.scrub(isUrlKey(key) ? stripUrl(value) : value);\n return truncate(v, key === \"err_stack\" ? MAX_STACK : MAX_STRING);\n}\n\nexport function buildRecord(\n level: Level,\n message: unknown,\n sources: (Fields | undefined)[],\n opts: NormalizeOptions,\n): LogRecord {\n const merged: Fields = {};\n for (const source of sources) if (source) Object.assign(merged, source);\n\n let err: unknown;\n if (merged.err !== undefined && merged.err !== null) {\n err = merged.err;\n delete merged.err;\n } else if (isErrorLike(merged.error)) {\n err = merged.error;\n delete merged.error;\n }\n\n const flat: LogRecord = {};\n flattenInto(flat, \"\", merged, 0, opts);\n if (err !== undefined) Object.assign(flat, serializeError(err));\n\n const text = typeof message === \"string\" ? message : opts.redactor.json(message);\n const out: LogRecord = { level, message: truncate(opts.redactor.scrub(text), MAX_MESSAGE) };\n for (const [k, v] of Object.entries(flat)) {\n const key = RESERVED_KEYS.has(k) ? `app_${k}` : k;\n let value = finalize(key, v, opts);\n if (opts.hook && !HOOK_EXEMPT.has(key)) {\n const replaced = opts.hook(key, value);\n if (replaced === undefined) continue;\n value = typeof replaced === \"object\" && replaced !== null ? opts.redactor.json(replaced) : (replaced as Primitive);\n }\n out[key] = value;\n }\n return out;\n}\n\nfunction byteLength(s: string): number {\n // UTF-8 uses at most 3 bytes per UTF-16 code unit: skip encoding short lines.\n if (s.length * 3 <= MAX_LINE_BYTES) return s.length;\n return new TextEncoder().encode(s).length;\n}\n\nexport function serializeRecord(record: LogRecord): string {\n const line = JSON.stringify(record);\n if (byteLength(line) <= MAX_LINE_BYTES) return line;\n const small: LogRecord = {};\n for (const [k, v] of Object.entries(record)) {\n if (KEEP_ON_SHRINK.has(k) || k.startsWith(\"http_\")) small[k] = v;\n }\n small.log_truncated = true;\n return JSON.stringify(small);\n}\n","// No imports: this module is shared with the edge entry (next-edge).\nexport const REQUEST_ID_RE = /^[A-Za-z0-9._-]{1,64}$/;\nconst TRACEPARENT_RE = /^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/;\n\nexport function newRequestId(): string {\n return globalThis.crypto.randomUUID();\n}\n\nfunction first(header?: string | string[] | null): string | undefined {\n return Array.isArray(header) ? header[0] : (header ?? undefined);\n}\n\nexport function resolveRequestId(header?: string | string[] | null): string {\n const value = first(header);\n return value && REQUEST_ID_RE.test(value) ? value : newRequestId();\n}\n\nexport function parseTraceparent(header?: string | string[] | null): { trace_id: string; span_id: string } | undefined {\n const value = first(header)?.trim().toLowerCase();\n const m = value ? TRACEPARENT_RE.exec(value) : null;\n if (!m) return undefined;\n const [, version, traceId, spanId] = m as unknown as [string, string, string, string];\n if (version === \"ff\" || /^0+$/.test(traceId) || /^0+$/.test(spanId)) return undefined;\n return { trace_id: traceId, span_id: spanId };\n}\n","import { getContext } from \"./context\";\nimport { markLogged, serializeError } from \"./error\";\nimport type { Logger } from \"./logger\";\nimport { stripUrl, type Fields } from \"./normalize\";\nimport { parseTraceparent, resolveRequestId } from \"./request-id\";\n\nexport { newRequestId, parseTraceparent, REQUEST_ID_RE, resolveRequestId } from \"./request-id\";\n\nexport type HeaderSource = Headers | Record<string, string | string[] | undefined>;\n\nfunction header(headers: HeaderSource, name: string): string | string[] | undefined {\n if (typeof (headers as Headers).get === \"function\") return (headers as Headers).get(name) ?? undefined;\n return (headers as Record<string, string | string[] | undefined>)[name];\n}\n\nexport function requestContextFields(headers: HeaderSource): { request_id: string; trace_id?: string; span_id?: string } {\n const out: { request_id: string; trace_id?: string; span_id?: string } = {\n request_id: resolveRequestId(header(headers, \"x-request-id\")),\n };\n const tp = parseTraceparent(header(headers, \"traceparent\"));\n if (tp) Object.assign(out, tp);\n return out;\n}\n\n// Headers to forward to services we own, so their logs share request_id / trace_id.\nexport function propagationHeaders(): Record<string, string> {\n const ctx = getContext();\n const out: Record<string, string> = {};\n if (typeof ctx.request_id === \"string\") out[\"x-request-id\"] = ctx.request_id;\n if (typeof ctx.trace_id === \"string\" && typeof ctx.span_id === \"string\") {\n out.traceparent = `00-${ctx.trace_id}-${ctx.span_id}-01`;\n }\n return out;\n}\n\nexport const DEFAULT_SKIP_PATHS: (string | RegExp)[] = [\n // Also under a prefix such as /api/v1/health.\n /(^|\\/)(health|healthz|ready|readyz|livez)\\/?$/,\n \"/favicon.ico\",\n /^\\/_next\\/static\\//,\n];\n\nexport interface HttpLogOptions {\n skipPaths?: (string | RegExp)[];\n}\n\nexport interface HttpRequestInfo {\n method: string;\n route?: string;\n path: string;\n status: number;\n duration_ms?: number;\n err?: unknown;\n fields?: Fields;\n}\n\nexport function shouldSkip(method: string, path: string, skipPaths: (string | RegExp)[] = DEFAULT_SKIP_PATHS): boolean {\n if (method.toUpperCase() === \"OPTIONS\") return true;\n const p = stripUrl(path);\n return skipPaths.some((s) => (typeof s === \"string\" ? p === s : s.test(p)));\n}\n\n// Writes the one `http.request` summary line for an inbound request. Skipped paths are still\n// logged when they fail with a 5xx, so a failing health check stays visible.\nexport function logHttpRequest(log: Logger, info: HttpRequestInfo, opts: HttpLogOptions = {}): void {\n if (info.status < 500 && shouldSkip(info.method, info.path, opts.skipPaths)) return;\n // The level follows the status only. An error's shape cannot tell a client hang-up apart:\n // knex's pool (tarn) rejects in-flight queries with Error(\"aborted\") when it is destroyed on\n // shutdown, and a pg or outbound socket reset is ECONNRESET too. Both are server-side failures.\n const level = info.status >= 500 ? \"error\" : info.status >= 400 ? \"warn\" : \"info\";\n const path = stripUrl(info.path);\n const errFields: Fields = {};\n if (info.err !== undefined && info.err !== null) {\n Object.assign(errFields, serializeError(info.err));\n if (info.status < 500) delete errFields.err_stack;\n markLogged(info.err);\n }\n // Route templates keep the message bounded; the raw path would make one message per URL.\n const message = info.route ? `${info.method} ${info.route} ${info.status}` : `${info.method} ${info.status}`;\n log[level](message, {\n ...info.fields,\n event: \"http.request\",\n http_method: info.method,\n http_route: info.route,\n http_path: path,\n http_status: info.status,\n duration_ms: info.duration_ms === undefined ? undefined : Math.round(info.duration_ms),\n ...errFields,\n });\n}\n","import { globalSingleton } from \"./global\";\nimport type { Logger } from \"./logger\";\nimport type { Fields } from \"./normalize\";\n\nexport function logStartup(log: Logger, fields: Fields = {}): void {\n log.info(\"app started\", {\n event: \"app.started\",\n runtime_version: `node ${process.versions.node}`,\n log_level: log.level,\n ...fields,\n });\n}\n\n/** Call at the start of your own shutdown handler (e.g. on SIGTERM). The library never handles signals. */\nexport function logShutdown(log: Logger, fields: Fields = {}): void {\n log.info(\"app stopping\", { event: \"app.stopping\", ...fields });\n}\n\nexport interface ProcessHandlerOptions {\n /** Exit with code 1 after an uncaught error. Next.js keeps serving, so its adapter passes false. */\n exitOnCrash?: boolean;\n /** Time other crash handlers (Sentry, APM) get to flush before exit. Default 1000 ms. */\n exitDelayMs?: number;\n exit?: (code: number) => void;\n}\n\nexport function crashHandlers(log: Logger, opts: ProcessHandlerOptions = {}) {\n const exitOnCrash = opts.exitOnCrash ?? true;\n const exitDelayMs = opts.exitDelayMs ?? 1000;\n const exit = opts.exit ?? ((code: number) => process.exit(code));\n let exiting = false;\n const crash = (source: string, err: unknown) => {\n if (!exitOnCrash) {\n log.error(\"unhandled error\", { event: \"app.unhandled_error\", crash_source: source, err });\n return;\n }\n log.fatal(\"app crashed\", { event: \"app.crashed\", crash_source: source, err });\n if (exiting) return;\n exiting = true;\n if (typeof process !== \"undefined\") process.exitCode = 1;\n // Deferred so listeners registered after ours still run; unref so a process with nothing\n // left to do exits on its own (with exitCode 1) without waiting.\n const timer = setTimeout(() => exit(1), exitDelayMs);\n (timer as { unref?: () => void }).unref?.();\n };\n return {\n onUncaught: (err: unknown) => crash(\"uncaughtException\", err),\n onRejection: (reason: unknown) => crash(\"unhandledRejection\", reason),\n };\n}\n\nconst state = globalSingleton(\"process\", () => ({ installed: false }));\n\n/** Logs uncaught exceptions and unhandled rejections. Does not touch SIGTERM/SIGINT. */\nexport function installProcessHandlers(log: Logger, opts: ProcessHandlerOptions = {}): void {\n if (state.installed || typeof process === \"undefined\" || typeof process.on !== \"function\") return;\n state.installed = true;\n const h = crashHandlers(log, opts);\n process.on(\"uncaughtException\", h.onUncaught);\n process.on(\"unhandledRejection\", h.onRejection);\n}\n\nconst warningState = globalSingleton(\"warnings\", () => ({ installed: false }));\n\n/**\n * Node keeps 10 frames by default; ORM/framework frames (knex, Strapi, Prisma) often use all of\n * them, hiding the app code that triggered a warning or error. Only ever raises the limit.\n */\nexport function raiseStackTraceLimit(limit: number): void {\n if (Error.stackTraceLimit < limit) Error.stackTraceLimit = limit;\n}\n\nexport interface ProcessWarningOptions {\n stackTraceLimit?: number;\n /**\n * Remove Node's own stderr printer, so a warning is one JSON line instead of that line plus\n * \"(node:1) Warning: ...\" and \"(Use `node --trace-deprecation ...`...)\". Default true.\n */\n replaceDefault?: boolean;\n /**\n * A repeated warning is written at most once per window (default 1 hour). The next line carries\n * `suppressed_count`, the repeats dropped since the previous line, so the frequency stays visible.\n */\n repeatWindowMs?: number;\n now?: () => number;\n}\n\n// Distinct warnings tracked; past this a new kind is logged every time instead of throttled.\nconst MAX_TRACKED_WARNINGS = 200;\n\n/**\n * Logs Node process warnings (deprecations, MaxListeners...) as `process.warning` lines whose\n * err_stack points at the code that triggered them. Repeats are throttled (see repeatWindowMs).\n * Also raises Error.stackTraceLimit (default 30) so the stack reaches past framework frames.\n */\nexport function logProcessWarnings(log: Logger, opts: ProcessWarningOptions = {}): void {\n if (warningState.installed || typeof process === \"undefined\" || typeof process.on !== \"function\") return;\n warningState.installed = true;\n raiseStackTraceLimit(opts.stackTraceLimit ?? 30);\n if (opts.replaceDefault ?? true) {\n for (const l of process.listeners(\"warning\")) if (l.name === \"onWarning\") process.off(\"warning\", l);\n }\n const windowMs = opts.repeatWindowMs ?? 60 * 60 * 1000;\n const now = opts.now ?? Date.now;\n const tracked = new Map<string, { loggedAt: number; suppressed: number }>();\n process.on(\"warning\", (warning: Error) => {\n const key = `${warning?.name}:${(warning as { code?: unknown })?.code ?? \"\"}:${warning?.message}`;\n const t = now();\n const entry = tracked.get(key);\n if (entry && t - entry.loggedAt < windowMs) {\n entry.suppressed += 1;\n return;\n }\n if (entry) tracked.set(key, { loggedAt: t, suppressed: 0 });\n else if (tracked.size < MAX_TRACKED_WARNINGS) tracked.set(key, { loggedAt: t, suppressed: 0 });\n log.warn(\"process warning\", {\n event: \"process.warning\",\n suppressed_count: entry ? entry.suppressed : undefined,\n err: warning,\n });\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,8BAAkC;;;ACE3B,SAAS,gBAAmB,MAAc,MAAkB;AACjE,QAAM,MAAM,uBAAO,IAAI,iBAAiB,IAAI,EAAE;AAC9C,QAAM,IAAI;AACV,MAAI,QAAQ,EAAE,GAAG;AACjB,MAAI,UAAU,QAAW;AACvB,YAAQ,KAAK;AACb,MAAE,GAAG,IAAI;AAAA,EACX;AACA,SAAO;AACT;;;ADCA,IAAM,MAAM,gBAAgB,OAAO,MAAM,IAAI,0CAAgC,CAAC;AAIvE,SAAS,aAAgB,QAAgB,IAAmC;AACjF,QAAM,SAAS,IAAI,SAAS;AAC5B,QAAM,QAAsB,EAAE,QAAQ,EAAE,GAAG,QAAQ,QAAQ,GAAG,OAAO,GAAG,OAAO;AAC/E,SAAO,IAAI,IAAI,OAAO,MAAM,GAAG,KAAK,CAAC;AACvC;;;AEjBO,IAAM,sBAAsB;AAAA,EACjC;AAAA,EAAY;AAAA,EAAU;AAAA,EAAO;AAAA,EAAc;AAAA,EAAU;AAAA,EACrD;AAAA,EAAS;AAAA,EAAgB;AAAA,EAAiB;AAAA,EAAY;AAAA,EACtD;AAAA,EAAW;AAAA,EAAU;AAAA,EAAc;AAAA,EAAc;AAAA,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