import * as _logtape_logtape from '@logtape/logtape'; export { withContext } from '@logtape/logtape'; /** Options for {@link configureGcpLogging}. */ interface GcpLoggingConfig { /** * GCP project ID. * * Auto-detected in this order: * 1. This explicit value * 2. `GOOGLE_CLOUD_PROJECT` / `GCLOUD_PROJECT` / `GCP_PROJECT` env vars */ projectId?: string; /** `"development"` uses console transport; anything else uses GCP Cloud Logging. Falls back to `NODE_ENV`. */ environment?: string; /** Winston / LogTape log level. Defaults to `"debug"` in dev, `"info"` otherwise. */ logLevel?: string; /** Service name reported to Cloud Logging (appears in `serviceContext`). */ serviceName?: string; /** * Monkey-patch global `console` methods so that **all** `console.log` / * `console.error` / … calls — including from third-party dependencies — * are automatically correlated with the active GCP trace. * * @default true */ patchConsole?: boolean; /** * Enable ANSI-colored log output in development mode. * * When `true` (the default in development), log levels are color-coded * (debug = blue, info = green, warning = yellow, error = red) and * timestamps / categories are dimmed for readability. * * Set to `false` to get plain text output, e.g. when piping to a file * or running in CI where ANSI codes are unwanted. * * Has no effect in production — production always outputs structured JSON. * * @default true (in development) */ colorize?: boolean; } /** * Pre-configured root logger instance. * * Import and use directly — trace correlation is automatic when * running inside `loggerMiddleware()` or `wrapCloudRunFunction()`. * * ```typescript * import { logger } from 'nodejs-gcp-log-correlation'; * logger.info('Hello'); * ``` */ declare const logger: _logtape_logtape.Logger; /** * Configure LogTape with a GCP-aware Winston sink and implicit context storage. * * In most cases you **don't need to call this** — `loggerMiddleware()` and * `wrapCloudRunFunction()` auto-initialise with sensible defaults (project ID * auto-detected from env vars, console patching enabled). * * Call this explicitly **only** if you need custom options (e.g. a specific * `logLevel` or `serviceName`). If you do, call it **once** at application * startup, **before** the middleware or any logging runs. */ declare function configureGcpLogging(options?: GcpLoggingConfig): Promise; /** * Express middleware that extracts the GCP trace header and scopes it as * LogTape implicit context for the lifetime of the request. * * Automatically initialises the library on first use if `configureGcpLogging()` * was not called explicitly. * * Every `logger.*` or `console.*` call — in your code **or** in third-party * dependencies — will automatically include the trace fields while inside this * context. * * @example * ```typescript * import express from 'express'; * import { loggerMiddleware, logger } from 'nodejs-gcp-log-correlation'; * * const app = express(); * app.use(loggerMiddleware()); * * app.get('/', (req, res) => { * logger.info('Request processed'); * res.json({ status: 'ok' }); * }); * * app.listen(8080); * ``` */ declare function loggerMiddleware(): (req: { header(name: string): string | undefined; }, res: unknown, next: (err?: unknown) => void) => void; /** * Wrap a Cloud Run function handler so that the GCP trace context is * automatically propagated through the entire function execution. * * Automatically initialises the library on first use if `configureGcpLogging()` * was not called explicitly. * * @example * ```typescript * import { wrapCloudRunFunction, logger } from 'nodejs-gcp-log-correlation'; * * export const handler = wrapCloudRunFunction((req, res) => { * logger.info('Function executed'); * res.send('Done!'); * }); * ``` */ declare function wrapCloudRunFunction any>(fn: T): T; /** * Hono middleware that extracts the GCP trace header and scopes it as * LogTape implicit context for the lifetime of the request. * * Automatically initialises the library on first use if `configureGcpLogging()` * was not called explicitly. * * Every `logger.*` or `console.*` call — in your code **or** in third-party * dependencies — will automatically include the trace fields while inside this * context. * * @example * ```typescript * import { Hono } from 'hono'; * import { honoLoggerMiddleware, logger } from 'nodejs-gcp-log-correlation'; * * const app = new Hono(); * app.use(honoLoggerMiddleware()); * * app.get('/', (c) => { * logger.info('Request processed'); * return c.json({ status: 'ok' }); * }); * ``` */ declare function honoLoggerMiddleware(): (c: { req: { header(name: string): string | undefined; }; }, next: () => Promise) => Promise; /** GCP Cloud Logging trace key — used as the context property name */ declare const TRACE_KEY = "logging.googleapis.com/trace"; /** * Read the current GCP trace context from LogTape's implicit context. * Returns an empty object when called outside a traced context. */ declare function getTraceContext(): { trace?: string; }; export { type GcpLoggingConfig, TRACE_KEY, configureGcpLogging, getTraceContext, honoLoggerMiddleware, logger, loggerMiddleware, wrapCloudRunFunction };