fix: inherit logging level from config

This commit is contained in:
Wesley F. Young 2024-08-12 01:12:27 +08:00
parent 436249597d
commit 7152213344
2 changed files with 18 additions and 7 deletions

View File

@ -68,7 +68,7 @@ export class LogWrapper {
this.setLogSelfInfo({ nick: '', uin: '', uid: '' }); this.setLogSelfInfo({ nick: '', uin: '', uid: '' });
} }
setLogLevel(fileLogLevel: LogLevel, consoleLogLevel: LogLevel) { setFileAndConsoleLogLevel(fileLogLevel: LogLevel, consoleLogLevel: LogLevel) {
this.logConfig.categories.file.level = fileLogLevel; this.logConfig.categories.file.level = fileLogLevel;
this.logConfig.categories.console.level = consoleLogLevel; this.logConfig.categories.console.level = consoleLogLevel;
log4js.configure(this.logConfig); log4js.configure(this.logConfig);
@ -81,13 +81,12 @@ export class LogWrapper {
this.loggerDefault.addContext('userInfo', userInfo); this.loggerDefault.addContext('userInfo', userInfo);
} }
setFileLogEnabled(isEnabled: boolean) {
enableFileLog(enable: boolean) { this.fileLogEnabled = isEnabled;
this.fileLogEnabled = enable;
} }
enableConsoleLog(enable: boolean) { setConsoleLogEnabled(isEnabled: boolean) {
this.consoleLogEnabled = enable; this.consoleLogEnabled = isEnabled;
} }
formatMsg(msg: any[]) { formatMsg(msg: any[]) {

View File

@ -10,6 +10,7 @@ import { NTQQFileApi, NTQQFriendApi, NTQQGroupApi, NTQQMsgApi, NTQQSystemApi, NT
import os from 'node:os'; import os from 'node:os';
import { NTQQCollectionApi } from './apis/collection'; import { NTQQCollectionApi } from './apis/collection';
import { NapCatConfigLoader } from './helper/config'; import { NapCatConfigLoader } from './helper/config';
import { LogLevel } from '@/common/utils/log';
export enum NapCatCoreWorkingEnv { export enum NapCatCoreWorkingEnv {
Unknown = 0, Unknown = 0,
@ -55,7 +56,7 @@ export class NapCatCore {
UserApi: new NTQQUserApi(this.context, this), UserApi: new NTQQUserApi(this.context, this),
GroupApi: new NTQQGroupApi(this.context, this), GroupApi: new NTQQGroupApi(this.context, this),
}; };
this.configLoader = new NapCatConfigLoader(this,this.context.pathWrapper.configPath); this.configLoader = new NapCatConfigLoader(this, this.context.pathWrapper.configPath);
this.NapCatDataPath = path.join(this.dataPath, 'NapCat'); this.NapCatDataPath = path.join(this.dataPath, 'NapCat');
fs.mkdirSync(this.NapCatDataPath, { recursive: true }); fs.mkdirSync(this.NapCatDataPath, { recursive: true });
this.NapCatTempPath = path.join(this.NapCatDataPath, 'temp'); this.NapCatTempPath = path.join(this.NapCatDataPath, 'temp');
@ -64,6 +65,17 @@ export class NapCatCore {
fs.mkdirSync(this.NapCatTempPath, { recursive: true }); fs.mkdirSync(this.NapCatTempPath, { recursive: true });
} }
this.initNapCatCoreListeners().then().catch(this.context.logger.logError); this.initNapCatCoreListeners().then().catch(this.context.logger.logError);
this.context.logger.setFileLogEnabled(
this.configLoader.configData.fileLog,
);
this.context.logger.setConsoleLogEnabled(
this.configLoader.configData.consoleLog,
);
this.context.logger.setFileAndConsoleLogLevel(
this.configLoader.configData.fileLogLevel as LogLevel,
this.configLoader.configData.consoleLogLevel as LogLevel,
);
} }
get dataPath(): string { get dataPath(): string {