Skip to content

[components][ulog] support output the calling function, file and line - #11987

Open
ymj0440 wants to merge 8 commits into
RT-Thread:masterfrom
ymj0440:fix-ulog-output-file-line
Open

ymj0440 wants to merge 8 commits into
RT-Thread:masterfrom
ymj0440:fix-ulog-output-file-line

Conversation

@ymj0440

@ymj0440 ymj0440 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Description

This PR implements the feature requested in #7724: support outputting the calling function name, file name and line number in ulog.

Three independent switches are introduced so that users can freely decide which context information to output, avoiding overly long log lines:

  • ULOG_USING_OUTPUT_FILE: prepend the calling file name
  • ULOG_USING_OUTPUT_FUNC: prepend the calling function name
  • ULOG_USING_OUTPUT_LINE: prepend the calling line number

When all switches are disabled (the default), the output is completely unchanged, so existing behavior is preserved.

Example output with all switches enabled:

[main.c:42] app_entry(): this is a debug log!

How to test

Enable the switches in menuconfig (RT-Thread Kernel -> Enable ulog) or define them in rtconfig.h, then use the LOG_D/LOG_I/LOG_W/LOG_E APIs as usual.

Notes

  • The existing ulog APIs (ulog_output, ulog_e/i/w/d) are kept unchanged for backward compatibility. The new function ulog_output_ctx() is only used by the LOG_X macros.
  • Verified with gcc -fsyntax-only under three configurations (all switches off / all on / only function name) and checked the macro expansion contains the expected __FILE__ / __FUNCTION__ / __LINE__ values.

Fixes #7724

Add three independent switches (ULOG_USING_OUTPUT_FILE/FUNC/LINE) so that
users can freely decide whether to prepend the calling file name, function
name or line number to the log message when using the LOG_X API. These
switches are disabled by default, keeping the output unchanged.

Signed-off-by: ymj0440 <ymj0440@users.noreply.github.com>
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

👋 感谢您对 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

  • Use workflow from 保持默认分支(通常为 master)
    Keep the default branch (usually master) in Use workflow from
  • 在 branch 输入框填写 PR 分支 fix-ulog-output-file-line
    Enter PR branch fix-ulog-output-file-line in the branch field
  • 设置需排除的文件/目录(目录请以"/"结尾)
    Set files/directories to exclude (directories should end with "/")
  1. 等待工作流完成 | Wait for the workflow to complete
    格式化后的代码将作为独立提交推送至你的分支。
    The formatting changes will be pushed to your branch as a separate commit.

完成后,提交将自动更新至 fix-ulog-output-file-line 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the fix-ulog-output-file-line 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

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

📌 Code Review Assignment

🏷️ Tag: components

Reviewers: @Maihuanyi

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

