Skip to content

Commit

Permalink
fix: ServerConfig cannot be found when the component is unmounted (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
hacke2 authored Nov 29, 2024
1 parent bff6397 commit 4a12e25
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/sumi-core/src/server/logs-core/log-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<LogLevel>();
private globalLogLevel: LogLevel;
Expand All @@ -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();
}
Expand All @@ -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 = (
Expand Down

0 comments on commit 4a12e25

Please sign in to comment.