refactor(logger): optimize logging architecture with 6 improvements

1. Extract shared module: consolidate getLogDir() and isProduction()
   into shared.ts, eliminate duplication across logger modules
2. Make retention config effective: delay file transport creation
   until config is loaded, apply appRetention/auditRetention from config.yaml
3. Add before-quit log flush: close logger and audit logger on
   app exit to prevent log loss
4. Unify logError entry point: remove duplicate logError from index.ts,
   re-export from error-utils.ts with richer error context
5. Renderer log level filtering: add client-side level check in preload
   to skip IPC for filtered-out messages
6. Child logger cache + audit cleanup: cache child loggers in IPC
   handler for performance, remove redundant timestamp format in audit logger

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Misaka
2026-04-03 20:53:53 +08:00
parent 020bbcdccc
commit 883f98065a
22 changed files with 300 additions and 176 deletions

View File

@@ -48,13 +48,13 @@ graph TD
## 文档职责一览
| 文档 | 主要回答的问题 |
| --- | --- |
| `overview.md` | 这个项目整体是什么、做什么、核心目录和主链路是什么 |
| `runtime-architecture.md` | `main / preload / renderer` 如何协作 |
| `data-flow.md` | 核心业务数据如何在各层之间流动 |
| `file-map.md` | 关键文件在哪里、应该先看哪些入口 |
| `decision-log.md` | 最近几轮重要重构和架构决策是什么 |
| 文档 | 主要回答的问题 |
| ------------------------- | -------------------------------------------------- |
| `overview.md` | 这个项目整体是什么、做什么、核心目录和主链路是什么 |
| `runtime-architecture.md` | `main / preload / renderer` 如何协作 |
| `data-flow.md` | 核心业务数据如何在各层之间流动 |
| `file-map.md` | 关键文件在哪里、应该先看哪些入口 |
| `decision-log.md` | 最近几轮重要重构和架构决策是什么 |
## 按问题选择阅读路径

View File

@@ -66,13 +66,13 @@ flowchart TD
## 当前文档一览
| 文档 | 主要内容 |
| --- | --- |
| `local-development.md` | 环境准备、启动、构建、常用命令、本地验证 |
| `debugging.md` | 分层调试思路、调试入口、主链路定位方法 |
| 文档 | 主要内容 |
| ------------------------- | ---------------------------------------- |
| `local-development.md` | 环境准备、启动、构建、常用命令、本地验证 |
| `debugging.md` | 分层调试思路、调试入口、主链路定位方法 |
| `renderer-development.md` | React 渲染层开发方式、页面/hook/组件边界 |
| `ipc-development.md` | 新增或修改 IPC 能力的推荐实现路径 |
| `release-process.md` | 构建、发布、更新产物与上传流程 |
| `ipc-development.md` | 新增或修改 IPC 能力的推荐实现路径 |
| `release-process.md` | 构建、发布、更新产物与上传流程 |
## 与其他文档目录的关系

View File

@@ -59,14 +59,14 @@ graph TD
## 模块目录一览
| 模块 | 文档 | 核心职责 |
| --- | --- | --- |
| Auth | `auth.md` | 登录、silent login、管理员代切用户、用户上下文同步 |
| Extractor | `extractor.md` | 订单号输入、提取执行、日志与共享订单号同步 |
| 模块 | 文档 | 核心职责 |
| ---------- | --------------- | --------------------------------------------------------- |
| Auth | `auth.md` | 登录、silent login、管理员代切用户、用户上下文同步 |
| Extractor | `extractor.md` | 订单号输入、提取执行、日志与共享订单号同步 |
| Validation | `validation.md` | 共享 Production IDs、校验查询、结果富化、Cleaner 数据准备 |
| Cleaner | `cleaner.md` | 物料校验展示、删除计划保存、ERP 清理执行、报告展示 |
| Update | `update.md` | 更新目录、状态广播、下载、安装、用户/管理员更新视图 |
| Settings | `settings.md` | ERP 凭据加载与保存、当前用户配置管理 |
| Cleaner | `cleaner.md` | 物料校验展示、删除计划保存、ERP 清理执行、报告展示 |
| Update | `update.md` | 更新目录、状态广播、下载、安装、用户/管理员更新视图 |
| Settings | `settings.md` | ERP 凭据加载与保存、当前用户配置管理 |
## 模块入口地图