/** * Log level constants for controlling diagnostics output. * Lower numeric values indicate higher priority (more restrictive filtering). * * @example * ```ts * import { LogLevel, setGlobalLoggerConfig } from "@alchemy/common"; * * setGlobalLoggerConfig({ level: LogLevel.DEBUG }); * ``` */ export declare const LogLevel: { /** Critical errors only */ readonly ERROR: 0; /** Warnings and errors */ readonly WARN: 1; /** Informational messages, warnings, and errors */ readonly INFO: 2; /** Debug messages and all above */ readonly DEBUG: 3; /** All messages including verbose details */ readonly VERBOSE: 4; }; export type LogLevel = (typeof LogLevel)[keyof typeof LogLevel]; /** * Configuration for redacting sensitive data in log output. */ export type RedactConfig = { /** Predicate function to test if a key should be redacted. Returns true if the key should be redacted. */ keys?: (key: string) => boolean; /** Function to replace redacted values. Defaults to returning "[REDACTED]". */ replacer?: (value: unknown, key?: string) => unknown; }; /** * Configuration for the diagnostics logging system. * All properties are optional and will use sensible defaults if not provided. */ export type DiagnosticsConfig = { /** Minimum log level to emit. Defaults to INFO in development, ERROR in production. */ level?: LogLevel; /** Configuration for redacting sensitive data in logs. */ redact?: RedactConfig; /** Array of sink functions to receive log entries. Defaults to console sink. */ sinks?: Array<(entry: LogEntry) => void>; /** Disable telemetry headers in requests. Defaults to false. */ disableTelemetryHeaders?: boolean; /** Array of exact namespace strings to allow. If undefined or empty, all namespaces are enabled. Example: ["aa-infra", "wallet-apis"] */ enabledNamespaces?: string[]; }; /** * Base context attached to all log entries from a logger instance. */ export type LoggerContextBase = { /** Package name (e.g., "@alchemy/aa-infra") */ package: string; /** Package version (e.g., "1.0.0") */ version: string; }; /** * A single log entry emitted by the diagnostics logger. */ export type LogEntry = { /** Timestamp in milliseconds since epoch (Date.now()) */ ts: number; /** Log level of this entry */ level: LogLevel; /** Optional namespace for filtering/grouping (e.g., "aa-infra", "wallet-apis") */ namespace: string | undefined; /** The log message */ message: string; /** Optional structured data attached to this log entry */ data?: Record; /** Package context (name and version) */ context: LoggerContextBase; }; /** * Gets the current global logger configuration. * If not yet initialized, returns default configuration based on environment. * * @returns {Required} The current global configuration with all fields populated * @example * ```ts * import { getGlobalLoggerConfig } from "@alchemy/common"; * * const config = getGlobalLoggerConfig(); * console.log("Current log level:", config.level); * ``` */ export declare function getGlobalLoggerConfig(): Required; /** * Sets the global logger configuration. * Partial configuration is supported - unspecified fields retain their current values. * * Configuration precedence (highest to lowest): * 1. Explicit setGlobalLoggerConfig calls * 2. ALCHEMY_LOG_LEVEL environment variable * 3. Defaults (INFO in dev, ERROR in prod) * * @param {DiagnosticsConfig} cfg - Partial configuration to apply * @example * ```ts * import { setGlobalLoggerConfig, LogLevel } from "@alchemy/common"; * * // Set log level only * setGlobalLoggerConfig({ level: LogLevel.DEBUG }); * * // Add custom sink * setGlobalLoggerConfig({ * sinks: [(entry) => console.log(JSON.stringify(entry))] * }); * * // Filter to specific namespaces * setGlobalLoggerConfig({ * enabledNamespaces: ["aa-infra", "wallet-apis"] * }); * ``` */ export declare function setGlobalLoggerConfig(cfg: DiagnosticsConfig): void; /** * Checks if a given log level is enabled based on current global configuration. * Used internally by logger to short-circuit disabled log statements. * * @param {LogLevel} level - The log level to check * @returns {boolean} True if the level is enabled (will be logged), false otherwise * @example * ```ts * import { isLevelEnabled, LogLevel } from "@alchemy/common"; * * if (isLevelEnabled(LogLevel.DEBUG)) { * // Perform expensive debug computation * } * ``` */ export declare function isLevelEnabled(level: LogLevel): boolean; /** * Checks if a given namespace is enabled based on current global configuration. * Used internally by logger to short-circuit logs from disabled namespaces. * * @param {string | undefined} namespace - The namespace to check * @returns {boolean} True if the namespace is enabled (will be logged), false otherwise * @example * ```ts * import { isNamespaceEnabled } from "@alchemy/common"; * * if (isNamespaceEnabled("aa-infra")) { * // This namespace is enabled * } * ``` */ export declare function isNamespaceEnabled(namespace: string | undefined): boolean; /** * Redacts sensitive keys in an object based on global redaction configuration. * Performs deep redaction by recursively processing nested objects and arrays. * Default redaction includes: authorization, apiKey, jwt, privateKey, secret, password. * * @param {Record | undefined} obj - The object to redact * @returns {Record | undefined} A new object with sensitive values redacted, or undefined if input was undefined * @example * ```ts * import { redactObject } from "@alchemy/common"; * * const data = { * apiKey: "secret123", * userId: "user-456", * nested: { secret: "hidden" } * }; * * const redacted = redactObject(data); * // { apiKey: "[REDACTED]", userId: "user-456", nested: { secret: "[REDACTED]" } } * ``` */ export declare function redactObject(obj: Record | undefined): Record | undefined; /** * Default console sink for diagnostics logging. * Routes log entries to appropriate console methods based on log level. * * Format: [HH:MM:SS.mmm] [package@version] message {data} * * @param {LogEntry} entry - The log entry to output * @example * ```ts * import { consoleSink, setGlobalLoggerConfig } from "@alchemy/common"; * * // Console sink is used by default, but can be explicitly configured * setGlobalLoggerConfig({ * sinks: [consoleSink] * }); * ``` */ export declare function consoleSink(entry: LogEntry): void; //# sourceMappingURL=config.d.ts.map