generaltranslation
Version:
A language toolkit for AI developers
118 lines (117 loc) • 4.15 kB
TypeScript
/**
* Comprehensive logging system for the General Translation library
* Provides structured logging with multiple levels and configurable output
*/
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'off';
export interface LogEntry {
level: LogLevel;
message: string;
timestamp: Date;
context?: string;
metadata?: Record<string, any>;
}
export interface LoggerConfig {
/** Minimum log level to output */
level: LogLevel;
/** Whether to include timestamps in log output */
includeTimestamp: boolean;
/** Whether to include context information */
includeContext: boolean;
/** Custom prefix for all log messages */
prefix?: string;
/** Whether to output to console (default: true) */
enableConsole: boolean;
/** Custom log handlers */
handlers?: LogHandler[];
}
export interface LogHandler {
handle(entry: LogEntry): void;
}
/**
* Console log handler that outputs formatted messages to console
*/
export declare class ConsoleLogHandler implements LogHandler {
private config;
constructor(config: LoggerConfig);
handle(entry: LogEntry): void;
}
/**
* Main Logger class providing structured logging capabilities
*/
export declare class Logger {
private config;
private handlers;
constructor(config?: Partial<LoggerConfig>);
/**
* Add a custom log handler
*/
addHandler(handler: LogHandler): void;
/**
* Remove a log handler
*/
removeHandler(handler: LogHandler): void;
/**
* Update logger configuration
*/
configure(config: Partial<LoggerConfig>): void;
/**
* Check if a log level should be output based on current configuration
*/
private shouldLog;
/**
* Internal logging method that creates log entries and passes them to handlers
*/
private log;
/**
* Log a debug message
* Used for detailed diagnostic information, typically of interest only when diagnosing problems
*/
debug(message: string, context?: string, metadata?: Record<string, any>): void;
/**
* Log an info message
* Used for general information about application operation
*/
info(message: string, context?: string, metadata?: Record<string, any>): void;
/**
* Log a warning message
* Used for potentially problematic situations that don't prevent operation
*/
warn(message: string, context?: string, metadata?: Record<string, any>): void;
/**
* Log an error message
* Used for error events that might still allow the application to continue
*/
error(message: string, context?: string, metadata?: Record<string, any>): void;
/**
* Create a child logger with a specific context
*/
child(context: string): ContextLogger;
/**
* Get current logger configuration
*/
getConfig(): LoggerConfig;
}
/**
* Context logger that automatically includes context information
*/
export declare class ContextLogger {
private logger;
private context;
constructor(logger: Logger, context: string);
debug(message: string, metadata?: Record<string, any>): void;
info(message: string, metadata?: Record<string, any>): void;
warn(message: string, metadata?: Record<string, any>): void;
error(message: string, metadata?: Record<string, any>): void;
child(childContext: string): ContextLogger;
}
export declare const defaultLogger: Logger;
export declare const debug: (message: string, context?: string, metadata?: Record<string, any>) => void;
export declare const info: (message: string, context?: string, metadata?: Record<string, any>) => void;
export declare const warn: (message: string, context?: string, metadata?: Record<string, any>) => void;
export declare const error: (message: string, context?: string, metadata?: Record<string, any>) => void;
export declare const fetchLogger: ContextLogger;
export declare const validationLogger: ContextLogger;
export declare const formattingLogger: ContextLogger;
export declare const localeLogger: ContextLogger;
export declare const gtInstanceLogger: ContextLogger;
export { Logger as GTLogger };