UNPKG

@catbee/utils

Version:

A modular, production-grade utility toolkit for Node.js and TypeScript, designed for robust, scalable applications (including Express-based services). All utilities are tree-shakable and can be imported independently.

39 lines 1.73 kB
import type { Logger } from "pino"; /** * Use an object compatible with either modern or legacy global scopes. */ export declare const _globalThis: typeof globalThis; /** * Retrieves the current logger instance: * - Returns a request-scoped logger from AsyncLocalStorage if available * - Falls back to the global (singleton) logger * - Initializes the global logger if not created yet * * @returns {Logger} The logger instance (request-bound or global root logger) */ export declare function getLogger(): Logger; /** * Creates a child logger with additional context. * * @param {Record<string, any>} bindings - Properties to attach to all log records * @param {Logger} [parentLogger] - Parent logger (defaults to current context logger or global) * @returns {Logger} Child logger with merged context */ export declare function createChildLogger(bindings: Record<string, any>, parentLogger?: Logger): Logger; /** * Creates a request-scoped logger with request ID and stores it in context * * @param {string} requestId - Unique request identifier * @param {object} [additionalContext] - Additional context to include in logs * @returns {Logger} Request-scoped logger instance */ export declare function createRequestLogger(requestId: string, additionalContext?: Record<string, any>): Logger; /** * Utility to safely log errors with proper stack trace extraction * * @param {Error|unknown} error - Error object to log * @param {string} [message] - Optional message to include * @param {Record<string, any>} [context] - Additional context properties */ export declare function logError(error: Error | unknown, message?: string, context?: Record<string, any>): void; //# sourceMappingURL=logger.utils.d.ts.map