Skip to content

Logger

Structured logger with context-aware formatting and configurable levels.

Defined in: src/utils/logger.ts:90

Structured logger with context-aware formatting and configurable levels.

Remarks

The Logger class provides four severity methods (Logger.debug, Logger.info, Logger.warn, Logger.error) that respect the configured minimum log level. Messages are prefixed with a timestamp, level, and context string for easy filtering.

Supports custom logger functions for integration with external logging systems (e.g., Sentry, DataDog, or structured JSON logging).

Child loggers can be created with Logger.child to add nested context (e.g., 'CompositeVoice:STT:DeepgramSTT').

Example

import { Logger } from 'composite-voice';

const logger = new Logger('MyProvider', {
  enabled: true,
  level: 'info',
});

logger.info('Provider ready');

// Create a child logger with additional context
const childLogger = logger.child('WebSocket');
childLogger.debug('Connection established'); // [timestamp] [DEBUG] [MyProvider:WebSocket] ...

Constructors

Constructor

new Logger(context, config): Logger;

Defined in: src/utils/logger.ts:114

Creates a new Logger instance.

Parameters

ParameterTypeDescription
contextstringA label identifying the source of log messages (e.g., 'DeepgramTTS').
configLoggingConfigLogging configuration controlling enabled state, level, and custom logger.

Returns

Logger

Example

const logger = new Logger('CompositeVoice', {
  enabled: true,
  level: 'debug',
  logger: (level, message, ...args) => {
    // Custom logging integration
    externalLogger.log({ level, message, args });
  },
});

Methods

child()

child(childContext): Logger;

Defined in: src/utils/logger.ts:286

Creates a child logger with a nested context label.

Parameters

ParameterTypeDescription
childContextstringThe context label for the child logger.

Returns

Logger

A new Logger instance with the combined context parent:child.

Remarks

The child logger inherits the parent’s configuration (enabled state, level, custom logger) and appends the child context to the parent context with a colon separator.

Example

const parentLogger = new Logger('CompositeVoice', { enabled: true, level: 'debug' });
const childLogger = parentLogger.child('DeepgramTTS');
// Child context: 'CompositeVoice:DeepgramTTS'
childLogger.info('Connected'); // [timestamp] [INFO] [CompositeVoice:DeepgramTTS] Connected

debug()

debug(message, ...args): void;

Defined in: src/utils/logger.ts:185

Logs a debug-level message.

Parameters

ParameterTypeDescription
messagestringThe debug message to log.
argsunknown[]Additional data to include in the log output.

Returns

void

Remarks

Debug messages provide detailed diagnostic information useful during development. They are only output when the configured level is LogLevel.DEBUG or lower.


error()

error(message, ...args): void;

Defined in: src/utils/logger.ts:254

Logs an error-level message.

Parameters

ParameterTypeDescription
messagestringThe error message to log.
argsunknown[]Additional data to include in the log output (typically error objects).

Returns

void

Remarks

Error messages indicate failures that may prevent normal operation. Always output unless logging is disabled entirely.


info()

info(message, ...args): void;

Defined in: src/utils/logger.ts:208

Logs an info-level message.

Parameters

ParameterTypeDescription
messagestringThe informational message to log.
argsunknown[]Additional data to include in the log output.

Returns

void

Remarks

Info messages describe normal operational events such as initialization, connection establishment, or configuration details.


warn()

warn(message, ...args): void;

Defined in: src/utils/logger.ts:231

Logs a warning-level message.

Parameters

ParameterTypeDescription
messagestringThe warning message to log.
argsunknown[]Additional data to include in the log output.

Returns

void

Remarks

Warning messages indicate potentially harmful situations or unexpected conditions that do not prevent normal operation but may warrant attention.

© 2026 CompositeVoice. All rights reserved.

Font size
Contrast
Motion
Transparency