|
1 | 1 | import type pino from 'pino'; |
2 | 2 | import type { DomainLogger } from '@domain/service/shared/logger.js'; |
3 | | -import { getRequestLogger } from '@infrastructure/logging/index.js'; |
| 3 | +import { getLogger } from '@infrastructure/logging/index.js'; |
| 4 | +import { getCurrentReqId } from '@infrastructure/logging/reqId.context.js'; |
4 | 5 |
|
5 | 6 | /** |
6 | 7 | * Adapter that wraps a pino.Logger to implement the DomainLogger interface |
7 | 8 | * This allows the infrastructure's pino logger to be injected into domain services |
8 | 9 | * without the domain layer depending directly on pino |
9 | 10 | */ |
10 | 11 | export class PinoDomainLoggerAdapter implements DomainLogger { |
| 12 | + private readonly baseLogger: pino.Logger; |
| 13 | + |
| 14 | + constructor() { |
| 15 | + this.baseLogger = getLogger('domain'); |
| 16 | + } |
| 17 | + |
11 | 18 | public debug(msg: string, meta?: Record<string, unknown>): void { |
12 | | - this.getReqLogger().debug({ |
13 | | - msg, |
14 | | - ...meta, |
15 | | - }); |
| 19 | + const reqId = getCurrentReqId(); |
| 20 | + |
| 21 | + this.baseLogger.debug({ ...meta, |
| 22 | + reqId }, msg); |
16 | 23 | } |
17 | 24 |
|
18 | 25 | public info(msg: string, meta?: Record<string, unknown>): void { |
19 | | - this.getReqLogger().info({ |
20 | | - msg, |
21 | | - ...meta, |
22 | | - }); |
| 26 | + const reqId = getCurrentReqId(); |
| 27 | + |
| 28 | + this.baseLogger.info({ ...meta, |
| 29 | + reqId }, msg); |
23 | 30 | } |
24 | 31 |
|
25 | 32 | public warn(msg: string, meta?: Record<string, unknown>): void { |
26 | | - this.getReqLogger().warn({ |
27 | | - msg, |
28 | | - ...meta, |
29 | | - }); |
30 | | - } |
| 33 | + const reqId = getCurrentReqId(); |
31 | 34 |
|
32 | | - private getReqLogger(): pino.Logger { |
33 | | - return getRequestLogger('domain'); |
| 35 | + this.baseLogger.warn({ ...meta, |
| 36 | + reqId }, msg); |
34 | 37 | } |
35 | 38 | } |
0 commit comments