diff --git a/packages/faas/src/framework.ts b/packages/faas/src/framework.ts index 141874e120ca..380464ab43b0 100644 --- a/packages/faas/src/framework.ts +++ b/packages/faas/src/framework.ts @@ -86,8 +86,8 @@ export class MidwayFaaSFramework extends BaseFramework< this.configurationOptions?.initializeContext?.['logger'] || console; this.appLogger = this.logger; - loggers.addLogger('coreLogger', this.logger); - loggers.addLogger('appLogger', this.logger); + loggers.addLogger('coreLogger', this.logger, false); + loggers.addLogger('appLogger', this.logger, false); } } diff --git a/packages/logger/src/container.ts b/packages/logger/src/container.ts index ae6317542563..521c20fcdb3a 100644 --- a/packages/logger/src/container.ts +++ b/packages/logger/src/container.ts @@ -21,15 +21,17 @@ export class MidwayLoggerContainer extends Map { return this.getLogger(name); } - addLogger(name: string, logger: ILogger, replaceError = true) { + addLogger(name: string, logger: ILogger, errorWhenReplace = true) { if (!this.has(name)) { if (logger['on']) { (logger as any).on('close', () => this.delete(name)); } this.set(name, logger); } else { - if (replaceError) { + if (errorWhenReplace) { throw new Error(`logger id ${name} has duplicate`); + } else { + return this.addLogger(name, logger, false); } } return this.get(name);