UNPKG

ai-functions

Version:

Core AI primitives for building intelligent applications

118 lines 3.44 kB
/** * Configurable Logger for AI Functions * * Provides a pluggable logging interface that defaults to console but can be * configured to use any logging implementation. This allows library consumers * to integrate with their own logging infrastructure. * * @example * ```ts * import { configureLogger, getLogger } from 'ai-functions' * * // Use with default console logger * const logger = getLogger() * logger.warn('Something happened') * * // Configure a custom logger * configureLogger({ * debug: (msg, ...args) => myLogger.debug(msg, ...args), * info: (msg, ...args) => myLogger.info(msg, ...args), * warn: (msg, ...args) => myLogger.warn(msg, ...args), * error: (msg, ...args) => myLogger.error(msg, ...args), * }) * * // Disable logging entirely * configureLogger(null) * ``` * * @packageDocumentation */ /** * Logger interface that matches the standard console methods. * * All methods are optional to allow partial implementations. * Missing methods will be no-ops when called. */ export interface Logger { /** Debug level logging (verbose) */ debug?: (message: string, ...args: unknown[]) => void; /** Info level logging (general information) */ info?: (message: string, ...args: unknown[]) => void; /** Warning level logging (potential issues) */ warn?: (message: string, ...args: unknown[]) => void; /** Error level logging (errors and exceptions) */ error?: (message: string, ...args: unknown[]) => void; } /** * Logger configuration options */ export interface LoggerConfig { /** The logger implementation to use */ logger?: Logger | null; /** Minimum log level to output */ level?: 'debug' | 'info' | 'warn' | 'error' | 'silent'; } /** * Configure the global logger for ai-functions. * * @param config - Logger configuration or just a logger instance * * @example * ```ts * // Use a custom logger * configureLogger({ * logger: { * debug: (msg) => myLogger.debug(msg), * info: (msg) => myLogger.info(msg), * warn: (msg) => myLogger.warn(msg), * error: (msg) => myLogger.error(msg), * }, * level: 'info', * }) * * // Just set the log level * configureLogger({ level: 'debug' }) * * // Disable all logging * configureLogger({ logger: null }) * // or * configureLogger({ level: 'silent' }) * * // Reset to defaults * configureLogger({}) * ``` */ export declare function configureLogger(config: LoggerConfig | Logger | null): void; /** * Get the current logger instance. * * Returns a logger that respects the configured log level. * Methods for levels below the configured minimum will be no-ops. * * @returns Logger instance with level filtering applied * * @example * ```ts * const logger = getLogger() * logger.warn('This is a warning') * logger.error('This is an error', { details: 'foo' }) * ``` */ export declare function getLogger(): Required<Logger>; /** * Reset the logger to default configuration. * * Restores the console-based logger with 'warn' minimum level. */ export declare function resetLogger(): void; /** * Get the current log level */ export declare function getLogLevel(): string; /** * Set the minimum log level * * @param level - Minimum level to log ('debug' | 'info' | 'warn' | 'error' | 'silent') */ export declare function setLogLevel(level: 'debug' | 'info' | 'warn' | 'error' | 'silent'): void; //# sourceMappingURL=logger.d.ts.map