From d80ba28172fc45c20d988bc98a474fcfeb4d0766 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A3=E4=B8=87=E4=BF=8A?= Date: Tue, 13 Jan 2026 16:44:20 +0800 Subject: [PATCH] =?UTF-8?q?feat/=E6=89=93=E5=8D=B0=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/logger.js | 84 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/utils/logger.js diff --git a/src/utils/logger.js b/src/utils/logger.js new file mode 100644 index 0000000..75b73a6 --- /dev/null +++ b/src/utils/logger.js @@ -0,0 +1,84 @@ +/* + * @Author: 系统生成 + * @Date: 2025-01-XX + * @Description: 日志工具 - 根据环境变量控制日志输出 + */ + +// 判断是否为生产环境 +const isProduction = import.meta.env.MODE === 'production' || import.meta.env.PROD + +// 日志工具类 +const logger = { + /** + * 普通日志(生产环境不输出) + */ + log(...args) { + if (!isProduction) { + console.log(...args) + } + }, + + /** + * 警告日志(生产环境不输出) + */ + warn(...args) { + if (!isProduction) { + console.warn(...args) + } + }, + + /** + * 错误日志(始终输出) + */ + error(...args) { + console.error(...args) + }, + + /** + * 信息日志(生产环境不输出) + */ + info(...args) { + if (!isProduction) { + console.info(...args) + } + }, + + /** + * 调试日志(生产环境不输出) + */ + debug(...args) { + if (!isProduction) { + console.debug(...args) + } + }, + + /** + * 分组日志(生产环境不输出) + */ + group(...args) { + if (!isProduction) { + console.group(...args) + } + }, + + /** + * 结束分组(生产环境不输出) + */ + groupEnd() { + if (!isProduction) { + console.groupEnd() + } + }, + + /** + * 表格日志(生产环境不输出) + */ + table(...args) { + if (!isProduction) { + console.table(...args) + } + } +} + +export default logger +