Skip to content

Conversation

@ChenZiHong-Gavin
Copy link
Collaborator

@ChenZiHong-Gavin ChenZiHong-Gavin commented Sep 29, 2025

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.

Copy link
Contributor

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 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.

Comment on lines 19 to 39
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)
Copy link

Copilot AI Sep 29, 2025

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.

Copilot uses AI. Check for mistakes.
ChenZiHong-Gavin and others added 2 commits September 29, 2025 15:01
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

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

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.

@ChenZiHong-Gavin ChenZiHong-Gavin merged commit 6d22862 into main Sep 29, 2025
2 checks passed
@ChenZiHong-Gavin ChenZiHong-Gavin deleted the rich-logger branch September 29, 2025 07:30
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.

2 participants