Handler for processing log messages

Implementations can handle logs by writing to different outputs such as console, memory, IndexedDB, or external services.

Example

class ConsoleHandler implements LogHandler {
minLevel = LogLevel.Info;

handle(entry: LogEntry): void {
const prefix = `[${entry.level.toUpperCase()}] [${entry.scope}]`;
console.log(`${prefix} ${entry.message}`, entry.data);
}
}

// Change level at runtime
consoleHandler.minLevel = LogLevel.Debug;

Hierarchy

Properties

Methods

Properties

minLevel?: LogLevel

Minimum log level this handler should receive

If specified, the factory will only pass log entries with a level equal to or higher than this value. If not specified, all log entries are passed to the handler.

Level priority (lowest to highest): Debug → Info → Warn → Error

This can be changed at runtime to dynamically adjust filtering.

Methods

  • Handles a log entry

    Implementations should handle their own errors internally to ensure reliability. However, any uncaught errors thrown by this method will be caught by the factory to prevent one handler from breaking others. Errors will be logged to the console but will not stop other handlers from receiving the log entry.

    Parameters

    • entry: LogEntry

      The log entry to handle

    Returns void | Promise<void>