📊 Current Review Status (Last Updated: 2026-11-13 10:57 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.

@Rbb666

Rbb666 commented Nov 5, 2026

Copy link
Copy Markdown
Member

三个独立开关符合 #7724 的需求,不过当前实现还有三处问题需要修正。以下基于提交 8aa4a23e。

  1. 原有的静态日志级别过滤失效了。 ulog.h:70–73 将 LOG_E/W/I/D 直接改为调用 ulog_output_ctx(),绕过了 ulog_e/w/i/d 中对 LOG_LVL 和 ULOG_OUTPUT_LVL 的判断。两个级别都设为 ERROR 时,原来的 LOG_D("value=%d", expensive_side_effect()) 会被预处理掉,这版仍会调用函数并求值参数。三个新开关全部关闭时也一样,和描述中的“默认行为不变”不符。这里需要保留原有的条件编译,全关时建议直接走原来的调用路径。

  2. 格式字符串被提前截断,会丢掉本来能放下的日志。 ulog.c:864–868 先把原始格式串复制到 fmt[ULOG_LINE_BUF_SIZE],再展开参数。但格式串可能比输出结果长。例如缓冲区为 128 字节,格式串由 30 个 %02x 组成,传入 1 到 30:模板长 150 字符,输出只有 90 字符。原版能完整输出,这版在三个开关全关时只剩前 25 个值,末尾还多出一个 %。应该截断格式化后的结果,不能先截断格式串。

  3. 文件名里的百分号会被当成格式指令。 ulog.c:864、874 把上下文直接拼进 fmt,随后又交给格式器解析。源码路径允许包含 %。用 file="dir%u/test.c"、format="value=%u"、参数 11, 22 验证,实际得到的是 [dir11/test.c] value=22,文件名吃掉了正文的参数。如果只传正文所需的一个参数,就会读取不存在的变参;路径里出现 %s 时还可能错误解引用。上下文应作为普通文本写入缓冲区,正文继续使用完整的原始格式串。

第一项用 GCC 预处理验证过;后两项用该提交的 ulog_output_ctx() 和同版本 tiny 格式器做了最小运行验证。建议补上这些回归用例,再确认默认配置和各开关组合的行为。

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

at32f415-start

  • ROM: .text +80 B (+0.1%, 65,524 B / 262,144 B, total: 25% used)

esp32-c3

  • dram0_0_seg: .dram0.data +36 B, .dram0.dummy +8,192 B, .stack +4 B (+3.9%, 216,832 B / 325,120 B, total: 67% used)
  • iram0_0_seg: .iram0.text +8,008 B, .iram0.text_end +184 B (+15.4%, 61,440 B / 325,120 B, total: 19% used)
  • iram0_2_seg: .flash.text +128 B (-1.9%, 421,880 B / 8,388,576 B, total: 5% used)

gd32105r-start

  • CODE: .text +80 B (+0.1%, 69,436 B / 262,144 B, total: 26% used)

hc32f334

  • FLASH: .text +80 B (+0.1%, 99,692 B / 131,072 B, total: 76% used)

hpmicro-hpm5100evk

  • ILM: .fast +32 B (+0.1%, 42,672 B / 262,144 B, total: 16% used)
  • XPI0: .fast +32 B, .text +24 B (+0.1%, 102,980 B / 1,048,576 B, total: 10% used)

hpmicro-hpm5301evklite

  • ILM: .fast +16 B (+0.1%, 23,728 B / 131,072 B, total: 18% used)
  • XPI0: .fast +16 B, .text +24 B (+0.1%, 76,788 B / 1,048,576 B, total: 7% used)

infineon-psoc6

  • flash: .text +80 B (+0.1%, 116,292 B / 262,144 B, total: 44% used)

k230

  • SRAM: .bss +61,608 B, .data +1,096 B, .eh_frame +22,712 B, .sbss +44 B, .srodata.cst8 +24 B, .stack -8 B, .text +99,872 B (+15.4%, 1,391,440 B / 60,682,240 B, total: 2% used)

loongson-ls1cdev

  • Code: .text +540 B (+0.1%, 363,948 B)

nordic-nrf51822

  • FLASH: .text +72 B (+0.1%, 52,128 B / 262,144 B, total: 20% used)

nuvoton-m487

  • CODE: .text +332 B (+0.1%, 356,912 B / 524,288 B, total: 68% used)

qemu-virt64-aarch64

  • Code: .eh_frame +112 B, .text +2,048 B (+0.2%, 1,011,196 B)
  • Data: .bss +16 B (+0.0%, 1,068,120 B)

raspberry-pico-rp2040

  • FLASH: .rodata +40 B, .text +40 B (+0.1%, 114,272 B / 2,097,152 B, total: 5% used)

renesas-ra2l1

  • FLASH: .text +188 B (+0.2%, 98,492 B / 262,144 B, total: 38% used)

simulator

  • Code: .rela.dyn +1,728 B, .rodata +224 B, .text +1,644 B (+0.1%, 2,676,654 B)
  • Data: .data +1,824 B (+0.1%, 1,610,852 B)

stm32f407-rt-spark

  • CODE: .text +80 B (+0.1%, 86,168 B / 1,048,576 B, total: 8% used)

stm32l475-atk-pandora-llvm

  • ROM: .text +92 B (+0.1%, 82,804 B / 524,288 B, total: 16% used)

wch-ch32v208w-r0

  • FLASH: .text +296 B (+0.2%, 159,976 B / 491,520 B, total: 33% used)

x86

  • Code: .rodata +32 B, .text +304 B (+0.2%, 199,277 B)

xuantie-e901plus

  • ISRAM: .rodata +48 B, .text +16 B (+0.1%, 46,488 B / 131,072 B, total: 35% used)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@Rbb666 Rbb666 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

复核提交 8aa4a23eac3833c8846801218df75f1da69414ea,此前评论中的三个问题仍存在,请修复后再合并。

  1. [P1] 保留原有静态日志级别过滤。 ulog.h 第 70–73 行 直接调用 ulog_output_ctx(),绕过 ulog_e/w/i/d 对 LOG_LVL 和 ULOG_OUTPUT_LVL 的条件编译。即使三个新开关全部关闭,被过滤日志的参数仍会求值。已核对 Nuvoton CI 失败日志:M460 驱动原本被 ERROR 级别过滤掉的 LOG_I 现在参与编译,暴露 nu_usbd.address_tmp 未声明错误。请修复宏的过滤行为,而不是仅修改该驱动以绕过这次失败。

  2. [P1] 上下文必须作为普通文本处理。 ulog.c 第 864–874 行 将文件名等上下文拼入格式串,随后再次解析。源文件路径含百分号时会消耗正文的变参:使用 file="dir%u/test.c"、正文 "value=%u"、参数 11, 22,实际得到 [dir11/test.c] value=22。只有一个正文参数时会读取不存在的变参,路径含 %s 时还可能错误解引用。请直接写入上下文文本,正文保持使用原始格式串。

  3. [P2] 不要在展开参数前截断格式串。 新增的 fmt[ULOG_LINE_BUF_SIZE] 先截断模板,会丢失原本能完整输出的数据。例如 30 个 %02x 的模板长 150 字符,但展开 1–30 后只有 90 字符,原本能放入 128 字节缓冲区;当前实现提前截断模板,输出不完整,并可能留下残缺格式指令。请限制最终输出长度,而非原始模板长度。

本轮使用提取的当前函数和主机格式器复核了参数副作用、百分号路径及长模板问题。请补充新开关全关、各开关组合、静态级别过滤及上述格式化场景的回归验证。

另请将标题和提交信息改为仓库要求的方括号前缀,例如 [ulog] 支持输出调用文件、函数和行号;验证说明应通过 menuconfig/pyconfig 生成 BSP 的 rtconfig.h,不要建议手工修改。

@BernardXiong BernardXiong left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

结论:暂不建议合并,前两项为阻塞问题。

1. [P1] 静态日志级别过滤被绕过 / Static level filtering bypassed

ulog.h#L70-L73

LOG_E/W/I/D 直接调用 ulog_output_ctx(),绕过了 ulog_def.h 中 ulog_e/w/i/d 的 (LOG_LVL >= ...) && (ULOG_OUTPUT_LVL >= ...) 条件编译。即使三个新开关全部关闭,被过滤日志的参数仍会被编译和求值,代码体积和运行时开销都会增加。

这也是 Nuvoton CI 失败 的直接原因:drv_usbd.c 定义了 DBG_LEVEL DBG_ERROR,第 442 行的 LOG_I 原本被过滤掉,现在参与编译,暴露了 nu_usbd 未声明。正确的修法是恢复宏的过滤逻辑,而不是去改该驱动掩盖问题。

2. [P1] 上下文被拼进格式串 / Context merged into the format string

ulog.c#L864

rt_snprintf(fmt, sizeof(fmt), "[%s] %s", ctx_buf, format) 会把 __FILE__ 等上下文再次当作 printf 格式串解析。若路径含 %,例如 file="dir%u/test.c"、正文 "value=%u"、参数 11, 22,实际输出 [dir11/test.c] value=22;路径含 %s 时还可能解引用错误指针。

建议把 [file:line func()] 作为普通文本直接写入输出缓冲(或给 ulog_voutput 增加上下文字段),正文继续使用原始 format。

3. [P2] 展开前截断模板 / Format template truncated before expansion

ulog.c#L836-L837

每次日志调用都在栈上分配两个 ULOG_LINE_BUF_SIZE 缓冲;模板在展开前就被截断,长模板会丢数据,甚至留下残缺的 %。三个开关全关时应直接回退到 ulog_output();开启时应限制最终输出长度,而不是原始模板。

4. [建议]

  • ulog.h#L59 使用 C99 的 __func__ 代替 GNU 扩展 __FUNCTION__。
  • 标题和提交信息建议按仓库约定加 [ulog] 前缀。

1. Keep the compile-time log level filtering. LOG_X still expands to
   ulog_e/w/i/d when all three switches are disabled, and the new
   ulog_x_ctx macros share the same LOG_LVL/ULOG_OUTPUT_LVL guard, so
   logs filtered out at compile time do not evaluate their arguments.
2. Format the message before truncation. The original format string is
   always used in full; only the formatted result is limited by
   ULOG_LINE_BUF_SIZE, so a long template with a short output is no
   longer cut.
3. Assemble "[context] message" as plain text and pass it to the
   formatter through an "%s" format, so '%' characters inside the file
   name or the message are never parsed as format specifiers.

Verified with gcc -fsyntax-only (all off / all on), macro expansion for
the level filtering case, and runtime cases for a long format template
and for '%' inside file names.

Signed-off-by: ymj0440 <ymj0440@users.noreply.github.com>
@ymj0440

ymj0440 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @Rbb666 for the careful review. All three issues are fixed in a2e8d01b:

  1. Static log level filtering: LOG_X now expands back to ulog_e/w/i/d when all three switches are disabled, and the new ulog_x_ctx macros are defined inside the same #if (LOG_LVL >= ...) && (ULOG_OUTPUT_LVL >= ...) guard as the original ones. Logs filtered out at compile time expand to nothing, so their arguments are not evaluated. Verified by preprocessing with LOG_LVL=3 and ULOG_OUTPUT_LVL=3: LOG_D(...) disappears, LOG_E(...) keeps using ulog_output().

  2. Format string truncated in advance: ulog_output_ctx() now formats the message first with rt_vsnprintf(body_buf, sizeof(body_buf), format, args). The format string is always used in full; only the formatted result is limited by ULOG_LINE_BUF_SIZE. Verified with a 30-specifier %02x template (format string ~150 chars, output ~90 chars): all 30 values are printed.

  3. Percent sign in the file name: the [context] message text is now assembled as plain text and passed to the formatter as an %s argument, so % inside the file name or the message is never parsed as a format specifier. Verified: file="dir%u/test.c", format="value=%u", arg 11 gives [dir%u/test.c:10 f()] value=11; file="dir%s/test.c", format="name=%s", arg "bob" gives [dir%s/test.c:10 f()] name=bob.

When all three switches are off, ulog_output_ctx() takes the original ulog_voutput() path directly, so the default output is byte-for-byte unchanged.

I also added the regression checks above as verification steps; if you prefer, I can turn them into a test case in the repository.

@BernardXiong

Copy link
Copy Markdown
Member

CI 的 Check File Format and License 在 head a2e8d01b 仍失败,属代码格式问题,不是环境或基础设施故障:

  • components/utilities/ulog/ulog.h:77-80:LOG_E/W/I/D 宏
  • components/utilities/ulog/ulog_def.h:74-105:ulog_d/i/w/e 及 *_ctx 宏

失败日志:https://github.com/RT-Thread/rt-thread/actions/runs/42181815149/job/127772930166
请用仓库锁定的 clang-format 22.1.8 处理这两个文件后重新推送;其余 CI 检查已通过。


The Check File Format and License job still fails on head a2e8d01b (code formatting, not infrastructure): clang-format violations in ulog.h:77-80 and ulog_def.h:74-105. See the job log above. Please run the repo-pinned clang-format 22.1.8 on both files and push again; the other checks pass.

Format the LOG_X and ulog_x_ctx macro definitions in ulog.h and
ulog_def.h with the repo-pinned clang-format 22.1.8, fixing the
'Check File Format and License' CI job.

Signed-off-by: ymj0440 <ymj0440@users.noreply.github.com>
@ymj0440

ymj0440 commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @BernardXiong. Both files are now formatted with the repo-pinned clang-format 22.1.8 (pip install -r tools/ci/requirements-format.txt) in 8fa52fc2; only the macro definitions touched by this PR changed.

Re-verified after formatting:

  • all switches on: LOG_D expands to ulog_output_ctx(<level>, LOG_TAG, __FILE__, __FUNCTION__, __LINE__, ...)
  • all switches off: LOG_D goes back to ulog_output(<level>, LOG_TAG, RT_TRUE, ...), and compile-time filtered levels still expand to nothing (arguments not evaluated)
  • gcc -fsyntax-only passes for both all-off and all-on configurations

@BernardXiong BernardXiong left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

复核 head 8fa52fc2:格式检查已通过,三个开关独立配置、关闭时保留原有静态日志级别过滤的设计也成立。发现一处边界问题:

[一般] ulog_output_ctx() 可能把未初始化的栈内容拼进日志

components/utilities/ulog/ulog.c:849-860 中:

n = rt_snprintf(ctx_buf + pos, sizeof(ctx_buf) - pos, "%s", file);
pos += (n > 0 && n < (int)(sizeof(ctx_buf) - pos)) ? n : (sizeof(ctx_buf) - pos - 1);

当 rt_snprintf() 返回 0(例如调用方传入空字符串 file)或负数时,pos 会被直接推到 sizeof(ctx_buf) - 1;随后 ulog.c:893 的 rt_memcpy(out_buf + 1, ctx_buf, pos) 会拷贝 ctx_buf 中未初始化的内容并输出。经 LOG_X 宏传入的 __FILE__ 不会为空,但 ulog_output_ctx() 是头文件中公开的 API,空字符串即可触发,属于潜在栈信息泄漏。

建议只在 n > 0 时推进 pos;n >= remaining 时取 remaining - 1,或先把 ctx_buf[0] = '\0' 初始化。

建议:ULOG_FUNC_INFO 使用 __FUNCTION__ 属于编译器扩展,可考虑改用标准 __func__ 以提升可移植性。


Reviewed head 8fa52fc2. Format checks now pass, and the independent-switch design (falling back to the original static level filtering when all three switches are off) is sound. One edge case:

[Medium] ulog_output_ctx() can copy uninitialized stack data into the log

At ulog.c:849-860, when rt_snprintf() returns 0 (e.g. an empty file string) or a negative value, pos is advanced to sizeof(ctx_buf) - 1; ulog.c:893 then copies pos bytes from the uninitialized ctx_buf into out_buf and emits it. The LOG_X macros never pass an empty __FILE__, but ulog_output_ctx() is a public API in ulog.h, so the empty-string case is reachable and can leak stack contents.

Suggested fix: only advance pos when n > 0 (use remaining - 1 when truncated), or initialize ctx_buf[0] = '\0' first.

Only advance `pos` when rt_snprintf() returns a positive value, so that
an empty file name or function name can no longer push `pos` to the end
of the buffer and make the following memcpy pick up uninitialized
stack bytes. Initialize ctx_buf[0] as well.

Also use the standard __func__ instead of the compiler extension
__FUNCTION__ for ULOG_FUNC_INFO, as suggested.

Verified: empty file -> pos stays 0; normal case -> 'main.c:42
app_entry()'; a 95-byte file name is truncated safely to the buffer.

Signed-off-by: ymj0440 <ymj0440@users.noreply.github.com>
@ymj0440

ymj0440 commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @BernardXiong for the careful review. Both points are addressed in 2820068a:

  1. [Medium] uninitialized stack data: pos is now advanced only when rt_snprintf() returns a positive value, and ctx_buf[0] is initialized to '\0'. An empty file/func therefore keeps pos == 0 and takes the no-context path (ulog_voutput() with the original format), so nothing uninitialized is ever copied. Verified: empty file -> pos == 0; file="main.c", line=42, func="app_entry" -> pos == 21, prefix [main.c:42 app_entry()]; a >127-byte file name is truncated to pos == 95, still inside the buffer.
  2. __FUNCTION__ -> __func__: ULOG_FUNC_INFO now uses the standard __func__.

The changed lines pass clang-format -style=file --dry-run --Werror with the repo-pinned 22.1.8.

@BernardXiong BernardXiong left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

复核 head 2820068a。 / Re-review at head 2820068a.

  • ulog_output_ctx() 现在把 ctx_buf[0] 初始化为 '\0',并且只在 rt_snprintf() 返回正值时推进 pos,不会再拼入未初始化的栈内容;
  • out_buf 的最大写入下标为 2 * ULOG_LINE_BUF_SIZE + 1,小于分配的 2 * ULOG_LINE_BUF_SIZE + 8,无溢出;
  • 组装好的消息以 "%s" 交给 ulog_output(),文件名或消息中的 % 不会被再次当作格式符解析;
  • 三个开关全部关闭时仍走原 ulog_x() 路径,静态日志级别过滤和“被过滤参数不求值”的语义保持不变。

格式 CI 已通过,CLA 已签,未发现阻塞问题。批准。 / CI passes, CLA is signed, no blocking issue found. Approved.

@Rbb666 Rbb666 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

复核提交 2820068:请先解决两条行内问题——调用线程栈占用过大,以及运行时过滤之前执行格式化。长文件路径前缀另列为非阻塞建议。

验证:八种上下文开关组合,分别检查正常输出、LOG_LVL 静态过滤和 ULOG_OUTPUT_LVL 静态过滤,共 24 项通过。边界行为使用提取的 PR 源码和实际 tiny formatter 在宿主复现;未进行板端或 QEMU 验证。

另有非阻塞规范建议:PR 标题和提交消息使用仓库要求的 [components][ulog] 前缀,常规修正提交可在合并前归并。

Reviewed commit 2820068. Please address the two inline issues: excessive caller stack usage and formatting before runtime filtering. The long file-path prefix is a separate non-blocking suggestion.

Validation: all eight context-switch combinations passed normal-output, LOG_LVL filtering, and ULOG_OUTPUT_LVL filtering checks (24 cases). Boundary behavior was reproduced on the host using extracted PR code and the actual tiny formatter; no hardware or QEMU validation was performed.

Non-blocking repository conventions: use the required [components][ulog] prefix for the PR title and commit messages, and consolidate routine follow-up fixes before merging.

Comment thread components/utilities/ulog/ulog.c Outdated
Comment on lines +836 to +838
char ctx_buf[ULOG_LINE_BUF_SIZE];
char body_buf[ULOG_LINE_BUF_SIZE];
char out_buf[2 * ULOG_LINE_BUF_SIZE + 8];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P1] 避免在调用线程栈上分配三个整行缓冲区 / Avoid allocating three line buffers on the caller's stack

