import { PluginLogger, LogContext, LogLevel } from '@quilltap/plugin-types'; export { LogContext, LogLevel, PluginLogger, createConsoleLogger, createNoopLogger } from '@quilltap/plugin-types'; /** * Plugin Logger Bridge * * Provides a logger factory for plugins that automatically bridges * to Quilltap's core logging when running inside the host application, * or falls back to console logging when running standalone. * * @module @quilltap/plugin-utils/logging/plugin-logger */ /** * Extended logger interface with child logger support */ interface PluginLoggerWithChild extends PluginLogger { /** * Create a child logger with additional context * @param additionalContext Context to merge with parent context * @returns A new logger with combined context */ child(additionalContext: LogContext): PluginLoggerWithChild; } /** * Type for the global Quilltap logger bridge * Stored on globalThis to work across different npm package copies */ declare global { var __quilltap_logger_factory: ((pluginName: string) => PluginLoggerWithChild) | undefined; } /** * Inject the core logger factory from Quilltap host * * This is called by Quilltap core when loading plugins to bridge * plugin logging into the host's logging system. Uses globalThis * to ensure it works even when plugins have their own copy of * plugin-utils in their node_modules. * * **Internal API - not for plugin use** * * @param factory A function that creates a child logger for a plugin */ declare function __injectCoreLoggerFactory(factory: (pluginName: string) => PluginLoggerWithChild): void; /** * Clear the injected core logger factory * * Useful for testing or when unloading the plugin system. * * **Internal API - not for plugin use** */ declare function __clearCoreLoggerFactory(): void; /** * Check if a core logger has been injected * * @returns True if running inside Quilltap with core logging available */ declare function hasCoreLogger(): boolean; /** * Create a plugin logger that bridges to Quilltap core logging * * When running inside Quilltap: * - Routes all logs to the core logger * - Tags logs with `{ plugin: pluginName, module: 'plugin' }` * - Logs appear in Quilltap's combined.log and console * * When running standalone: * - Falls back to console logging with `[pluginName]` prefix * - Respects the specified minimum log level * * @param pluginName - The plugin identifier (e.g., 'qtap-plugin-openai') * @param minLevel - Minimum log level when running standalone (default: 'debug') * @returns A logger instance * * @example * ```typescript * // In your plugin's provider.ts * import { createPluginLogger } from '@quilltap/plugin-utils'; * * const logger = createPluginLogger('qtap-plugin-my-provider'); * * export class MyProvider implements LLMProvider { * async sendMessage(params: LLMParams, apiKey: string): Promise { * logger.debug('Sending message', { model: params.model }); * * try { * const response = await this.client.chat({...}); * logger.info('Received response', { tokens: response.usage?.total_tokens }); * return response; * } catch (error) { * logger.error('Failed to send message', { model: params.model }, error as Error); * throw error; * } * } * } * ``` */ declare function createPluginLogger(pluginName: string, minLevel?: LogLevel): PluginLoggerWithChild; /** * Get the minimum log level from environment * * Checks for LOG_LEVEL or QUILLTAP_LOG_LEVEL environment variables. * Useful for configuring standalone plugin logging. * * @returns The configured log level, or 'info' as default */ declare function getLogLevelFromEnv(): LogLevel; export { type PluginLoggerWithChild, __clearCoreLoggerFactory, __injectCoreLoggerFactory, createPluginLogger, getLogLevelFromEnv, hasCoreLogger };