| 7 | const NOOP_TASK_LOGGER = new NoopTaskLogger(); |
| 8 | |
| 9 | export class LoggerAPI implements TaskLogger { |
| 10 | private static _instance?: LoggerAPI; |
| 11 | |
| 12 | private constructor() {} |
| 13 | |
| 14 | public static getInstance(): LoggerAPI { |
| 15 | if (!this._instance) { |
| 16 | this._instance = new LoggerAPI(); |
| 17 | } |
| 18 | |
| 19 | return this._instance; |
| 20 | } |
| 21 | |
| 22 | public disable() { |
| 23 | unregisterGlobal(API_NAME); |
| 24 | } |
| 25 | |
| 26 | public setGlobalTaskLogger(taskLogger: TaskLogger): boolean { |
| 27 | return registerGlobal(API_NAME, taskLogger); |
| 28 | } |
| 29 | |
| 30 | public debug(message: string, metadata?: Record<string, unknown>) { |
| 31 | this.#getTaskLogger().debug(message, metadata); |
| 32 | } |
| 33 | |
| 34 | public log(message: string, metadata?: Record<string, unknown>) { |
| 35 | this.#getTaskLogger().log(message, metadata); |
| 36 | } |
| 37 | |
| 38 | public info(message: string, metadata?: Record<string, unknown>) { |
| 39 | this.#getTaskLogger().info(message, metadata); |
| 40 | } |
| 41 | |
| 42 | public warn(message: string, metadata?: Record<string, unknown>) { |
| 43 | this.#getTaskLogger().warn(message, metadata); |
| 44 | } |
| 45 | |
| 46 | public error(message: string, metadata?: Record<string, unknown>) { |
| 47 | this.#getTaskLogger().error(message, metadata); |
| 48 | } |
| 49 | |
| 50 | public trace<T>(name: string, fn: (span: Span) => Promise<T>): Promise<T> { |
| 51 | return this.#getTaskLogger().trace(name, fn); |
| 52 | } |
| 53 | |
| 54 | #getTaskLogger(): TaskLogger { |
| 55 | return getGlobal(API_NAME) ?? NOOP_TASK_LOGGER; |
| 56 | } |
| 57 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…