vibelogger
Version:
AI-Native Logging for LLM Agent Development - TypeScript/Node.js Implementation
148 lines • 4.62 kB
TypeScript
/**
* VibeCoding Logger - TypeScript Implementation
*
* AI-Native Logging for LLM Agent Development
*
* CONCEPT:
* This logger is designed specifically for VibeCoding (AI-driven development) where
* LLMs need rich, structured context to understand and debug code effectively.
* Unlike traditional human-readable logs, this creates "AI briefing packages" with
* comprehensive context, correlation tracking, and embedded human annotations.
*
* KEY FEATURES:
* - Structured JSON format optimized for LLM consumption
* - Rich context including function arguments, stack traces, environment info
* - Correlation IDs to track request flows across operations
* - Human annotation fields (humanNote, aiTodo) for AI instructions
* - Automatic file saving with timestamp-based naming
* - Thread-safe operations for concurrent environments
*
* BASIC USAGE:
* ```typescript
* import { createFileLogger } from 'vibe-logger';
*
* // Create logger with auto-save to timestamped file
* const logger = createFileLogger('my-project');
*
* // Log with rich context
* logger.info('fetchUserProfile', 'Starting user profile fetch', {
* context: { userId: '123', source: 'api_endpoint' },
* humanNote: 'AI-TODO: Check if user exists before fetching profile'
* });
*
* // Log exceptions with full context
* try {
* const result = riskyOperation();
* } catch (error) {
* logger.logException('fetchUserProfile', error, {
* context: { userId: '123' },
* aiTodo: 'Suggest proper error handling for this case'
* });
* }
*
* // Get logs formatted for AI analysis
* const aiContext = logger.getLogsForAI();
* ```
*/
import { LogEntry, LogLevel, LogOptions, VibeLoggerConfig } from './types.js';
/**
* Core VibeCoding Logger implementation
*/
export declare class VibeLogger {
private config;
private correlationId;
private environment;
private logs;
private memoryMutex;
constructor(configOptions?: VibeLoggerConfig);
/**
* Get caller information (file, line, function)
* TypeScript equivalent of Python's inspect functionality
*/
private getCallerInfo;
/**
* Extract error information from various error types
*/
private extractErrorInfo;
/**
* Create a log entry with all context information
*/
private createLogEntry;
/**
* Add log entry to memory (with thread safety)
*/
private addToMemory;
/**
* Save log entry to file (async, non-blocking)
*/
private saveToFile;
/**
* Core logging method
*/
log(level: LogLevel, operation: string, message: string, options?: LogOptions): Promise<LogEntry>;
/**
* Log debug message
*/
debug(operation: string, message: string, options?: LogOptions): Promise<LogEntry>;
/**
* Log info message
*/
info(operation: string, message: string, options?: LogOptions): Promise<LogEntry>;
/**
* Log warning message
*/
warning(operation: string, message: string, options?: LogOptions): Promise<LogEntry>;
/**
* Log error message
*/
error(operation: string, message: string, options?: LogOptions): Promise<LogEntry>;
/**
* Log critical message
*/
critical(operation: string, message: string, options?: LogOptions): Promise<LogEntry>;
/**
* Log exception with full context
*/
logException(operation: string, error: unknown, options?: Omit<LogOptions, 'includeStack'>): Promise<LogEntry>;
/**
* Get all logs as JSON string formatted for AI consumption
*/
getLogsForAI(operationFilter?: string): Promise<string>;
/**
* Get logs as array of objects
*/
getLogs(operationFilter?: string): Promise<LogEntry[]>;
/**
* Clear all logs from memory
*/
clearLogs(): Promise<void>;
/**
* Save all current logs to a file
*/
saveAllLogs(filePath?: string): Promise<void>;
/**
* Load logs from a file
*/
loadLogsFromFile(filePath: string): Promise<void>;
/**
* Get current configuration
*/
getConfig(): Required<VibeLoggerConfig>;
/**
* Get correlation ID
*/
getCorrelationId(): string;
}
/**
* Create a logger with custom configuration
*/
export declare function createLogger(config?: VibeLoggerConfig): VibeLogger;
/**
* Create a file logger for a specific project
*/
export declare function createFileLogger(projectName: string): VibeLogger;
/**
* Create a logger configured from environment variables
*/
export declare function createEnvLogger(): VibeLogger;
//# sourceMappingURL=logger.d.ts.map