All files / src/logging index.ts

0% Statements 0/2
100% Branches 0/0
0% Functions 0/1
0% Lines 0/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51                                                                                                     
/**
 * Logging Module
 *
 * File-based logging infrastructure for per-process stdout/stderr capture.
 */
 
// Types
export type { LogLevel, LogEntry, LogConfig, LogStream } from './types.js';
 
// Classes
export { LogManager } from './manager.js';
export { ProcessLogWriter } from './writer.js';
 
// Convenience functions
import { LogManager } from './manager.js';
import { ProcessLogWriter } from './writer.js';
import type { EventBus } from '../events/index.js';
 
/**
 * Creates a new ProcessLogWriter with default configuration.
 *
 * Convenience function for common use case of creating a log writer
 * for a specific process using default log directory (~/.cw/logs).
 *
 * @param processId - Unique identifier for the process
 * @param eventBus - Optional EventBus for emitting log entry events
 * @returns A new ProcessLogWriter instance (call open() before writing)
 *
 * @example
 * ```typescript
 * const writer = createLogger('agent-001');
 * await writer.open();
 * await writer.writeStdout('Hello from agent\n');
 * await writer.close();
 * ```
 *
 * @example
 * ```typescript
 * // With event bus for real-time streaming
 * const bus = createEventBus();
 * const writer = createLogger('agent-001', bus);
 * bus.on('log:entry', (event) => console.log(event.payload));
 * await writer.open();
 * await writer.writeStdout('Hello from agent\n');
 * ```
 */
export function createLogger(processId: string, eventBus?: EventBus): ProcessLogWriter {
  const manager = new LogManager();
  return new ProcessLogWriter(processId, manager, eventBus);
}