重构日志系统:使用 structlog 替代 loguru#1035
Conversation
备注
|
There was a problem hiding this comment.
Summary of Changes
Hello @BBleae, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request undertakes a significant refactoring of the application's logging system, migrating from loguru to structlog. This change aims to provide more robust structured logging and potentially better performance. Alongside the library swap, the PR standardizes logger imports and adjusts log level usage across numerous files. It also updates how global singleton instances are accessed.
Highlights
- Logging Library Migration: Replaced the
logurulogging library withstructlogto leverage its structured logging capabilities and improve performance. - Unified Logger Import: Standardized the logger import across the codebase, changing all instances from
src.common.logger_managertosrc.common.logger. - Log Level Renaming: Updated log level calls to align with standard logging practices, specifically changing
logger.successtologger.infoandlogger.warningtologger.warn. - Global Instance Access: Replaced direct access to global instances like
global_apiandglobal_serverwith calls to their respective getter functions (get_global_api(),get_global_server()) for better encapsulation and potential lazy initialization.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configureGemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This pull request successfully refactors the logging system from loguru to structlog, unifying logger imports and updating log level calls as described. The changes are extensive and touch many files, primarily involving import path updates and method name changes for logging.
Key observations:
- The core logging logic in
src/common/logger.pyhas been completely rewritten usingstructlog. The new implementation is simpler and sets a foundation for structured logging. However, it currently lacks features like file logging and the extensive custom console styling present in the previouslogurusetup. TODOs for these are noted in the new logger file. - A significant behavioral change was identified in
bot.pyconcerning the handling of a missing.envfile: it now logs a warning instead of raising an error. This needs clarification to ensure it aligns with application requirements. - The introduction of getter functions (
get_global_server(),get_global_api()) for global instances is a positive change, promoting better management of these singletons.
Overall, the PR achieves its main refactoring goal. The primary points for consideration are the implications of the simplified logging configuration (loss of custom styles, pending features like file logging) and the behavioral change in .env file handling.
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the logging system by replacing loguru with structlog, updating logger imports and log level calls for more structured logging and improved performance.
- Changed logger imports from src.common.logger_manager to src.common.logger
- Replaced logger.success calls with logger.info and logger.warning calls with logger.warn
- Updated global logger/server calls accordingly
Reviewed Changes
Copilot reviewed 132 out of 132 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/chat/focus_chat/heartFC_sender.py | Updated logger import and log level call in send_message; review logger initialization. |
| src/chat/focus_chat/heartFC_chat.py | Switched logger import to new module. |
| src/chat/focus_chat/heartFC_Cycleinfo.py | Changed logger import and maintained logger naming. |
| src/chat/focus_chat/expressors/*.py | Updated logger import in multiple expressor files. |
| src/chat/emoji_system/emoji_manager.py | Modified logging level calls and import replacement. |
| src/chat/command/command_handler.py | Updated logger import. |
| src/chat/actions/*.py | Refactored logger import across actions modules. |
| src/api/*.py | Replaced logger and global server imports. |
| scripts/*.py | Updated logger import across multiple scripts. |
| docs/plugin_quick_start.md | Changed logger import for documentation examples. |
| bot.py | Updated logger calls (e.g., logger.success to logger.info) and removed redundant load_env call. |
Comments suppressed due to low confidence (1)
src/chat/focus_chat/heartFC_sender.py:24
- The send_message function uses 'logger.info(...)' without initializing a logger instance in this file. Consider initializing a logger (e.g., by adding 'logger = get_logger("heartFC_sender")') so that logging calls work as expected.
await get_global_api().send_message(message)
|
@sourcery-ai review |
|
(generated by claude code) Code Review - Logger Refactoring✅ Review Summary: APPROVEDThis PR successfully refactors the logging system from loguru to structlog. The migration is well-executed and complete. What Was Reviewed:
Key Strengths:
Technical Details:The new src/common/logger.py provides:
Future Improvements (TODOs noted):
Recommendation: ✅ APPROVEThis refactoring improves the logging infrastructure while maintaining full functionality. The code is ready to merge. |
Summary
• 将日志系统从 loguru 重构为 structlog,提供更好的结构化日志支持和性能
• 统一所有文件中的日志导入,从
src.common.logger_manager改为src.common.logger• 更新日志级别调用,将
logger.success改为logger.info,logger.warning改为logger.warnTest plan
🤖 Generated with Claude Code