fix: 修复全局变量失效

This commit is contained in:
ningmengchongshui 2024-06-09 12:31:15 +08:00
parent 31aab55f65
commit 32fd1e27f2
2 changed files with 43 additions and 28 deletions

View File

@ -2,10 +2,13 @@ import { segment as se } from 'icqq'
import { RedisClientType } from 'redis' import { RedisClientType } from 'redis'
import { Yunzai } from './bot.js' import { Yunzai } from './bot.js'
import { plugin as p } from './core/index.js' import { plugin as p } from './core/index.js'
/**
*
*/
declare global { declare global {
let redis: RedisClientType let redis: RedisClientType
let Bot: typeof Yunzai.prototype let Bot: typeof Yunzai.prototype
let segment: typeof se let segment: typeof se
let logger: typeof console
let plugin: typeof p.prototype let plugin: typeof p.prototype
let logger: any
} }

View File

@ -3,19 +3,14 @@ import chalk from 'chalk'
import cfg from './config.js' import cfg from './config.js'
import fs from 'node:fs' 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[5].level = Number.MAX_VALUE
// log4js.levels.levels.sort((a, b) => a.level - b.level) // log4js.levels.levels.sort((a, b) => a.level - b.level)
log4js.configure({ log4js.configure({
appenders: { appenders: {
console: { console: {
@ -57,9 +52,9 @@ export default function setLog () {
const commandLogger = log4js.getLogger('command') const commandLogger = log4js.getLogger('command')
const errorLogger = log4js.getLogger('error') const errorLogger = log4js.getLogger('error')
/* eslint-disable no-useless-call */ /** 调整error日志等级 */
/** 全局变量 logger */
global.logger = { const logger = {
trace() { trace() {
defaultLogger.trace.call(defaultLogger, ...arguments) defaultLogger.trace.call(defaultLogger, ...arguments)
}, },
@ -83,14 +78,31 @@ export default function setLog () {
errorLogger.mark.call(commandLogger, ...arguments) errorLogger.mark.call(commandLogger, ...arguments)
} }
} }
return logger
logColor()
} }
/**
*
*/
export default function setLog() {
/** /**
* *
*/ */
function logColor () { let file = './logs'
/**
*
*/
if (!fs.existsSync(file)){
fs.mkdirSync(file, {
'recursive': true
})
}
/** 全局变量 logger */
global.logger = createLog()
logger.chalk = chalk logger.chalk = chalk
logger.red = chalk.red logger.red = chalk.red
logger.green = chalk.green logger.green = chalk.green