Skip to content

Commit

Permalink
fix: can't throw error in faas (#790)
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 authored Jan 5, 2021
1 parent 9ebd596 commit e740cda
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/faas/src/framework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
6 changes: 4 additions & 2 deletions packages/logger/src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ export class MidwayLoggerContainer extends Map<string, ILogger> {
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);
Expand Down

0 comments on commit e740cda

Please sign in to comment.