Lime Web Components API Documentation - v7.4.0
    Preparing search index...

    Interface LoggerFactoryBeta

    Factory for creating Logger instances

    The factory is initialized with one or more log handlers. All loggers created from the factory will write to all configured handlers.

    import {
    LogEntry,
    LogHandler,
    LogLevel,
    PlatformServiceName,
    } from '@limetech/lime-web-components';

    const loggerFactory = platform.get(PlatformServiceName.Logger);

    // A component should prefer the exported `createLogger`, which adds the package
    // name to the scope. Go through the factory when you need the handler methods.
    const httpLogger = loggerFactory.createLogger('http');
    const authLogger = loggerFactory.createLogger('auth');

    class AuditHandler implements LogHandler {
    public minLevel: LogLevel = LogLevel.Warn;

    public handle(entry: LogEntry): void {
    void fetch('/api/audit', {
    method: 'POST',
    body: JSON.stringify(entry),
    });
    }
    }

    const auditHandler = new AuditHandler();

    loggerFactory.addHandler(auditHandler);

    const allLogs = await loggerFactory.getLogs();

    await loggerFactory.clearLogs();

    loggerFactory.removeHandler(auditHandler);
    interface LoggerFactory {
        addHandler(handler: LogHandler): void;
        clearLogs(): Promise<void>;
        createLogger(scope: string): Logger;
        getLogs(): Promise<LogEntry[]>;
        removeHandler(handler: LogHandler): boolean;
    }
    Index

    Methods

    • Beta

      Registers a new handler with the factory

      The handler will receive all future log entries from all loggers (both existing and newly created). Historical logs are not replayed.

      Parameters

      Returns void

    • Beta

      Clears logs from all handlers that support storage

      This method clears logs from all handlers that implement LogStore. Handlers that don't support clearing (like console) are ignored.

      Returns Promise<void>

    • Beta

      Creates a logger instance for a specific scope/category

      Parameters

      • scope: string

        The scope or category for the logger (e.g., 'http', 'auth', 'component-name')

      Returns Logger

      A logger instance that writes to all configured handlers

    • Beta

      Retrieves logs from all handlers that support storage

      This method aggregates logs from all handlers that implement LogStore. Handlers that don't support log retrieval (like console) are ignored.

      Returns Promise<LogEntry[]>

      Array of all log entries from all storage handlers

    • Beta

      Removes a handler from the factory

      Parameters

      Returns boolean

      true if the handler was removed, false if it was not found