From 32fd1e27f27da2c2a45b2135671d1d8e1623331f Mon Sep 17 00:00:00 2001 From: ningmengchongshui <916415899@qq.com> Date: Sun, 9 Jun 2024 12:31:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E5=A4=B1=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/{index.d.ts => global.d.ts} | 7 ++-- src/lib/config/log.ts | 64 +++++++++++++++++++-------------- 2 files changed, 43 insertions(+), 28 deletions(-) rename src/{index.d.ts => global.d.ts} (85%) diff --git a/src/index.d.ts b/src/global.d.ts similarity index 85% rename from src/index.d.ts rename to src/global.d.ts index 76da7f2..96149aa 100644 --- a/src/index.d.ts +++ b/src/global.d.ts @@ -2,10 +2,13 @@ import { segment as se } from 'icqq' import { RedisClientType } from 'redis' import { Yunzai } from './bot.js' import { plugin as p } from './core/index.js' +/** + * 全局变量声明 + */ declare global { let redis: RedisClientType let Bot: typeof Yunzai.prototype let segment: typeof se - let logger: typeof console let plugin: typeof p.prototype -} + let logger: any +} \ No newline at end of file diff --git a/src/lib/config/log.ts b/src/lib/config/log.ts index 91a500b..6d7cafd 100644 --- a/src/lib/config/log.ts +++ b/src/lib/config/log.ts @@ -2,20 +2,15 @@ import log4js from 'log4js' import chalk from 'chalk' import cfg from './config.js' import fs from 'node:fs' + /** -* 设置日志样式 -*/ -export default function setLog () { - let file = './logs' - if (!fs.existsSync(file)) { - fs.mkdirSync(file) - } - - /** 调整error日志等级 */ + * 创建日志 + * @returns + */ +function createLog() { // log4js.levels.levels[5].level = Number.MAX_VALUE // log4js.levels.levels.sort((a, b) => a.level - b.level) - log4js.configure({ appenders: { console: { @@ -57,40 +52,57 @@ export default function setLog () { const commandLogger = log4js.getLogger('command') const errorLogger = log4js.getLogger('error') - /* eslint-disable no-useless-call */ - /** 全局变量 logger */ - global.logger = { - trace () { + /** 调整error日志等级 */ + + const logger = { + trace() { defaultLogger.trace.call(defaultLogger, ...arguments) }, - debug () { + debug() { defaultLogger.debug.call(defaultLogger, ...arguments) }, - info () { + info() { defaultLogger.info.call(defaultLogger, ...arguments) }, // warn及以上的日志采用error策略 - warn () { + warn() { commandLogger.warn.call(defaultLogger, ...arguments) }, - error () { + error() { errorLogger.error.call(errorLogger, ...arguments) }, - fatal () { + fatal() { errorLogger.fatal.call(errorLogger, ...arguments) }, - mark () { + mark() { errorLogger.mark.call(commandLogger, ...arguments) } } - - logColor() + return logger } /** - * - */ -function logColor () { +* 设置日志样式 +*/ +export default function setLog() { + + /** + * + */ + let file = './logs' + + /** + * + */ + if (!fs.existsSync(file)){ + fs.mkdirSync(file, { + 'recursive': true + }) + } + + /** 全局变量 logger */ + global.logger = createLog() + logger.chalk = chalk logger.red = chalk.red logger.green = chalk.green @@ -98,4 +110,4 @@ function logColor () { logger.blue = chalk.blue logger.magenta = chalk.magenta logger.cyan = chalk.cyan -} +} \ No newline at end of file