/** * ObjectQL - Logger Type Definitions * Copyright (c) 2026-present ObjectStack Inc. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * Defines the canonical Logger interface for the ObjectQL ecosystem. * All packages must use this interface instead of direct console.* calls. */ /** * Log severity levels (RFC 5424 Syslog) */ export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal'; /** * Log output format */ export type LogFormat = 'json' | 'pretty' | 'compact'; /** * Structured log entry for serialization */ export interface LogEntry { /** ISO 8601 timestamp */ readonly timestamp: string; /** Log severity level */ readonly level: LogLevel; /** Logger name / component identifier */ readonly name: string; /** Human-readable message */ readonly message: string; /** Structured metadata (key-value pairs) */ readonly data?: Record; /** Error object, if applicable */ readonly error?: { readonly name: string; readonly message: string; readonly stack?: string; }; } /** * Logger configuration */ export interface LoggerConfig { /** Logger name / component identifier */ readonly name: string; /** Minimum log level to emit */ readonly level?: LogLevel; /** Output format */ readonly format?: LogFormat; } /** * Canonical Logger interface for the ObjectQL ecosystem * * All packages must program against this interface. * Implementations are provided by the runtime layer (`@objectstack/core` * or a custom adapter), keeping foundation packages runtime-agnostic. * * @example * ```typescript * class MyPlugin { * private logger: Logger; * constructor(logger: Logger) { * this.logger = logger; * } * async process() { * this.logger.info('Processing started', { batch: 42 }); * } * } * ``` */ export interface Logger { /** Finest-grained informational events */ trace(message: string, data?: Record): void; /** Detailed debug information */ debug(message: string, data?: Record): void; /** Informational messages that highlight progress */ info(message: string, data?: Record): void; /** Potentially harmful situations */ warn(message: string, data?: Record): void; /** Error events that might still allow the application to continue */ error(message: string, error?: Error, data?: Record): void; /** Severe error events that will presumably lead to application abort */ fatal(message: string, error?: Error, data?: Record): void; } /** * Factory function signature for creating Logger instances. * Typically provided by the runtime layer. */ export type LoggerFactory = (config: LoggerConfig) => Logger; /** * Console-based Logger implementation * * A zero-dependency reference implementation suitable for: * - Unit tests (without mocking an external logger library) * - Development environments * - Packages that cannot depend on `@objectstack/core` * * For production use, prefer the structured logger from `@objectstack/core`. */ export declare class ConsoleLogger implements Logger { private readonly name; private readonly level; private static readonly LEVELS; constructor(config: LoggerConfig); private shouldLog; private format; trace(message: string, data?: Record): void; debug(message: string, data?: Record): void; info(message: string, data?: Record): void; warn(message: string, data?: Record): void; error(message: string, error?: Error, data?: Record): void; fatal(message: string, error?: Error, data?: Record): void; } /** * No-op Logger implementation * * Useful for suppressing all log output (e.g., in benchmarks or silent tests). */ export declare class NullLogger implements Logger { trace(): void; debug(): void; info(): void; warn(): void; error(): void; fatal(): void; }