Interfaces

Logging Interface

Explore the Logging interface that provides structured logging capabilities across your Antelopejs application.

Key Features

The Logging interface provides a structured, standardized way to log information across your Antelopejs application. It offers multiple severity levels, channel-based categorization, and an event-based architecture for capturing and processing log entries.

  • Severity levels: Predefined levels (ERROR, WARN, INFO, DEBUG, TRACE) for categorizing log importance
  • Channels: Separate logging channels for different components or concerns
  • Event-based: Uses the EventProxy system for flexible log processing
  • Standardized API: Consistent logging interface across the entire application

Basic Usage

Importing the Logging Interface

import { Logging } from '@ajs/logging/beta';

Using Standard Logging Methods

// Log an error
Logging.Error('Failed to connect to database', error);

// Log a warning
Logging.Warn('Connection pool running low', { available: 2, total: 10 });

// Log general information
Logging.Info('User logged in', { userId: 'user123' });

// Log debug information
Logging.Debug('Processing request', request);

// Log highly detailed trace information
Logging.Trace('Function called with arguments', args);

Using Custom Channels

// Log to a custom channel with specific severity
Logging.Write(Logging.Level.INFO, 'database', 'Query executed in 15ms', { query, params });

Log Levels

The Logging interface provides five standard severity levels:

LevelValueDescriptionUse Case
ERROR40Critical errors that may cause application failureFailed database connections, API errors, crashes
WARN30Important issues that don't prevent functioningDegraded performance, retries, deprecated feature use
INFO20General application information and status updatesUser actions, business events, normal operations
DEBUG10Detailed information useful for debuggingVariable values, control flow, decision points
TRACE0Highly detailed tracing informationFunction entry/exit, loop iterations, detailed flow

Listening to Log Events

You can capture and process logs using the event system:

import eventLog from '@ajs/logging/beta/listener';

// Register a log listener
eventLog.register((log) => {
  const { time, channel, levelId, args } = log;

  // Example: Send to console
  const timestamp = new Date(time).toISOString();
  const level = getLevelName(levelId);

  if (levelId >= Logging.Level.WARN) {
    sendToExternalService({ timestamp, level, channel, message: args });
  }
});

// Helper function to get level name
function getLevelName(levelId: number): string {
  switch (levelId) {
    case Logging.Level.ERROR: return 'ERROR';
    case Logging.Level.WARN: return 'WARN';
    case Logging.Level.INFO: return 'INFO';
    case Logging.Level.DEBUG: return 'DEBUG';
    case Logging.Level.TRACE: return 'TRACE';
    default: return 'UNKNOWN';
  }
}