Skip to content

Commit

Permalink
chore: revert
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 committed Dec 21, 2024
1 parent e646afd commit db21608
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 66 deletions.
65 changes: 2 additions & 63 deletions packages/core/src/service/loggerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
LoggerFactory,
} from '../common/loggerFactory';
import { MidwayFeatureNoLongerSupportedError } from '../error';
import { extend } from '../util/extend';

@Provide()
@Scope(ScopeEnum.Singleton)
Expand All @@ -35,7 +34,7 @@ export class MidwayLoggerService extends ServiceFactory<ILogger> {
}

@Init()
protected async init() {
protected init() {
const loggerFactory = this.configService.getConfiguration('loggerFactory');

// load logger factory from user config first
Expand All @@ -59,67 +58,7 @@ export class MidwayLoggerService extends ServiceFactory<ILogger> {
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',
Expand Down
3 changes: 0 additions & 3 deletions packages/web/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export async function initializeAgentApplicationContext(agent) {
MidwayEnvironmentService
);
agentFramework.loggerService = applicationContext.get(MidwayLoggerService);
agentFramework.loggerService.initSync();
agentFramework.informationService = applicationContext.get(
MidwayInformationService
);
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit db21608

Please sign in to comment.