中文:开启任一上下文选项后,LOG_X 会进入此函数。默认 ULOG_LINE_BUF_SIZE=128 时,这三个数组合计占用 520 字节,已经超过 src/Kconfig 中非 64 位目标默认的 512 字节软定时器线程栈,尚未计入局部变量、调用者和后续格式化/后端调用。在软定时器回调中记录日志会因此产生栈溢出风险。提取当前提交代码进行宿主 GCC -m32 -O2 -fstack-usage 检查时,此函数自身栈帧为 624 字节;这是宿主编译结果,并非板端实测。建议把上下文拼接合入持锁后的现有日志缓冲区,避免让每个调用线程增加 4 * ULOG_LINE_BUF_SIZE + 8 的临时数组开销。

English: Enabling any context option routes LOG_X through this function. With the default ULOG_LINE_BUF_SIZE=128, these arrays alone occupy 520 bytes, exceeding the default 512-byte soft-timer thread stack on non-64-bit targets, before accounting for callers and formatting/backend calls. Logging from a soft-timer callback can therefore overflow its stack. A host GCC -m32 -O2 -fstack-usage build of the extracted code reports a 624-byte frame for this function; this is not an on-target measurement. Please append context directly to the existing protected log buffer instead of allocating these temporary line buffers on every caller's stack.

