import { a as EnvironmentContext, d as Log, g as RequestLogger, y as SamplingConfig } from "../types-B82IuY7M.mjs"; import { n as createError } from "../error-D4JQHcSq.mjs"; import { t as _log } from "../logger-Dwb7G3sg.mjs"; import { t as BaseMxllogOptions } from "../middleware-Cbh6eBkJ.mjs"; import { AsyncLocalStorage } from "node:async_hooks"; //#region src/next/types.d.ts interface NextMxllogOptions extends BaseMxllogOptions { /** * Service name for all logged events. * @default auto-detected from SERVICE_NAME env or 'app' */ service?: string; /** * Environment context overrides. */ env?: Partial; /** * Enable pretty printing. * @default true in development, false in production */ pretty?: boolean; /** * Enable or disable all logging globally. * @default true */ enabled?: boolean; /** * Sampling configuration for filtering logs. */ sampling?: SamplingConfig; /** * When pretty is disabled, emit JSON strings (default) or raw objects. * @default true */ stringify?: boolean; } interface MxllogMiddlewareConfig { /** * Route patterns to include in middleware processing. * Supports glob patterns like '/api/**'. */ include?: string[]; /** * Route patterns to exclude from middleware processing. * Supports glob patterns like '/_next/**'. */ exclude?: string[]; } //#endregion //#region src/next/storage.d.ts /** * Get the current request-scoped logger. * Must be called inside a `withMxllog()` wrapper. * * @throws {Error} if called outside of `withMxllog()` context * * @example * ```ts * export const POST = withMxllog(async (request) => { * const log = useLogger() * log.set({ user: { id: '123' } }) * return Response.json({ ok: true }) * }) * ``` */ declare function useLogger>(): RequestLogger; //#endregion //#region src/next/middleware.d.ts type NextRequest = { nextUrl: { pathname: string; }; headers: { get(name: string): string | null; }; }; type NextResponse = { headers: { set(name: string, value: string): void; }; }; /** * Create an mxllog middleware for Next.js. * Sets `x-request-id` and `x-mxllog-start` headers so `withMxllog()` can reuse them * for timing consistency across the middleware -> handler chain. * * @example * ```ts * // middleware.ts * import { mxllogMiddleware } from '@safaricom-mxl/log/next' * export const middleware = mxllogMiddleware() * export const config = { matcher: ['/api/:path*'] } * ``` */ declare function mxllogMiddleware(config?: MxllogMiddlewareConfig): (request: NextRequest) => Promise; //#endregion //#region src/next/index.d.ts /** * Create an mxllog instance configured for Next.js. * Returns all helpers needed for server-side logging. * * @example * ```ts * // lib/mxllog.ts * import { createMxllog } from '@safaricom-mxl/log/next' * import { createAxiomDrain } from '@safaricom-mxl/log/axiom' * import { createDrainPipeline } from '@safaricom-mxl/log/pipeline' * * const pipeline = createDrainPipeline({ batch: { size: 50 } }) * * export const { withMxllog, useLogger, log, createMxllogError } = createMxllog({ * service: 'my-app', * sampling: { * rates: { info: 10 }, * keep: [{ status: 400 }, { duration: 1000 }], * }, * drain: pipeline(createAxiomDrain({ * dataset: 'logs', * token: process.env.AXIOM_TOKEN!, * })), * enrich: (ctx) => { * ctx.event.deploymentId = process.env.VERCEL_DEPLOYMENT_ID * }, * }) * ``` */ declare function createMxllog(options?: NextMxllogOptions): { withMxllog: (handler: (...args: TArgs) => TReturn) => (...args: TArgs) => Promise>; useLogger: typeof useLogger; log: Log; createError: typeof createError; createMxllogError: typeof createError; }; //#endregion export { type MxllogMiddlewareConfig, type NextMxllogOptions, createError, createError as createMxllogError, createMxllog, _log as log, mxllogMiddleware, useLogger }; //# sourceMappingURL=index.d.mts.map