diff --git a/packages/core/src/service/loggerService.ts b/packages/core/src/service/loggerService.ts index 20a2b2a7fc2..1f03e233545 100644 --- a/packages/core/src/service/loggerService.ts +++ b/packages/core/src/service/loggerService.ts @@ -13,7 +13,6 @@ import { LoggerFactory, } from '../common/loggerFactory'; import { MidwayFeatureNoLongerSupportedError } from '../error'; -import { extend } from '../util/extend'; @Provide() @Scope(ScopeEnum.Singleton) @@ -35,7 +34,7 @@ export class MidwayLoggerService extends ServiceFactory { } @Init() - protected async init() { + protected init() { const loggerFactory = this.configService.getConfiguration('loggerFactory'); // load logger factory from user config first @@ -59,67 +58,7 @@ export class MidwayLoggerService extends ServiceFactory { this.configService.addObject(defaultLoggerConfig, true); // init logger - await this.initClients(this.configService.getConfiguration('midwayLogger')); - // alias inject logger - this.applicationContext?.registerObject( - 'logger', - this.getLogger('appLogger') - ); - } - - /** - * just for egg - */ - public initSync() { - const loggerFactory = this.configService.getConfiguration('loggerFactory'); - - // load logger factory from user config first - this.loggerFactory = - loggerFactory || - this.globalOptions['loggerFactory'] || - new DefaultConsoleLoggerFactory(); - - // check - if (!this.loggerFactory.getDefaultMidwayLoggerConfig) { - throw new MidwayFeatureNoLongerSupportedError( - 'please upgrade your @midwayjs/logger to latest version' - ); - } - - const defaultLoggerConfig = this.loggerFactory.getDefaultMidwayLoggerConfig( - this.configService.getAppInfo() - ); - - // merge to user config - this.configService.addObject(defaultLoggerConfig, true); - - // init logger - const options = this.configService.getConfiguration('midwayLogger'); - this.options = options; - - // merge options.client to options.clients['default'] - if (options.client) { - options.clients = options.clients || {}; - options.clients['default'] = options.clients['default'] || {}; - extend(true, options.clients['default'], options.client); - } - - // multi client - if (options.clients) { - for (const id of Object.keys(options.clients)) { - const newConfig = extend( - true, - {}, - options['default'], - options.clients[id] - ); - this.createClient(newConfig, id); - } - } - - // set priority - this.clientPriority = options.priority || {}; - + this.initClients(this.configService.getConfiguration('midwayLogger')); // alias inject logger this.applicationContext?.registerObject( 'logger', diff --git a/packages/web/src/utils.ts b/packages/web/src/utils.ts index 21b1be70379..78a1fdceeca 100644 --- a/packages/web/src/utils.ts +++ b/packages/web/src/utils.ts @@ -87,7 +87,6 @@ export async function initializeAgentApplicationContext(agent) { MidwayEnvironmentService ); agentFramework.loggerService = applicationContext.get(MidwayLoggerService); - agentFramework.loggerService.initSync(); agentFramework.informationService = applicationContext.get( MidwayInformationService ); @@ -117,8 +116,6 @@ export async function initializeAgentApplicationContext(agent) { const loggerService = getCurrentApplicationContext().get(MidwayLoggerService); - loggerService.initSync(); - // framework/config/plugin/logger/app decorator support // register base config hook decoratorService.registerPropertyHandler(