Comment thread components/utilities/ulog/ulog.c Outdated
{
/* format the message first, so that the result (not the format
* string) is truncated when the output is longer than the buffer */
n = rt_vsnprintf(body_buf, sizeof(body_buf), format, args);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P2] 在格式化之前执行运行时过滤 / Apply runtime filtering before formatting

中文:这里先格式化正文,前面也已经格式化上下文,直到第 910 行进入 ulog_output()/ulog_voutput() 后才检查初始化状态、全局/标签级别和标签过滤。因此,即使运行时已关闭 DEBUG 日志,这些日志仍会完整执行字符串扫描及数值转换。在使用当前 PR 源码和实际 tiny formatter 的宿主复现中,把全局级别设为 ERROR 后输出一条 DEBUG 日志:原路径调用 rt_vsnprintf 0 次,仅启用行号的新路径调用 2 次,两者最终都没有输出。高频线程或 ISR 中这会保留本应被过滤掉的格式化开销。建议让新路径先经过公共初始化和过滤检查,再格式化上下文及正文。

English: The context and message are formatted before ulog_output()/ulog_voutput() performs initialization, level, and tag checks. Runtime-disabled DEBUG logs therefore still scan strings and perform conversions. In a host reproduction using this PR's code and the actual tiny formatter, an ERROR global threshold resulted in zero rt_vsnprintf calls on the original DEBUG path but two calls with line context enabled, with no output in either case. This adds avoidable work to high-frequency thread/ISR logging. Please run the shared initialization and filtering checks before formatting context or message text.

