Skip to content

美化输出 #1075

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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

美化输出 #1075

wants to merge 12 commits into from

Conversation

Fuxuan-CN
Copy link

美化了日志输出,进度条输出,用rich库

Motivation

因为我觉得,这个输出,有点不好看

Modifications

az,不知道捏,总之就是log.py和main.py那里噢,还加了个自己写的exec_hook.py

@anka-afk anka-afk requested a review from Copilot March 31, 2025 15:00
Copy link
Contributor

@Copilot 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 aims to beautify log and progress output using the rich library and adds a custom exception hook to improve the readability of error traces. Key changes include:

  • Calling the custom exec_hook to set a beautified exception hook in main.py.
  • Updating file download progress with a rich progress bar in io.py.
  • Replacing colorlog-based formatting with RichHandler in log.py and adding detailed logging output.
  • Introducing a new exec_hook.py module to reformat exception stack traces using rich.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

File Description
main.py Added import and invocation of the exec_hook for enhanced error display.
astrbot/core/utils/io.py Replaced manual progress printing with a rich progress bar setup.
astrbot/core/log.py Migrated from colorlog to rich logging for improved log aesthetics and clarity.
astrbot/core/exec_hook.py Introduced a custom exception hook using rich components for better stack trace formatting.

datefmt="%H:%M:%S",
log_colors=log_color_config,
)
if cls._handler is None:
Copy link
Preview

Copilot AI Mar 31, 2025

Choose a reason for hiding this comment

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

The new RichHandler instance is configured but never added to the logger. Please add a line such as 'logger.addHandler(cls._handler)' after its configuration so that log messages are properly routed.

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

"""
sys.excepthook = sys_excepthook

def GetStackTrace(vokedepth: int = 1) -> str:
Copy link
Preview

Copilot AI Mar 31, 2025

Choose a reason for hiding this comment

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

The GetStackTrace function is annotated to return a str, but it actually returns a rich Text object. Consider updating the return type annotation or converting the Text to a string.

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

@anka-afk anka-afk requested a review from Copilot April 2, 2025 13:57
Copy link
Contributor

@Copilot 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 aims to beautify log and progress output by leveraging the rich library and improving exception formatting.

  • Update log output and exception handling by integrating a custom exec_hook module.
  • Enhance download progress display with a rich progress bar and improve type annotations in several modules.

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
main.py Added exec_hook initialization for beautified exception info.
dashboard/src/components/shared/ConsoleDisplayer.vue Updated console styling and log-level mapping with rich styles.
astrbot/core/zip_updator.py Replaced basic error messages with formatted ExtractException output.
astrbot/core/utils/io.py Introduced a rich progress bar and refined download retry logic.
astrbot/core/star/star_handler.py Updated type annotations for consistency.
astrbot/core/star/star.py Replaced List/Dict with native list/dict annotations.
astrbot/core/provider/func_tool_manager.py Improved type annotations and added inline documentation.
astrbot/core/log.py Switched from colorlog to rich logging with a custom theme.
astrbot/core/initial_loader.py Updated exception logging to use ExtractException for detailed info.
astrbot/core/exec_hook.py Added a new module to format and display exceptions using rich.
astrbot/core/core_lifecycle.py Updated exception handling to use ExtractException for better clarity.
Comments suppressed due to low confidence (1)

astrbot/core/utils/io.py:224

  • [nitpick] Consider replacing raw print statements with a logger (e.g., logger.info) for consistent production-level logging.
print(f"尝试下载管理面板文件(尝试 {i+1})")

# 获取当前调用栈信息的前两层
stack = traceback.extract_stack(limit=vokedepth)
stack_info = Text("Stack Trace:\n", style="bold")
for frame in stack[:-vokedepth+1]:
Copy link
Preview

Copilot AI Apr 2, 2025

Choose a reason for hiding this comment

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

When vokedepth is 1, this slice returns an empty list, potentially omitting useful stack trace information. Consider adjusting the slicing logic to ensure at least one stack frame is captured.

Suggested change
for frame in stack[:-vokedepth+1]:
if vokedepth == 1:
frames_to_include = stack[-1:]
else:
frames_to_include = stack[:-vokedepth+1]
for frame in frames_to_include:

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

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