fix:修复bug
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Console 日志配置
|
||||
* 用于控制是否在控制台打印日志
|
||||
*/
|
||||
|
||||
// 配置项:true 表示打印日志,false 表示不打印日志
|
||||
export const CONSOLE_CONFIG = {
|
||||
// 是否启用 console.log
|
||||
enableLog: true,
|
||||
// 是否启用 console.warn
|
||||
enableWarn: true,
|
||||
// 是否启用 console.error
|
||||
enableError: true,
|
||||
// 是否启用 console.info
|
||||
enableInfo: true
|
||||
}
|
||||
|
||||
// 保存原始的 console 方法
|
||||
const originalConsole = {
|
||||
log: console.log,
|
||||
warn: console.warn,
|
||||
error: console.error,
|
||||
info: console.info
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化 console 控制
|
||||
* 根据配置决定是否打印日志
|
||||
*/
|
||||
export function initConsoleControl() {
|
||||
// 重写 console.log
|
||||
console.log = function(...args) {
|
||||
if (CONSOLE_CONFIG.enableLog) {
|
||||
originalConsole.log.apply(console, args)
|
||||
}
|
||||
}
|
||||
|
||||
// 重写 console.warn
|
||||
console.warn = function(...args) {
|
||||
if (CONSOLE_CONFIG.enableWarn) {
|
||||
originalConsole.warn.apply(console, args)
|
||||
}
|
||||
}
|
||||
|
||||
// 重写 console.error
|
||||
console.error = function(...args) {
|
||||
if (CONSOLE_CONFIG.enableError) {
|
||||
originalConsole.error.apply(console, args)
|
||||
}
|
||||
}
|
||||
|
||||
// 重写 console.info
|
||||
console.info = function(...args) {
|
||||
if (CONSOLE_CONFIG.enableInfo) {
|
||||
originalConsole.info.apply(console, args)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复原始的 console 方法
|
||||
*/
|
||||
export function restoreConsole() {
|
||||
console.log = originalConsole.log
|
||||
console.warn = originalConsole.warn
|
||||
console.error = originalConsole.error
|
||||
console.info = originalConsole.info
|
||||
}
|
||||
|
||||
/**
|
||||
* 动态设置 console 配置
|
||||
* @param {Object} config - 配置对象
|
||||
*/
|
||||
export function setConsoleConfig(config) {
|
||||
Object.assign(CONSOLE_CONFIG, config)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user