Comment thread components/utilities/ulog/ulog.c Outdated
Comment on lines +851 to +854
n = rt_snprintf(ctx_buf + pos, sizeof(ctx_buf) - pos, "%s", file);
if (n > 0)
{
pos += (n < (int)(sizeof(ctx_buf) - pos)) ? (rt_size_t)n : (sizeof(ctx_buf) - pos - 1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[Suggestion / 非阻塞建议] 限制文件路径前缀占用 / Bound the file-path prefix

中文:ULOG_FILE_INFO 直接传入 FILE,它可能包含较长的构建目录。这里允许文件路径占满 ctx_buf,而最终 ulog_formater 仍受 ULOG_LINE_BUF_SIZE 限制。默认 128 字节配置下,传入 178 字节文件路径的宿主复现最终只输出路径开头,实际文件名、函数、行号和 ERROR_BODY 正文全部不可见。建议只保留文件名,或限制上下文宽度,为正文预留空间。这项作为非阻塞建议。

English: FILE can include a long build-directory path. The path may fill ctx_buf while the final formatter is still limited to ULOG_LINE_BUF_SIZE. With the default 128-byte limit, a host reproduction using a 178-byte path emitted only the beginning of the path; the basename, function, line number, and ERROR_BODY message were all absent. Consider using the basename or bounding context length to reserve space for the message. This is a non-blocking suggestion.

…tting

- keep a single ULOG_LINE_BUF_SIZE + 8 buffer on the caller stack instead
  of three line buffers (520 bytes), so the function stays usable on a
  512 bytes soft timer thread stack (measured 480 bytes on a 64-bit host,
  which includes the va_list register save area);
- apply the runtime filters (init state, global/tag level and tag filter)
  before formatting, so a log that would be dropped no longer scans the
  format string or converts any argument;
- use only the file name part of __FILE__ and bound the context prefix to
  ULOG_LINE_BUF_SIZE / 2, so a long build path cannot hide the message.

Signed-off-by: ymj0440 <ymj0440@users.noreply.github.com>
@ymj0440 ymj0440 changed the title feat(ulog): support output the calling function, file and line [components][ulog] support output the calling function, file and line Nov 10, 2026
@ymj0440

ymj0440 commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @Rbb666 for the detailed review. Both blocking issues and the non-blocking suggestions are addressed in 47609045:

  1. [P1] caller stack usage: the three line buffers (520 bytes) are replaced by a single ULOG_LINE_BUF_SIZE + 8 buffer - the context prefix and the message are both built into it. Measured with -O2 -fstack-usage: the ulog_output_ctx frame is 480 bytes on a 64-bit host, and that figure includes the va_list register save area, so a 32-bit target is smaller still.
  2. [P2] runtime filtering before formatting: ulog_output_ctx() now runs the same checks as ulog_voutput() (init state, global level, tag level and tag filter) before touching the format string, so a log that would be dropped performs no string scan and no argument conversion.
  3. [Suggestion] long file-path prefix: only the file-name part of __FILE__ is kept (both / and \\ separators handled), and the prefix is additionally bounded to ULOG_LINE_BUF_SIZE / 2, so the message always keeps enough room.
  4. Naming conventions: the PR title now carries the [components][ulog] prefix and the new commit follows it; the routine follow-up commits can be squashed before merging.

Verified on the host: an empty file name takes the no-context path with zero overhead; components/utilities/ulog/ulog.c renders as [ulog.c:42 app_entry()]; a % inside the file name stays literal; an over-long message is truncated in the result, never in the format string. The changed lines pass clang-format -style=file --dry-run --Werror.

@BernardXiong BernardXiong left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

结论:批准;上一轮的两项阻塞问题已解决。 / Verdict: approved; the two blocking items from the previous review are addressed.

复核 head 47609045:

  • 调用线程栈占用:三段行缓冲(520 B)合并为一个 ULOG_LINE_BUF_SIZE + 8 缓冲;前缀上限为缓冲的一半,消息格式化到剩余空间。每次 rt_snprintf() 的 size 至少为 1,pos 不会超过 ULOG_LINE_BUF_SIZE / 2 - 1,不存在无符号下溢。
  • 运行时过滤先于格式化:ulog_output_ctx_filtered() 在任何格式化之前执行,逻辑与 ulog_voutput() 一致(init_ok、级别/标签过滤、syslog mask);keyword 过滤仍在 ulog_voutput() 中对整行执行。
  • 文件名/函数名/消息中的 % 仍通过最终 "%s" 传递,不会被当作格式串解析。
  • CI:108 pass / 3 skipping。

非阻塞:

  1. 过滤逻辑在 ulog_output_ctx_filtered() 与 ulog_voutput() 中重复(ulog.c#L858),建议后续抽成共享辅助函数,避免两处条件漂移。
  2. 上下文前缀被限制在 ULOG_LINE_BUF_SIZE / 2,过长的 __func__ 会被静默截断,可考虑在帮助中说明。

@Rbb666 Rbb666 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

复核提交 47609045。请处理这四条行内评论后再合并。运行复现使用宿主 GCC 和该提交的 tiny formatter。

Reviewed commit 47609045. Please address the four inline findings before merging. Runtime reproductions used host GCC and the tiny formatter from this commit.

Comment thread components/utilities/ulog/ulog.c Outdated
rt_bool_t newline, const char *format, ...)
{
va_list args;
char out_buf[ULOG_LINE_BUF_SIZE + 8];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P1] 复用现有日志缓冲区 / Reuse the existing log buffer

ULOG_LINE_BUF_SIZE=512 时,这个局部数组单独占用 520 B,超过非 64 位目标默认的 512 B 软定时器线程栈。软定时器回调开启上下文后,只要调用一条通过静态过滤的 LOG_X 就会进入这条路径。提取当前实现,用宿主 GCC -m32 -O2 -fstack-usage 测得 ulog_output_ctx() 自身栈帧为 608 B。请在持锁后复用已有的线程或 ISR 日志缓冲区来写入上下文和正文。

With ULOG_LINE_BUF_SIZE=512, this local array alone takes 520 B, exceeding the default 512 B soft-timer thread stack on non-64-bit targets. A soft-timer callback reaches this path when context is enabled and its LOG_X call passes compile-time filtering. Host GCC with -m32 -O2 -fstack-usage reports a 608 B frame for ulog_output_ctx(). Please write the context and message into the existing thread or ISR log buffer under its lock. 软定时器栈配置 / Soft-timer stack default

Comment thread components/utilities/ulog/ulog.c Outdated
/* hand the assembled "[context] message" to the formatter as a "%s"
* argument, so that '%' characters inside the file name or the message
* are never parsed as format specifiers */
ulog_output(level, tag, newline, "%s", out_buf);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P2] 保留递归日志的正文 / Preserve recursive log messages

同步后端的 output 回调里调用 LOG_E("backend diagnostic")。三个上下文开关全关时,控制台会输出正文。宿主复现中,仅开启行号就会丢失正文。这一行把已格式化文本包装成 %s,递归分支里的 rt_kprintf(format, args) 随后把 va_list 当成字符串地址。请在递归分支用支持 va_list 的格式化接口,再输出结果。

A synchronous backend's output callback can reproduce this with LOG_E("backend diagnostic"). With all context options disabled, the console prints the message. Enabling line context alone loses the message in the host test. This call wraps the text in %s, and the recursive fallback passes a va_list as the string argument to rt_kprintf. Please format the fallback through a va_list-aware interface before writing to the console. 递归分支 / Recursive fallback

Comment thread components/utilities/ulog/ulog.c Outdated
}
if (line > 0)
{
n = rt_snprintf(out_buf + pos, ULOG_LINE_BUF_SIZE / 2 - pos, ":%d", line);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P2] 保留完整行号 / Preserve the complete line number

