Skip to content

Feat/log system update#10

Merged
Stewitch merged 4 commits intomainfrom
feat/log-system-update
Feb 10, 2026
Merged

Feat/log system update#10
Stewitch merged 4 commits intomainfrom
feat/log-system-update

Conversation

@Stewitch
Copy link
Copy Markdown
Collaborator

This pull request introduces several improvements to logging practices and code readability in the bot_sdk package, especially in the Zulip integration and documentation. The main changes include switching to structured logging using loguru, updating documentation examples to use the new logging approach, and reformatting code for better clarity and maintainability.

Logging improvements:

  • Switched from the standard logging module to loguru in bot_sdk/async_zulip.py, updating all logger usage accordingly.
  • Added structured logging for key events and incoming messages in the example bot code in both README.md and README.zh-CN.md, replacing print statements with self.logger.info and self.logger.debug. [1] [2] [3] [4]
  • Updated imports and exports in bot_sdk/__init__.py to include get_bot_logger from the new log module. [1] [2]

Documentation updates:

  • Improved documentation comments in the bot example classes, clarifying logger injection and structured logging recommendations in both English and Chinese documentation. [1] [2]

Code formatting and maintainability:

  • Reformatted argument groups and function calls for better readability and consistency, including breaking up long lines and grouping related arguments in bot_sdk/async_zulip.py. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @Stewitch, 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 significantly overhauls the logging infrastructure within the 'bot_sdk' package, transitioning to a more robust and developer-friendly 'loguru'-based system. The primary goal is to provide clearer, more organized log output for both the SDK's internal operations and individual bot instances. This change not only improves debugging and monitoring capabilities but also enhances code readability and maintainability across the codebase, particularly in the Zulip integration and bot examples.

Highlights

  • Structured Logging with Loguru: Implemented a new structured logging system using 'loguru', replacing the standard 'logging' module for enhanced clarity, performance, and maintainability across the SDK.
  • Separated System and Bot Logs: Introduced distinct logging mechanisms for system-level events and individual bot instances, enabling better log organization, filtering, and dedicated log files (e.g., 'logs/system.log' and 'logs/<bot_name>.log').
  • Injected Bot-Specific Loggers: Refactored 'BaseBot' and 'BotRunner' to automatically inject a 'loguru' logger instance into each bot, simplifying logging within bot implementations by allowing direct use of 'self.logger'.
  • Enhanced Console Integration: Improved the interactive console's logging display to provide a merged, color-coded view of system and bot logs, with clear tags indicating log origin and added scrolling capabilities.
  • Code Readability and Consistency: Applied extensive code reformatting, particularly in 'async_zulip.py' and command argument definitions, to improve readability and consistency throughout the codebase.
  • Documentation Updates: Updated English and Chinese documentation to reflect the new structured logging system, its configuration, usage examples, and console integration.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • .gitignore
    • Added 'logs/' directory to the ignore list.
  • README.md
    • Updated bot example to use 'self.logger' for structured logging and added comments about logger injection.
  • README.zh-CN.md
    • Updated Chinese bot example to use 'self.logger' for structured logging and added comments about logger injection.
  • bot_sdk/init.py
    • Switched logging import from 'bot_sdk.logging' to 'bot_sdk.log' and exposed 'get_bot_logger'.
  • bot_sdk/async_zulip.py
    • Replaced standard 'logging' with 'loguru', removed 'logging' import, and applied extensive code reformatting for improved readability.
  • bot_sdk/bot.py
    • Modified 'BaseBot' constructor to accept and store a 'loguru' logger instance, and updated all internal logging calls to use 'self.logger'.
  • bot_sdk/cli.py
    • Integrated the new logging system into the CLI, updated 'BotRunner' instantiation to pass logger details, and enhanced the console's log display.
  • bot_sdk/commands.py
    • Applied minor formatting adjustments to improve code consistency.
  • bot_sdk/config.py
    • Applied minor formatting adjustments.
  • bot_sdk/console.py
    • Refactored 'BotManager' and 'run_console' to fully support the new structured logging, including per-bot loggers and enhanced Rich console integration.
  • bot_sdk/db/cli.py
    • Applied minor formatting adjustments.
  • bot_sdk/db/database.py
    • Applied minor formatting adjustments.
  • bot_sdk/db/migrations/versions/0001_initial.py
    • Corrected a comment.
  • bot_sdk/i18n.py
    • Applied minor formatting adjustments.
  • bot_sdk/loader.py
    • Updated 'BotSpec' and '_bind_factory' to accommodate the new logger injection mechanism for bot factories.
  • bot_sdk/log.py
    • Added new module implementing the 'loguru'-based structured logging system, including 'setup_logging' for system logs and 'get_bot_logger' for bot-specific logs.
  • bot_sdk/logging.py
    • Removed old logging module.
  • bot_sdk/models/api/request.py
    • Applied minor formatting adjustments.
  • bot_sdk/models/api/types.py
    • Applied minor formatting adjustments.
  • bot_sdk/permissions.py
    • Applied minor formatting adjustments.
  • bot_sdk/runner.py
    • Updated 'BotRunner' to initialize and manage bot-specific loggers, passing them to bot factories, and updated internal logging calls.
  • bot_sdk/storage.py
    • Applied minor formatting adjustments.
  • bots/counter_bot/init.py
    • Updated bot to use 'self.logger' and adjusted 'create_bot' factory signature.
  • bots/echo_bot/init.py
    • Updated bot to use 'self.logger' and adjusted 'create_bot' factory signature.
  • docs/logging.md
    • Updated documentation to detail the new structured logging system, its configuration, and usage examples.
  • docs/zh/logging.md
    • Updated Chinese documentation to detail the new structured logging system, its configuration, and usage examples.
  • main.py
    • Ensured file ends with a newline.
  • pyproject.toml
    • Updated project version to '1.3.0' and added 'ruff' as a dependency.
  • setup.py
    • Updated project version to '1.3.0'.
  • uv.lock
    • Updated project version to '1.3.0' and added 'ruff' dependency.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request significantly improves the logging system by introducing structured, per-bot logging with loguru, which is a great enhancement for debuggability and monitoring. The dependency injection of a bot-specific logger into BaseBot is a solid design choice that will make bot development cleaner. The documentation updates are also clear and helpful.

I've found a couple of minor issues:

  • A potential AttributeError in the new bot_sdk/log.py due to an undefined name in __all__.
  • ruff, a development tool, has been added as a runtime dependency.

Overall, this is a very strong pull request that greatly improves the SDK's foundation. Well done!

Comment thread bot_sdk/log.py Outdated
Comment thread pyproject.toml Outdated
"ruamel-yaml>=0.19.1",
"rich>=14.2.0",
"prompt-toolkit>=3.0.52",
"ruff>=0.15.0",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

ruff is a linter and formatter, which is typically a development dependency, not a runtime dependency for an SDK. Including it in the main dependencies list will install it for all users of this SDK, which is likely not intended. It would be better to move it to a development dependency group, for example, under [project.optional-dependencies].

Stewitch and others added 2 commits February 10, 2026 11:44
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@Stewitch Stewitch merged commit a395345 into main Feb 10, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant