Skip to content

Conversation

@wdfk-prog
Copy link
Contributor

拉取/合并请求描述:(PR description)

[

为什么提交这份PR (why to submit this PR)

  • 当前 ulog 组件在处理超长日志时,如果日志内容的长度超过了 ULOG_LINE_BUF_SIZE 定义的行缓冲区大小,会直接进行截断处理,而不会给开发者任何提示。这种“静默失败”的行为可能会导致调试信息不完整,开发者难以发现问题所在,从而影响开发效率。

你的解决方案是什么 (what is your solution)

  1. 新增了一个静态函数 ulog_no_enough_buffer_printf()。
  2. 该函数内部使用一个静态布尔变量来确保在系统的整个生命周期中,缓冲区不足的告警信息只会打印一次,有效避免了因连续输出超长日志而导致的控制台刷屏问题。
  3. 在标准日志格式化函数 ulog_formater 和十六进制打印函数 ulog_hex_formater 的截断逻辑处,调用此函数。当日志首次因超长被截断时,会打印如下告警:
    Warning: There is not enough buffer to output the log, please increase the ULOG_LINE_BUF_SIZE option.

这样,开发者就能明确地知道日志被截断了,并根据提示去调整配置。

请提供验证的bsp和config (provide the config and bsp)

  • BSP: 此修改为通用功能增强,不涉及特定硬件。已通过构造超长日志字符串进行测试,验证了告警信息能够按预期正确打印,并且只打印一次。
  • .config:
  • action:

]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用formatting 等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/ALL_BSP_COMPILE.json 详细请参考链接BSP自查

@github-actions
Copy link

👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread!

为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。
To ensure your code complies with RT-Thread's coding style, please run the code formatting workflow by following the steps below (If the formatting of CI fails to run).


🛠 操作步骤 | Steps

  1. 前往 Actions 页面 | Go to the Actions page
    点击进入工作流 → | Click to open workflow →

  2. 点击 Run workflow | Click Run workflow

  • 设置需排除的文件/目录(目录请以"/"结尾)
    Set files/directories to exclude (directories should end with "/")
  • 将目标分支设置为 \ Set the target branch to:ulog_buffer
  • 设置PR number为 \ Set the PR number to:10948
  1. 等待工作流完成 | Wait for the workflow to complete
    格式化后的代码将自动推送至你的分支。
    The formatted code will be automatically pushed to your branch.

完成后,提交将自动更新至 ulog_buffer 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the ulog_buffer branch automatically, and the related Pull Request will be updated.

如有问题欢迎联系我们,再次感谢您的贡献!💐
If you have any questions, feel free to reach out. Thanks again for your contribution!

@github-actions
Copy link

📌 Code Review Assignment

🏷️ Tag: components

Reviewers: @Maihuanyi

Changed Files (Click to expand)
  • components/utilities/ulog/ulog.c

📊 Current Review Status (Last Updated: 2025-11-17 17:02 CST)


📝 Review Instructions

  1. 维护者可以通过单击此处来刷新审查状态: 🔄 刷新状态
    Maintainers can refresh the review status by clicking here: 🔄 Refresh Status

  2. 确认审核通过后评论 LGTM/lgtm
    Comment LGTM/lgtm after confirming approval

  3. PR合并前需至少一位维护者确认
    PR must be confirmed by at least one maintainer before merging

ℹ️ 刷新CI状态操作需要具备仓库写入权限。
ℹ️ Refresh CI status operation requires repository Write permission.

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 adds a one-time warning mechanism to the ulog component to alert developers when log content exceeds the ULOG_LINE_BUF_SIZE buffer capacity. Currently, ulog silently truncates oversized logs, which can lead to incomplete debugging information.

Key Changes:

  • Introduces a new static function ulog_no_enough_buffer_printf() that prints a warning message only once using a static boolean flag
  • Integrates the warning function into both ulog_formater and ulog_hex_formater where log truncation occurs
  • Follows existing code patterns found elsewhere in the file (similar pattern at lines 606-612)

Comment on lines +429 to +430
rt_kprintf("Warning: There is not enough buffer to output the log,"
" please increase the ULOG_LINE_BUF_SIZE option.\n");
Copy link

Copilot AI Nov 17, 2025

Choose a reason for hiding this comment

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

[nitpick] [Spelling/拼写]: Minor wording improvement suggested for better English clarity.

English: While grammatically correct, "There is not enough buffer" is slightly awkward. It would be more natural to say "There is not enough buffer space" or "The buffer is not large enough". This would also make it more consistent and clear.

Note: This is better than the existing code at line 609 which uses "There is no enough buffer" (grammatically incorrect). Consider updating both messages together.

中文:虽然语法正确,但 "There is not enough buffer" 的表达略显不自然。建议改为 "There is not enough buffer space" 或 "The buffer is not large enough",这样会更加清晰自然。

注意:这已经比现有代码第 609 行的 "There is no enough buffer"(语法错误)要好。建议一起更新两处信息。

Suggested correction/建议修正:

rt_kprintf("Warning: There is not enough buffer space to output the log, "
        "please increase the ULOG_LINE_BUF_SIZE option.\n");
Suggested change
rt_kprintf("Warning: There is not enough buffer to output the log,"
" please increase the ULOG_LINE_BUF_SIZE option.\n");
rt_kprintf("Warning: There is not enough buffer space to output the log, "
"please increase the ULOG_LINE_BUF_SIZE option.\n");

Copilot uses AI. Check for mistakes.
@meng-plus
Copy link
Contributor

LGTM

@Rbb666 Rbb666 merged commit e1f609f into RT-Thread:master Nov 18, 2025
62 checks passed
@wdfk-prog wdfk-prog deleted the ulog_buffer branch November 18, 2025 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants