Logger Implementations
DomusJS provides a pluggable Logger system that lets you integrate different logging backends while keeping your application code clean and consistent.
✅ All modules and services rely on the Logger
interface, not on specific libraries.
✅ You can swap implementations without changing your business logic.
Provided Implementations
Section titled “Provided Implementations”DomusJS ships with several ready-to-use logger integrations:
🖥️ ConsoleLogger
Section titled “🖥️ ConsoleLogger”Simple wrapper over console.*
:
ConsoleLogger
✅ Great for development and local testing.
⚡ PinoLogger
Section titled “⚡ PinoLogger”Integration with Pino, a fast, structured logger:
PinoLogger
✅ Suitable for production setups where performance matters.
🌐 OpenTelemetryLogger
Section titled “🌐 OpenTelemetryLogger”Integration with OpenTelemetry, sending logs to observability backends like Signoz, Datadog, etc.
OpenTelemetryLogger
✅ Ideal for teams that want full tracing, metrics, and logging integration.
How to Register the Logger
Section titled “How to Register the Logger”Use the registerDomusCore()
helper:
import { registerDomusCore, PinoLogger } from '@domusjs/infrastructure';
registerDomusCore({ // Alternatively, you can use the ConsoleLogger, OpenTelemetryLogger or your own logger implementation logger: new PinoLogger()});
✅ Once registered, the logger is injectable anywhere:
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('Service action executed', { context: 'SomeService' }); }}
Best Practices
Section titled “Best Practices”✅ Always use the Logger
interface — avoid calling raw console.*
directly.
✅ Use structured attributes for context ({ context: 'SomeService' }
).
✅ Integrate the logger with your tracing setup for unified observability.
✅ Centralize configuration and never instantiate loggers manually in services.