type-compiler
Version:
A TypeScript compiler plugin for enhanced runtime type checking and analysis with Zod validation
126 lines (125 loc) • 3.15 kB
TypeScript
import ts from 'typescript';
import { TypeCompilerOptions } from './types';
/**
* Log levels for the type compiler
*/
export declare enum LogLevel {
ERROR = 0,// Only errors
WARN = 1,// Errors and warnings
INFO = 2,// Basic information about the compilation process
DEBUG = 3,// Detailed information for debugging
TRACE = 4
}
/**
* Logger configuration
*/
export interface LoggerConfig {
/**
* The minimum log level to display
*/
level: LogLevel;
/**
* Whether to use colors in the console output
*/
useColors: boolean;
/**
* Whether to include timestamps in log messages
*/
includeTimestamps: boolean;
/**
* Whether to log to a file in addition to the console
*/
logToFile: boolean;
/**
* The path to the log file (if logToFile is true)
*/
logFilePath?: string;
/**
* Custom log filter function. Return true to include the message, false to exclude it.
*/
filter?: (level: LogLevel, message: string, context?: Record<string, any>) => boolean;
}
/**
* Logger class for the type compiler
*/
export declare class Logger {
private config;
private buffer;
private startTime;
private compilationMetrics;
constructor(config?: Partial<LoggerConfig>);
/**
* Reconfigure the logger
*/
configure(config: Partial<LoggerConfig>): void;
/**
* Configure the logger from TypeCompilerOptions
*/
configureFromOptions(options: TypeCompilerOptions): void;
/**
* Map TypeCompilerOptions to LogLevel
*/
private getLogLevelFromOptions;
/**
* Log a message at a specific level
*/
private log;
/**
* Log an error message
*/
error(message: string, context?: Record<string, any>): void;
/**
* Log a warning message
*/
warn(message: string, context?: Record<string, any>): void;
/**
* Log an info message
*/
info(message: string, context?: Record<string, any>): void;
/**
* Log a debug message
*/
debug(message: string, context?: Record<string, any>): void;
/**
* Log a trace message
*/
trace(message: string, context?: Record<string, any>): void;
/**
* Handle TypeScript diagnostics
*/
logDiagnostics(diagnostics: readonly ts.Diagnostic[]): void;
/**
* Format diagnostic location information
*/
private formatDiagnosticLocation;
/**
* Update compilation metrics
*/
updateMetrics(metrics: Partial<Record<string, number>>): void;
/**
* Increment a specific metric
*/
incrementMetric(metric: string, amount?: number): void;
/**
* Log compilation summary
*/
logCompilationSummary(): void;
/**
* Start timing an operation
*/
startTimer(label: string): () => void;
/**
* Get the log buffer
*/
getBuffer(): string[];
/**
* Clear the log buffer
*/
clearBuffer(): void;
/**
* Reset compilation metrics
*/
resetMetrics(): void;
}
export declare const logger: Logger;
export declare function getLogger(): Logger;