feat: implement structured logging system for commands and errors (#30)#58
Open
Saksham-official wants to merge 2 commits into
Open
feat: implement structured logging system for commands and errors (#30)#58Saksham-official wants to merge 2 commits into
Saksham-official wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a shared logging utility and wires command success/error logging into the Discord bot for prefix and slash command flows.
Changes:
- Adds
utils/logger.pywith shared logging setup and command usage formatting. - Replaces inline logging setup in
bot.pywith the new utility. - Adds prefix/slash command completion and error logging hooks.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
utils/logger.py |
Introduces centralized logging configuration and command usage logging helper. |
bot.py |
Integrates logging setup and command/app-command success/error event handlers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| async def setup_hook(self) -> None: | ||
| """Setup hook called before the bot starts.""" | ||
| # Initialize CodeBuddy database | ||
| self.tree.on_app_command_completion = self.on_app_command_completion |
| log_level_str = os.getenv("LOG_LEVEL", "INFO") | ||
| log_level = getattr(logging, log_level_str.upper(), logging.INFO) | ||
|
|
||
| file_handler = logging.FileHandler("bot.log", encoding="utf-8") |
Contributor
Author
|
Hello! I have updated the logging utility to address the Docker volume persistence feedback:
The branch has been updated and the changes compile cleanly. Ready for review and merge! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR addresses Issue #30 by introducing a structured, robust, and unified logging system. It enables comprehensive tracking of both legacy prefix commands and modern slash (app) commands along with their respective execution errors.
Proposed Changes
utils/logger.py):basicConfigusing a unified logging format:Timestamp - Logger Name - Level - Message.bot.log) with UTF-8 encoding (preventing encoding crashes from complex Discord usernames).log_command_usage()to format and print logs consistently.bot.py):on_command_completionandon_command_errorlisteners to track traditional prefix commands.on_app_command_completionandon_app_command_errorlisteners to track slash commands (registered via theCommandTreeduringsetup_hook).Format Example
Success Log:
Failure/Error Log:
How Has This Been Tested?
python -m py_compile.Closes #30