同时开启文件名和行号时,默认 128 B 的日志缓冲区下,58 字节的文件名会让这里把 12345 截成 123。如果也开启函数名,函数名会被挤掉。请先为完整行号和分隔符预留空间,再截断文件名和函数名。

With file and line context enabled and the default 128 B buffer, a 58-byte basename makes this call display line 12345 as 123. If function context is also enabled, the function name disappears. Please reserve space for the complete line number and separators before truncating names.

Comment thread components/utilities/ulog/ulog.c Outdated
/* format the message directly into the remaining space, so that only the
* result is truncated for over-long messages and the format string itself
* is always used in full */
n = rt_vsnprintf(out_buf + pos, sizeof(out_buf) - pos, format, args);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P3] 保留格式化正文的字节长度 / Preserve the formatted message length

LOG_E("left%cRIGHT", 0) 会生成内嵌 NUL 的正文。原路径把完整字节和长度交给同步后端,文件后端会按这个长度写入。这里格式化后经 %s 再次传递,导致开启任一上下文选项时丢失 RIGHT。请把缓冲区中的实际字节长度随正文一起传给后端。

LOG_E("left%cRIGHT", 0) produces a message containing an embedded NUL. The original path passes the complete bytes and length to synchronous backends, and the file backend uses that length. Passing the result through %s drops RIGHT when any context option is enabled. Please carry the number of bytes actually written through to the backend. 文件后端 / File backend

