NapNeko / NapCatQQ-Desktop

NapCatQQ的Desktop程序
GNU General Public License v3.0
75 stars 4 forks source link

♻️ refactor: 不再使用Loguru模块记录日志 #29

Closed HeartfeltJoy closed 1 week ago

HeartfeltJoy commented 1 week ago

Summary by Sourcery

通过移除 Loguru 模块并实现自定义记录器来重构日志系统。添加 CONTRIBUTING.md 文件以指导贡献者遵循项目标准。

增强功能:

文档:

Original summary in English ## Summary by Sourcery Refactor the logging system by removing the Loguru module and implementing a custom logger. Add a CONTRIBUTING.md file to guide contributors on project standards. Enhancements: - Refactor the logging system by removing the Loguru module and implementing a custom logger. Documentation: - Add a CONTRIBUTING.md file to guide contributors on naming conventions, file structure, code formatting, documentation, and version control.

增强功能:

文档:

Original summary in English ## Summary by Sourcery 通过移除 Loguru 模块并实现自定义记录器来重构日志系统。添加 CONTRIBUTING.md 文件以指导贡献者遵循项目标准。 增强功能: - 通过移除 Loguru 模块并实现自定义记录器来重构日志系统。 文档: - 添加 CONTRIBUTING.md 文件以指导贡献者关于命名约定、文件结构、代码格式、文档和版本控制。
Original summary in English ## Summary by Sourcery Refactor the logging system by removing the Loguru module and implementing a custom logger. Add a CONTRIBUTING.md file to guide contributors on project standards. Enhancements: - Refactor the logging system by removing the Loguru module and implementing a custom logger. Documentation: - Add a CONTRIBUTING.md file to guide contributors on naming conventions, file structure, code formatting, documentation, and version control.

增强功能:

文档:

Original summary in English ## Summary by Sourcery 通过移除 Loguru 模块并实现自定义记录器来重构日志系统。添加 CONTRIBUTING.md 文件以指导贡献者遵循项目标准。 增强功能: - 通过移除 Loguru 模块并实现自定义记录器来重构日志系统。 文档: - 添加 CONTRIBUTING.md 文件以指导贡献者关于命名约定、文件结构、代码格式、文档和版本控制。
Original summary in English ## Summary by Sourcery Refactor the logging system by removing the Loguru module and implementing a custom logger. Add a CONTRIBUTING.md file to guide contributors on project standards. Enhancements: - Refactor the logging system by removing the Loguru module and implementing a custom logger. Documentation: - Add a CONTRIBUTING.md file to guide contributors on naming conventions, file structure, code formatting, documentation, and version control.
增强功能: - 通过移除 Loguru 模块并实现自定义记录器来重构日志系统。 文档: - 添加一个 CONTRIBUTING.md 文件,以指导贡献者关于命名约定、文件结构、代码格式、文档和版本控制。
Original summary in English ## Summary by Sourcery 通过移除 Loguru 模块并实现自定义记录器来重构日志系统。添加 CONTRIBUTING.md 文件以指导贡献者遵循项目标准。 增强功能: - 通过移除 Loguru 模块并实现自定义记录器来重构日志系统。 文档: - 添加 CONTRIBUTING.md 文件以指导贡献者关于命名约定、文件结构、代码格式、文档和版本控制。
Original summary in English ## Summary by Sourcery Refactor the logging system by removing the Loguru module and implementing a custom logger. Add a CONTRIBUTING.md file to guide contributors on project standards. Enhancements: - Refactor the logging system by removing the Loguru module and implementing a custom logger. Documentation: - Add a CONTRIBUTING.md file to guide contributors on naming conventions, file structure, code formatting, documentation, and version control.

Summary by Sourcery

通过移除 Loguru 模块并实现自定义记录器来重构日志系统。添加 CONTRIBUTING.md 文件以指导贡献者遵循项目标准。

增强功能:

文档:

Original summary in English ## Summary by Sourcery Refactor the logging system by removing the Loguru module and implementing a custom logger. Add a CONTRIBUTING.md file to guide contributors on project standards. Enhancements: - Refactor the logging system by removing the Loguru module and implementing a custom logger. Documentation: - Add a CONTRIBUTING.md file to guide contributors on naming conventions, file structure, code formatting, documentation, and version control.
sourcery-ai[bot] commented 1 week ago

审核指南由 Sourcery 提供

此拉取请求通过移除 Loguru 模块并实现自定义日志记录器来重构日志系统。更改包括创建一个新的日志记录模块,具有更好的结构化日志记录功能,并添加一个 CONTRIBUTING.md 文件以建立项目标准。该实现的重点是使日志系统更易于维护和一致,同时减少外部依赖。

新日志记录器实现的类图

