From 4a12e258410caace43935784ae60bfd68b73a6f6 Mon Sep 17 00:00:00 2001 From: hacke2 Date: Fri, 29 Nov 2024 17:46:58 +0800 Subject: [PATCH] fix: ServerConfig cannot be found when the component is unmounted (#236) --- packages/sumi-core/src/server/logs-core/log-manager.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/sumi-core/src/server/logs-core/log-manager.ts b/packages/sumi-core/src/server/logs-core/log-manager.ts index b5befedd..a87357e2 100644 --- a/packages/sumi-core/src/server/logs-core/log-manager.ts +++ b/packages/sumi-core/src/server/logs-core/log-manager.ts @@ -14,7 +14,8 @@ import { DEFAULT_LOG_FOLDER, LogService } from './log.service'; @Injectable() export class LogServiceManager implements ILogServiceManager { @Autowired(ServerConfig) - private serverConfig: ServerConfig; + // 卸载时会有时序问题导致 serverConfig 被销毁,这边改为 Optional + private serverConfig?: ServerConfig; protected readonly logLevelChangeEmitter = new Emitter(); private globalLogLevel: LogLevel; @@ -25,8 +26,8 @@ export class LogServiceManager implements ILogServiceManager { constructor() { this.init({ - logDir: this.serverConfig.logDir, - logLevel: this.serverConfig.logLevel, + logDir: this.serverConfig?.logDir, + logLevel: this.serverConfig?.logLevel, }); this.cleanOldLogs(); } @@ -35,7 +36,7 @@ export class LogServiceManager implements ILogServiceManager { this.logRootFolderPath = options.logDir || DEFAULT_LOG_FOLDER; this.logFolderPath = this._getLogFolder(); this.globalLogLevel = options.logLevel || LogLevel.Info; - this.LogServiceClass = this.serverConfig.LogServiceClass || LogService; + this.LogServiceClass = this.serverConfig?.LogServiceClass || LogService; }; getLogger = (