-
Notifications
You must be signed in to change notification settings - Fork 45
feat: add log RichHandler & RotatingFileHandler #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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 enhances the logging system by replacing basic file and stream handlers with more sophisticated alternatives - a RichHandler for console output with rich formatting and tracebacks, and a RotatingFileHandler for automatic log rotation to prevent excessive disk usage.
- Replaces standard StreamHandler with RichHandler for enhanced console output
- Replaces basic FileHandler with RotatingFileHandler for automatic log rotation
- Adds configurable log rotation parameters (max size and backup count)
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| if logger.handlers: | ||
| logger.handlers.clear() | ||
|
|
||
| if if_stream: | ||
| stream_handler = logging.StreamHandler() | ||
| stream_handler.setLevel(log_level) | ||
| stream_handler.setFormatter(formatter) | ||
|
|
||
| if not logger.handlers: | ||
| logger.addHandler(file_handler) | ||
| if if_stream and stream_handler: | ||
| logger.addHandler(stream_handler) | ||
| console = RichHandler(level=log_level, show_path=False, rich_tracebacks=True) | ||
| console.setFormatter(logging.Formatter("%(message)s")) | ||
| logger.addHandler(console) | ||
|
|
||
| file_handler = RotatingFileHandler( | ||
| log_file, | ||
| maxBytes=max_bytes, | ||
| backupCount=backup_count, | ||
| encoding="utf-8", | ||
| ) | ||
| file_handler.setFormatter( | ||
| logging.Formatter( | ||
| "[%(asctime)s] %(levelname)s [%(name)s:%(filename)s:%(lineno)d] %(message)s", | ||
| datefmt="%y-%m-%d %H:%M:%S", | ||
| ) | ||
| ) | ||
| logger.addHandler(file_handler) |
Copilot
AI
Sep 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The handlers are cleared on every call to set_logger(), which could cause issues if the function is called multiple times during application runtime. Consider checking if handlers are already configured or documenting that this function should only be called once during initialization.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
This PR enhances the logging system by replacing basic file and stream handlers with more sophisticated alternatives - a RichHandler for console output with rich formatting and tracebacks, and a RotatingFileHandler for automatic log rotation to prevent excessive disk usage.