classDiagram
    class Logger {
        -log_buffer: list[Log]
        -log_buffer_size: int
        -log_buffer_delete_size: int
        +__init__()
        +load_config()
        +createLogFile()
        +clearBuffer()
        +debug(message: str, log_type: LogType, log_source: LogSource, log_position: LogPosition, log_group: LogGroup)
        +info(message: str, log_type: LogType, log_source: LogSource, log_position: LogPosition, log_group: LogGroup)
        +warning(message: str, log_type: LogType, log_source: LogSource, log_position: LogPosition, log_group: LogGroup)
        +error(message: str, log_type: LogType, log_source: LogSource, log_position: LogPosition, log_group: LogGroup)
        +group(name: str, log_type: LogType, log_source: LogSource)
    }

    class Log {
        +level: LogLevel
        +message: str
        +time: int | float
        +log_type: LogType
        +source: LogSource
        +position: LogPosition
        +toString()
    }

    class LogGroup {
        +name: str
        +log_type: LogType
        +log_source: LogSource
        +add(log: Log)
        +toString()
    }

    class LogPosition {
        +module: str
        +file: str
        +line: int
    }

    class LogLevel {
        <<enumeration>>
        DBUG
        INFO
        WARN
        EROR
        CRIT
        ALL_
    }

    class LogType {
        <<enumeration>>
        FILE_FUNC
        NETWORK
        NONE_TYPE
    }

    class LogSource {
        <<enumeration>>
        UI
        CORE
        NONE
    }

    Logger --> Log
    Logger --> LogGroup
    Log --> LogPosition
    LogLevel --> Log
    LogType --> Log
    LogSource --> Log

PathFunc 更改的类图

classDiagram
    class PathFunc {
        +qq_path: Path
        +base_path: Path
        +napcat_path: Path
        +config_dir_path: Path
        +tmp_path: Path
        +config_path: Path
        +bot_config_path: Path
        +path_validator()
        +get_qq_path() Path | None
    }

文件级更改

更改 详情 文件
实现了自定义日志系统以替换 Loguru
  • 创建了新的日志记录模块,使用 LogLevel、LogType 和 LogSource 枚举进行更好的日志分类
  • 实现了 LogPosition 和 LogGroup 类以进行结构化日志记录
  • 添加了具有可配置保留期的日志文件轮换
  • 实现了日志缓冲和自动清理
  • 添加了用于分组日志记录的上下文管理器
src/Core/Utils/logger/log_func.py
src/Core/Utils/logger/log_data.py
src/Core/Utils/logger/log_enum.py
src/Core/Utils/logger/log_utils.py
src/Core/Utils/logger/__init__.py
重构了整个应用程序的日志调用
  • 移除了 Loguru 导入和依赖
  • 更新了日志调用以使用新的自定义日志记录器
  • 简化了错误处理和日志记录模式
  • 移除了冗余的日志语句
src/Core/NetworkFunc/Downloader.py
src/Core/Utils/PathFunc.py
src/Core/Utils/GetVersion.py
src/Core/Utils/InstallFunc.py
src/Ui/MainWindow/Window.py
src/Ui/MainWindow/TitleBar.py
main.py
添加了项目贡献指南
  • 创建了模块、类和函数的全面命名约定
  • 定义了项目文件结构标准
  • 建立了代码格式化规则
  • 添加了文档和版本控制指南
.github/CONTRIBUTING.md
从设置页面移除了日志查看功能
  • 移除了日志文件查看小部件和相关代码
  • 简化了设置页面初始化
  • 移除了未使用的导入和变量
src/Ui/SetupPage/Setup.py

可能相关的问题


