Skip to content

Logger

The Logger module in DomusJS provides a unified, pluggable interface for logging across your entire application.

✅ Abstracts away the underlying logging implementation.
✅ Supports integrations like console, pino, or OpenTelemetry logs.
✅ Ensures consistent log format across modules and layers.


Without a centralized logger:

  • Different modules may log inconsistently.
  • You risk tightly coupling the system to a specific logging library.
  • Changing log providers becomes painful.

✅ DomusJS’s logger abstraction solves this by providing a clean interface you can bind to any implementation.


DomusJS defines the following logger interface in the core module:

interface Logger {
info(message: string, context?: any): void;
warn(message: string, context?: any): void;
error(message: string, context?: any): void;
debug?(message: string, context?: any): void;
}

✅ All framework modules (and your own) depend on this interface, not on the underlying library.


export class ConsoleLogger implements Logger {
info(message: string, attributes?: Record<string, any>) {
console.info(message, attributes);
}
warn(message: string, attributes?: Record<string, any>) {
console.warn(message, attributes);
}
error(message: string, attributes?: Record<string, any>) {
console.error(message, attributes);
}
debug(message: string, attributes?: Record<string, any>) {
console.debug(message, attributes);
}
}

✅ You can build your own implementation as long as it matches the interface.


You should call registerDomusCore() early in your app setup and pass your preferred logger:

import { registerDomusCore, PinoLogger } from '@domusjs/infrastructure';
registerDomusCore({
logger: new PinoLogger()
});

✅ This makes the logger injectable in any module using tsyringe.


import { Logger } from '@domusjs/core';
import { inject, injectable } from 'tsyringe';
@injectable()
export class SomeService {
constructor(@inject('Logger') private readonly logger: Logger) {}
doSomething() {
this.logger.info('Doing something', { context: 'SomeService' });
}
}

✅ You can inject and use the logger anywhere in your application.


✅ Use structured logs (with attributes) for better traceability.
✅ Keep log messages consistent across modules.
✅ Integrate logs with your observability stack (e.g., Datadog, Signoz) for full insights.
✅ Avoid leaving console.log scattered around; always use the centralized logger.