| 1 | import type { DestinationStream } from 'pino' |
| 2 | import { PassThrough } from 'node:stream' |
| 3 | import PinoPretty from 'pino-pretty' |
| 4 | |
| 5 | export class ConsoleLogger implements DestinationStream { |
| 6 | private readonly stream: PinoPretty.PrettyStream | NodeJS.WriteStream |
| 7 | |
| 8 | constructor(options: PinoPretty.PrettyOptions & { pretty: boolean }) { |
| 9 | if (!options.pretty) { |
| 10 | this.stream = new PassThrough() |
| 11 | this.stream.pipe(process.stdout) |
| 12 | } |
| 13 | else { |
| 14 | this.stream = PinoPretty({ ...options, colorize: true, destination: process.stdout }) |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | write(msg: string): void { |
| 19 | this.stream.push(msg) |
| 20 | } |
| 21 | } |
| 22 |