…yte length

- reuse the thread/ISR log buffer instead of adding a local array, so
  ulog_output_ctx() no longer needs 520 bytes of caller stack (measured
  304 bytes at -O0 on a 64-bit host, which already includes the va_list
  register save area, and 32-bit targets are smaller);
- reserve space for the line number and the function name before writing
  the file name, so a long basename can no longer truncate them;
- keep the complete byte count returned by rt_vsnprintf and hand it to
  do_output(), so a message containing an embedded NUL reaches the
  backend in full;
- in the recursion branch format into a small local buffer and print it
  with "%s", so the va_list is never passed to rt_kprintf() as an
  ordinary argument.

Signed-off-by: ymj0440 <ymj0440@users.noreply.github.com>
@ymj0440

ymj0440 commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @Rbb666. The four inline findings are addressed in e31da27c:

  1. [P1] stack usage: the local array is gone. The context prefix and the message are now written directly into the thread/ISR log buffer after output_lock(), and the result is handed to do_output() together with its length, exactly like ulog_voutput() does. -O0 -fstack-usage on a 64-bit host gives 304 bytes for ulog_output_ctx() (including the va_list register save area; a 32-bit target is smaller) and 176 bytes for ulog_voutput_ctx(). ULOG_LINE_BUF_SIZE no longer affects the stack at all.
  2. [P2] recursive messages: the recursion branch now formats with rt_vsnprintf() into a small local buffer and prints it with rt_kprintf("%s", ...), so the va_list is never handed to rt_kprintf() as an ordinary argument and the message text is preserved.
  3. [P2] complete line number: ulog_ctx_formater() reserves 12 bytes for the line number and strlen(func) + 4 for the function name before bounding the file name, so neither can be squeezed out. Verified: a 58-byte basename with line 12345 renders [<58-byte name>:12345 app_entry()], and the function name stays visible when it is enabled as well.
  4. [P3] embedded NUL: the complete return value of rt_vsnprintf() is accumulated into log_len, and do_output(..., log_len) receives the full byte count, so LOG_E("left%c RIGHT", 0) keeps RIGHT for length-aware backends such as the file backend.

The changed lines pass clang-format -style=file --dry-run --Werror, and the all-switches-off build still compiles cleanly.

@BernardXiong BernardXiong left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

复核 e31da27c:四项行内意见已落实——上下文与正文直接写入 get_log_buf() 的线程/ISR 缓冲,运行时过滤在格式化前执行,行号/函数名先预留空间,递归分支用 rt_vsnprintf() 处理 va_list 并保留内嵌 NUL 的实际字节长度。静态检查未发现阻塞问题。

非阻塞:ulog_voutput_ctx() 在 ULOG_USING_SYSLOG 下仍调用 ulog_head_formater()(L1016),而普通 ulog_voutput() 在 syslog 配置下使用 syslog_formater()(L768)。同时开启 syslog 和任一上下文开关时,输出会缺少 syslog 前缀/格式,建议 ctx 路径也按配置选择 syslog_formater()。

log_len = ulog_head_formater(log_buf, level, tag);

CI:当前 head 的 4 个失败均停在 Install Tools / 工具链下载阶段(A9、AARCH64-smp 等),属于网络故障,不是代码失败;另有 2 个任务未完成。建议 rerun 后再合并。

syslog_formater() owns the format of every syslog record, so a context
prefix cannot be inserted without breaking the syslog format. Hide the
three switches in Kconfig when ULOG_USING_SYSLOG is enabled, and add the
same guard to the LOG_X macro, so that a hand-written configuration falls
back to the original path instead of emitting records without the syslog
head.

Signed-off-by: ymj0440 <ymj0440@users.noreply.github.com>
@ymj0440

ymj0440 commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @BernardXiong. The syslog case is handled in 6cc989a2. syslog_formater() owns the whole format of every record there, so a context prefix cannot be inserted without breaking the syslog head. Following the way ULOG_USING_COLOR is already gated in Kconfig, the three switches are now depends on !ULOG_USING_SYSLOG, and the LOG_X macro carries the same guard: with ULOG_USING_SYSLOG set, the macro falls back to ulog_output() and the original path is used untouched.

Verified: defining ULOG_USING_SYSLOG together with all three switches by hand makes LOG_D expand back to ulog_output(<level>, LOG_TAG, RT_TRUE, ...), and ulog.c compiles in syslog mode. If a context prefix is wanted under syslog later, it would need a dedicated design in syslog_formater(); I did not want to add a static buffer just for that combination.

On the CI: you are right that those A9 / AARCH64 jobs stopped during the tool-chain download. The new head 6cc989a2 has started a fresh run, so no rerun of the old ones is needed.

@Rbb666 Rbb666 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed 6cc989a2. Please address the inline findings before merging. The reproductions used host GCC and the RT-Thread tiny formatter from this commit.

Comment thread components/utilities/ulog/ulog.c Outdated
/* log head */
log_len = ulog_head_formater(log_buf, level, tag);
/* calling context prefix, e.g. "[ulog.c:42 app_entry()] " */
log_len += ulog_ctx_formater(log_buf + log_len, ULOG_LINE_BUF_SIZE - log_len, file, func, line);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P2] Reserve space for the log message

This call gives the context formatter all of the space left after the log header. With the default ULOG_LINE_BUF_SIZE=128 and only file context enabled, a 136-byte basename makes LOG_E("ERROR_BODY") lose its entire message in the host test. The same test retained the message on 47609045. Please reserve space for the message and line ending before truncating the context.

Comment thread components/utilities/ulog/ulog.c Outdated
/* a synchronous backend is logging again: format into a small local
* buffer and print it directly, so that the va_list is never handed to
* rt_kprintf() as an ordinary argument */
char tmp_buf[64];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P2] Preserve the console capacity for recursive logs

