Skip to content

feat: implement structured logging system for commands and errors (#30)#58

Open
Saksham-official wants to merge 2 commits into
TheCodeVerseHub:mainfrom
Saksham-official:feature/logging-system
Open

feat: implement structured logging system for commands and errors (#30)#58
Saksham-official wants to merge 2 commits into
TheCodeVerseHub:mainfrom
Saksham-official:feature/logging-system

Conversation

@Saksham-official
Copy link
Copy Markdown
Contributor

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

  • Added Logging Utility (utils/logger.py):
    • Configures standard basicConfig using a unified logging format: Timestamp - Logger Name - Level - Message.
    • Implements output logging to both the standard console (stdout) and a localized file (bot.log) with UTF-8 encoding (preventing encoding crashes from complex Discord usernames).
    • Standardized usage via log_command_usage() to format and print logs consistently.
  • Main Bot Integration (bot.py):
    • Registered on_command_completion and on_command_error listeners to track traditional prefix commands.
    • Registered on_app_command_completion and on_app_command_error listeners to track slash commands (registered via the CommandTree during setup_hook).
    • Swapped out hardcoded basic logging configurations for the new global logging setup.

Format Example

Success Log:

2026-05-31 19:40:00,123 - EigenBot - INFO - [PREFIX] User: Saksham (123456789) | Command: helpmenu | Status: SUCCESS

Failure/Error Log:

2026-05-31 19:41:00,456 - EigenBot - ERROR - [SLASH] User: Saksham (123456789) | Command: ticket close | Status: FAILED (Forbidden: 403 Forbidden)

How Has This Been Tested?

  • Verified that changed python files compile cleanly and load without syntax or dependency errors using python -m py_compile.

Closes #30

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.py with shared logging setup and command usage formatting.
  • Replaces inline logging setup in bot.py with 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.

Comment thread bot.py
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
Comment thread utils/logger.py Outdated
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")
@Saksham-official
Copy link
Copy Markdown
Contributor Author

Hello! I have updated the logging utility to address the Docker volume persistence feedback:

  • Log Location Updated: bot.log has been moved inside the logs/ directory (os.makedirs("logs", exist_ok=True) and os.path.join("logs", "bot.log")).
  • Docker Mount Alignment: This ensures that log files are correctly persisted on the host machine through the ./logs:/app/logs volume mapping and won't be lost when rebuilding or restarting the Docker containers.

The branch has been updated and the changes compile cleanly. Ready for review and merge!

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.

[Feature]: Add logging system

2 participants