| 12 | |
| 13 | @Injectable() |
| 14 | export class AmplicationLogger implements LoggerService, ILogger { |
| 15 | private logger: Logger; |
| 16 | private loggerOptions: LoggerOptions; |
| 17 | |
| 18 | constructor( |
| 19 | @Inject(AMPLICATION_LOGGER_MODULE_OPTIONS) |
| 20 | options: AmplicationLoggerModulesOptions |
| 21 | ) { |
| 22 | this.loggerOptions = { |
| 23 | component: options.component, |
| 24 | logLevel: options.logLevel, |
| 25 | isProduction: |
| 26 | options.isProduction ?? process.env.NODE_ENV === "production", |
| 27 | metadata: options.metadata, |
| 28 | }; |
| 29 | |
| 30 | this.logger = new Logger(this.loggerOptions); |
| 31 | } |
| 32 | |
| 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 34 | public debug(message: string, ...args: any[]): void { |
| 35 | args = args.filter((arg) => typeof arg === "object"); |
| 36 | this.logger.debug(message, ...args); |
| 37 | } |
| 38 | |
| 39 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 40 | public info(message: string, ...args: any[]): void { |
| 41 | args = args.filter((arg) => typeof arg === "object"); |
| 42 | this.logger.info(message, ...args); |
| 43 | } |
| 44 | |
| 45 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 46 | public warn(message: string, ...args: any[]): void { |
| 47 | args = args.filter((arg) => typeof arg === "object"); |
| 48 | this.logger.warn(message, ...args); |
| 49 | } |
| 50 | |
| 51 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 52 | public error(message: string, error?: Error, ...args: any[]): void { |
| 53 | args = args.filter((arg) => typeof arg === "object"); |
| 54 | this.logger.error(message, error, ...args); |
| 55 | } |
| 56 | |
| 57 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 58 | public log(message: string, ...args: any[]): void { |
| 59 | args = args.filter((arg) => typeof arg === "object"); |
| 60 | this.logger.info(message, ...args); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Generated a new logger instance with the same configuration of the parent with additional metadata. |
| 65 | * @param {Record<string, unknown} metadata? |
| 66 | * @returns Logger |
| 67 | */ |
| 68 | public child(metadata?: Record<string, unknown>): Logger { |
| 69 | const childOptions = { |
| 70 | ...this.loggerOptions, |
| 71 | metadata: { |
nothing calls this directly
no outgoing calls
no test coverage detected