| 1 | import { Channel, LoggerObjectController } from "./upstairs"; |
| 2 | |
| 3 | export default class DefaultObjectLogger implements LoggerObjectController { |
| 4 | |
| 5 | constructor( |
| 6 | private readonly prefix: string | undefined, |
| 7 | private readonly logs: unknown[], |
| 8 | private readonly namespaces?: Record<string, true> |
| 9 | ) { } |
| 10 | send(namespace: string, channel: Channel, interpolated: string): void { |
| 11 | if (!this.isEnabled(namespace)) { |
| 12 | return; |
| 13 | } |
| 14 | const finalNamespace = this.prefix ? `${this.prefix}/${namespace}` : namespace; |
| 15 | this.logs.push({ ns: finalNamespace, channel, msg: interpolated }); |
| 16 | } |
| 17 | |
| 18 | isEnabled(namespace: string): boolean { |
| 19 | if (!this.namespaces) { |
| 20 | return true; |
| 21 | } |
| 22 | return (namespace in this.namespaces); |
| 23 | } |
| 24 | sendObject<T extends abstract new (...args: any) => Error>(namespace: string, constructor: T, ...args: ConstructorParameters<T>): void { |
| 25 | if (!this.isEnabled(namespace)) { |
| 26 | return; |
| 27 | } |
| 28 | const obj = new (constructor as any)(...args); |
| 29 | const finalNamespace = this.prefix ? `${this.prefix}/${namespace}` : namespace; |
| 30 | this.logs.push({ ns: finalNamespace, obj }); |
| 31 | } |
| 32 | } |
nothing calls this directly
no outgoing calls
no test coverage detected