Skip to Content
DocsClaDIServicesLogging Service

Logging Service

ClaDI provides a logger contract (ILogger) and a console implementation (ConsoleLoggerService).

ILogger

src/domain/interface/logger/interface.ts
export interface ILogger { debug(message: string, options?: ILoggerMethodOptions): void; error(message: string, options?: ILoggerMethodOptions): void; info(message: string, options?: ILoggerMethodOptions): void; trace(message: string, options?: ILoggerMethodOptions): void; warn(message: string, options?: ILoggerMethodOptions): void; }

ILoggerMethodOptions

NameTypeDefault
contextRecord<string, unknown>

Optional context to include with the log.

sourcestring

Optional source identifier (e.g. “React”, “NestJS Scheduler”).

ConsoleLoggerService

ConsoleLoggerService prints timestamped logs with level, source, and optional structured context.

IConsoleLoggerOptions

NameTypeDefault
levelELoggerLogLevel

The log level to use.

ELoggerLogLevel.INFO
sourcestring

The source to use for the logger.

createLogger()

src/logger.ts
import { createLogger, ELoggerLogLevel } from "@elsikora/cladi"; const logger = createLogger({ level: ELoggerLogLevel.DEBUG, source: "Bootstrap", }); logger.info("Application started"); logger.debug("Configuration loaded", { context: { featureFlags: ["a", "b"] }, });

DI Integration

Register logger as a contract and inject where needed:

src/composition-logger.ts
import { createLogger, createToken, type ILogger } from "@elsikora/cladi"; const LoggerToken = createToken<ILogger>("Logger"); container.register({ provide: LoggerToken, useValue: createLogger({ source: "App" }), });
Last updated on