magiclogger - v0.1.0
    Preparing search index...

    Class SyncConsoleTransport

    Fully synchronous console transport.

    This transport writes directly to console with no async operations, promises, or callbacks. It provides immediate feedback which is essential for development and debugging.

    SyncConsoleTransport

    const consoleTransport = new SyncConsoleTransport({
    useColors: true,
    showTimestamp: true,
    showLevel: true
    });

    // Direct, synchronous output
    consoleTransport.log(entry); // Appears immediately

    Hierarchy

    • Transport
      • SyncConsoleTransport
    Index

    Constructors

    Properties

    closing: boolean = false

    Flag to track if transport is currently closing.

    enabled: boolean

    Whether this transport is currently active and processing logs. Can be toggled at runtime to enable/disable specific transports.

    excludeTags?: string[]

    Tags that exclude logs from being processed.

    filter?: (entry: LogEntry) => boolean

    Custom filter function for advanced filtering.

    format: "json" | "plain" | "custom"

    Output format for this transport.

    formatter?: (entry: LogEntry) => string | Buffer<ArrayBufferLike>

    Custom formatter function.

    initialized: boolean = false

    Flag to track if transport has been initialized.

    level: string

    Minimum log level for this transport.

    levels?: string[]

    Specific levels this transport handles (if specified).

    name: string

    Unique identifier for this transport instance. Used for managing multiple transports and debugging.

    Transport configuration options.

    silent: boolean

    Whether to suppress errors from this transport.

    stats: TransportStats = ...

    Statistics tracking for this transport.

    tags?: string[]

    Tags that must be present for logs to be processed.

    timeout: number

    Operation timeout in milliseconds.

    Methods

    • Close the transport and clean up resources.

      Returns Promise<void>

      Resolves when the transport is fully closed

      If cleanup fails

    • Protected

      Logs an entry synchronously to the console.

      This is the key method that demonstrates the correct architecture: completely synchronous with no promises or async operations.

      Parameters

      Returns Promise<void>

      Resolves immediately since this is synchronous.

    • Protected

      Optional method for transport-specific batch logging. Subclasses can implement this for efficient batch processing.

      Parameters

      • entries: LogEntry[]

        Array of log entries to process

      Returns Promise<void>

      Resolves when all logs have been processed

    • Synchronously calls each of the listeners registered for the event namedeventName, in the order they were registered, passing the supplied arguments to each.

      Returns true if the event had listeners, false otherwise.

      import EventEmitter from 'node:events';
      const myEmitter = new EventEmitter();

      // First listener
      myEmitter.on('event', function firstListener() {
      console.log('Helloooo! first listener');
      });
      // Second listener
      myEmitter.on('event', function secondListener(arg1, arg2) {
      console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
      });
      // Third listener
      myEmitter.on('event', function thirdListener(...args) {
      const parameters = args.join(', ');
      console.log(`event with parameters ${parameters} in third listener`);
      });

      console.log(myEmitter.listeners('event'));

      myEmitter.emit('event', 1, 2, 3, 4, 5);

      // Prints:
      // [
      // [Function: firstListener],
      // [Function: secondListener],
      // [Function: thirdListener]
      // ]
      // Helloooo! first listener
      // event with parameters 1, 2 in second listener
      // event with parameters 1, 2, 3, 4, 5 in third listener

      Parameters

      Returns boolean

      v0.1.26

    • Flush any buffered logs immediately.

      Returns Promise<void>

      Resolves when flush is complete

    • Protected

      Format a log entry according to the configured format.

      Parameters

      Returns string | Buffer<ArrayBufferLike>

      Formatted log entry

    • Protected

      Format a log entry as plain text.

      Parameters

      Returns string

      Plain text formatted log entry

    • Protected

      Generate a unique ID for tracking purposes.

      Returns string

      A unique identifier

    • Protected

      Handle errors according to the transport's configuration.

      Parameters

      • error: Error

        The error that occurred

      • Optionalentry: LogEntry

        The log entry that caused the error (if applicable)

      Returns void

    • Initialize the transport.

      Returns Promise<void>

      Resolves when initialization is complete

      If initialization fails

    • Check if the transport is currently enabled.

      Returns boolean

      True if transport is enabled

    • Check if transport is healthy.

      Returns Promise<boolean>

      True if transport is healthy

    • Protected

      Check if a log level is enabled based on minimum level.

      Parameters

      • level: string

        The level to check

      Returns boolean

      True if the level is enabled

    • Log multiple entries at once.

      Parameters

      • entries: LogEntry[]

        Array of log entries to process

      Returns Promise<void>

      Resolves when all logs have been processed

    • Check if this transport should handle a given log entry.

      Parameters

      Returns boolean

      True if the entry should be logged by this transport

    • Protected

      Whether this transport should rethrow errors encountered during log operations. Network-based transports typically want propagation so callers/tests can assert failures. Base transports default to swallowing errors after emitting events and updating stats.

      Returns boolean

    • Check if transport supports batching.

      Returns boolean

      True if batching is supported

    • Protected

      Apply a timeout to an async operation.

      Type Parameters

      • T

      Parameters

      • promise: Promise<T>

        The promise to apply timeout to

      • ms: number

        Timeout in milliseconds

      Returns Promise<T>

      The original promise with timeout applied

      If operation times out