A synchronous backend's output callback logs an 80-byte literal in this test. With the default 128-byte console buffer, the full message reaches the console when context is disabled. Enabling any context option limits the message to 63 bytes because of this temporary buffer. Please route the recursive fallback through a va_list-aware console output path that reuses the existing console buffer.

Comment thread components/utilities/ulog/ulog.c Outdated
if ((line > 0) && (size - pos > 3))
{
room = size - pos - 3;
n = rt_snprintf(buf + pos, room, ":%d", line);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P2] Emit the complete line number

With an 80-byte line buffer and a 68-byte log header, LOG_E() at file.c:12345 displays [fil:123]. The reserved = size / 3 fallback can leave too little room for the full number, and the truncated digits are still emitted. Please reserve space for the complete line number or omit the field when it cannot fit.


va_start(args, format);

if ((file == RT_NULL) && (func == RT_NULL) && (line <= 0))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P3] Apply the syslog fallback at the public entry point

With ULOG_USING_SYSLOG enabled, LOG_X produces a syslog record with a <PRI> header. A direct call to the publicly declared ulog_output_ctx() with a file name still enters ulog_voutput_ctx() and emits a plain ulog record into the same stream. Please apply the syslog fallback here as well so direct callers preserve syslog framing.

@BernardXiong BernardXiong left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

复核 head 6cc989a210:syslog 模式下的兜底已按上次建议禁用(!defined(ULOG_USING_SYSLOG) 同时覆盖 Kconfig 与手写配置),这一项已解决。Rbb666 在本 head 的 review 5867758384 中提出的四条行内问题,我复核后确认在当前代码中仍然成立:

  1. [P2] 正文空间被上下文挤占:ulog.c:1018 把 log head 之后的全部剩余空间交给 ulog_ctx_formater(),长文件名会把 LOG_E("ERROR_BODY") 的正文完全挤掉。
  2. [P2] 递归分支缓冲过小:ulog.c:999 的 tmp_buf[64] 把同步后端递归日志截到 63 字节,而控制台缓冲是 ULOG_LINE_BUF_SIZE。
  3. [P2] 行号仍可能被截断:ulog.c:908 的 reserved = size / 3 回退不足以容纳完整行号,会输出截断后的数字。
  4. [P3] 公开入口未走 syslog 兜底:ulog.c:1081 直接调用 ulog_output_ctx() 时仍会生成普通 ulog 记录,绕过 syslog 帧格式。

除这四条外未发现新的阻塞问题,建议修复后再合并。CI 全绿(108 成功、3 跳过)。

Summary (EN): The syslog fallback from the previous round is fixed. The four inline findings Rbb666 raised at this head are confirmed still valid: the message space is not reserved, the recursive buffer is only 64 bytes, the size / 3 fallback can still truncate the line number, and direct ulog_output_ctx() calls bypass syslog framing. No other blocking issues found.

…ve logs

- give the context prefix at most half of the space left after the log head,
  so a long file name can no longer hide the message; when the space is
  really tight the prefix still gets 12 bytes for the line number
- emit the line number and the function name only when they fit completely,
  a truncated number is never printed
- format recursive backend logs into a static buffer as wide as the console
  buffer instead of a 64-byte local one, and keep it out of the caller stack
- route the public ulog_output_ctx() through the plain path in syslog mode,
  so a direct call never emits a record without the syslog head

Signed-off-by: ymj0440 <ymj0440@users.noreply.github.com>
@ymj0440

ymj0440 commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @Rbb666, and thanks @BernardXiong for re-checking. All four inline findings are addressed in 9d6b54cf:

  1. [P2] message room: the context prefix now gets at most half of the space left after the log head (ctx_size = (ULOG_LINE_BUF_SIZE - log_len) / 2). With the default 128-byte buffer and the 136-byte basename, LOG_E("ERROR_BODY") now keeps its message: [nnnn...nn] ERROR_BODY (the prefix is cut at 40 bytes, the message stays complete).

  2. [P2] recursive buffer: tmp_buf[64] is replaced by a static buffer of ULOG_LINE_BUF_SIZE, the same width as the console buffer, so an 80-byte recursive message is no longer cut at 63 bytes. Being static it also stays off the caller stack — -O0 / 64-bit gives ulog_output_ctx 304, ulog_voutput_ctx 96, ulog_ctx_formater 128 (was 176 for ulog_voutput_ctx).

  3. [P2] complete line number: the reserved = size / 3 fallback is gone. The line number and the function name are emitted only when they fit completely, so a truncated number is never printed. With your 80-byte buffer and 68-byte header, file.c:12345 now shows [:12345] with the rest left to the message; when the space is tight the prefix still gets 12 bytes so the complete number fits. Normal case stays [ulog.c:42 app_entry()] value=11.

  4. [P3] syslog at the public entry: ulog_output_ctx() now goes through ulog_voutput() under #ifdef ULOG_USING_SYSLOG, so a direct public call never drops the syslog head.

Verified with host GCC against the tiny formatter for the cases above; ulog.c compiles in both normal and syslog configurations and clang-format is clean.

@BernardXiong BernardXiong left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

复核 head 9d6b54cf:上轮指出的四项行内问题均已落实。

  • 正文空间:ctx_size = (ULOG_LINE_BUF_SIZE - log_len) / 2,长文件名不会再挤掉正文;
  • 递归缓冲:改为与控制台同宽的静态缓冲,位于 output_lock() 保护区内,递归日志不再被截到 63 字节;
  • 行号:完整数字放得下才输出,不再打印截断的行号;
  • syslog:ulog_output_ctx() 在 ULOG_USING_SYSLOG 下回落到普通 ulog_voutput(),不会产生缺少 syslog 头的记录。

CI 通过,未发现阻塞问题。批准。

This branch has not been deployed

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

ulog支持打印调用所在的函数,文件名和行数

3 participants