提示和命令 #### 与 Sourcery 互动 - **触发新审核:** 在拉取请求中评论 `@sourcery-ai review`。 - **继续讨论:** 直接回复 Sourcery 的审核评论。 - **从审核评论生成 GitHub 问题:** 通过回复审核评论请求 Sourcery 创建问题。 - **生成拉取请求标题:** 在拉取请求标题的任何地方写 `@sourcery-ai` 以随时生成标题。 - **生成拉取请求摘要:** 在拉取请求正文的任何地方写 `@sourcery-ai summary` 以随时生成 PR 摘要。您也可以使用此命令指定摘要应插入的位置。 #### 自定义您的体验 访问您的[仪表板](https://app.sourcery.ai)以: - 启用或禁用审核功能,例如 Sourcery 生成的拉取请求摘要、审核指南等。 - 更改审核语言。 - 添加、删除或编辑自定义审核说明。 - 调整其他审核设置。 #### 获取帮助 - [联系我们的支持团队](mailto:support@sourcery.ai)以获取问题或反馈。 - 访问我们的[文档](https://docs.sourcery.ai)以获取详细指南和信息。 - 通过关注我们在 [X/Twitter](https://x.com/SourceryAI)、[LinkedIn](https://www.linkedin.com/company/sourcery-ai/) 或 [GitHub](https://github.com/sourcery-ai) 上的 Sourcery 团队保持联系。
Original review guide in English ## Reviewer's Guide by Sourcery This pull request refactors the logging system by removing the Loguru module and implementing a custom logger. The changes include creating a new logger module with better structured logging capabilities and adding a CONTRIBUTING.md file to establish project standards. The implementation focuses on making the logging system more maintainable and consistent while reducing external dependencies. #### Class diagram for the new Logger implementation ```mermaid classDiagram class Logger { -log_buffer: list[Log] -log_buffer_size: int -log_buffer_delete_size: int +__init__() +load_config() +createLogFile() +clearBuffer() +debug(message: str, log_type: LogType, log_source: LogSource, log_position: LogPosition, log_group: LogGroup) +info(message: str, log_type: LogType, log_source: LogSource, log_position: LogPosition, log_group: LogGroup) +warning(message: str, log_type: LogType, log_source: LogSource, log_position: LogPosition, log_group: LogGroup) +error(message: str, log_type: LogType, log_source: LogSource, log_position: LogPosition, log_group: LogGroup) +group(name: str, log_type: LogType, log_source: LogSource) } class Log { +level: LogLevel +message: str +time: int | float +log_type: LogType +source: LogSource +position: LogPosition +toString() } class LogGroup { +name: str +log_type: LogType +log_source: LogSource +add(log: Log) +toString() } class LogPosition { +module: str +file: str +line: int } class LogLevel { <> DBUG INFO WARN EROR CRIT ALL_ } class LogType { <> FILE_FUNC NETWORK NONE_TYPE } class LogSource { <> UI CORE NONE } Logger --> Log Logger --> LogGroup Log --> LogPosition LogLevel --> Log LogType --> Log LogSource --> Log ``` #### Class diagram for PathFunc changes ```mermaid classDiagram class PathFunc { +qq_path: Path +base_path: Path +napcat_path: Path +config_dir_path: Path +tmp_path: Path +config_path: Path +bot_config_path: Path +path_validator() +get_qq_path() Path | None } ``` ### File-Level Changes | Change | Details | Files | | ------ | ------- | ----- | | Implemented a custom logging system to replace Loguru |
  • Created new logger module with LogLevel, LogType, and LogSource enums for better log categorization
  • Implemented LogPosition and LogGroup classes for structured logging
  • Added log file rotation with configurable retention period
  • Implemented log buffering with automatic cleanup
  • Added context manager for grouped logging
| `src/Core/Utils/logger/log_func.py`
`src/Core/Utils/logger/log_data.py`
`src/Core/Utils/logger/log_enum.py`
`src/Core/Utils/logger/log_utils.py`
`src/Core/Utils/logger/__init__.py` | | Refactored logging calls throughout the application |
  • Removed Loguru imports and dependencies
  • Updated logging calls to use the new custom logger
  • Simplified error handling and logging patterns
  • Removed redundant logging statements
| `src/Core/NetworkFunc/Downloader.py`
`src/Core/Utils/PathFunc.py`
`src/Core/Utils/GetVersion.py`
`src/Core/Utils/InstallFunc.py`
`src/Ui/MainWindow/Window.py`
`src/Ui/MainWindow/TitleBar.py`
`main.py` | | Added project contribution guidelines |
  • Created comprehensive naming conventions for modules, classes, and functions
  • Defined project file structure standards
  • Established code formatting rules
  • Added documentation and version control guidelines
| `.github/CONTRIBUTING.md` | | Removed log viewing functionality from setup page |
  • Removed log file viewing widgets and related code
  • Simplified setup page initialization
  • Removed unused imports and variables
| `src/Ui/SetupPage/Setup.py` | ### Possibly linked issues - **#2**: The PR addresses the roadmap task of removing the Loguru module for logging. ---
Tips and commands #### Interacting with Sourcery - **Trigger a new review:** Comment `@sourcery-ai review` on the pull request. - **Continue discussions:** Reply directly to Sourcery's review comments. - **Generate a GitHub issue from a review comment:** Ask Sourcery to create an issue from a review comment by replying to it. - **Generate a pull request title:** Write `@sourcery-ai` anywhere in the pull request title to generate a title at any time. - **Generate a pull request summary:** Write `@sourcery-ai summary` anywhere in the pull request body to generate a PR summary at any time. You can also use this command to specify where the summary should be inserted. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) to: - Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others. - Change the review language. - Add, remove or edit custom review instructions. - Adjust other review settings. #### Getting Help - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).
HeartfeltJoy commented 1 week ago

@sourcery-ai review

HeartfeltJoy commented 1 week ago

@sourcery-ai review

sonarcloud[bot] commented 1 week ago

Quality Gate Passed Quality Gate passed

Issues
10 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.5% Duplication on New Code

See analysis details on SonarQube Cloud

HeartfeltJoy commented 1 week ago

@sourcery-ai summary

sourcery-ai[bot] commented 1 week ago

I'm sorry, I don't understand the command @sourcery-ai summary.

Please use @sourcery-ai review to request a review.

HeartfeltJoy commented 1 week ago

@sourcery-ai

HeartfeltJoy commented 1 week ago

@sourcery-ai review