Skip to content

feat(hlog): add %p (pid) / %t (tid) format specifiers (standalone, supersedes #742) - #865

Closed
ithewei wants to merge 1 commit into
masterfrom
feat/hlog-pid-tid
Closed

feat(hlog): add %p (pid) / %t (tid) format specifiers (standalone, supersedes #742)#865
ithewei wants to merge 1 commit into
masterfrom
feat/hlog-pid-tid

Conversation

@ithewei

@ithewei ithewei commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Adds %p (process id) and %t (thread id) log format specifiers.

Reworked version of #742 to respect a design constraint: hlog.h/hlog.c are meant to be usable standalone (depending only on hexport.h). #742 did #include <hthread.h> to get hv_getpid()/hv_gettid(), which pulls in hplatform.h and breaks that independence.

Instead, this inlines the pid/tid platform primitives directly in hlog.c, using the headers it already includes (windows.h on Windows; pthread.h + sys/syscall.h/SYS_gettid on Linux, pthread_threadid_np on macOS, pthread_self fallback) — no hthread.h/hplatform.h dependency.

Usage

hlog_set_format("%y-%m-%d %H:%M:%S.%z %L [%p:%t] %s");

Verified

  • hlog.c compiles standalone (cc -I. -Ibase hlog.c + a tiny main) — no hthread.h/hplatform.h needed.
  • %p prints the process id, %t the thread id.
  • Full make libhv builds clean; format doc in hlog.h updated.

Supersedes #742 (thanks @mtdxc for the original idea).

Adds %p/%t to the log format. hlog is meant to be usable standalone
(depending only on hexport.h), so instead of pulling in hthread.h this
inlines the pid/tid platform primitives using the headers hlog.c already
includes (windows.h / pthread.h + sys/syscall.h on Linux, pthread_
threadid_np on macOS).

Verified: hlog.c still compiles standalone (only -I. -Ibase, no
hthread.h/hplatform.h) and %p/%t print the correct process/thread id.

Supersedes #742 (same feature; reworked to keep hlog dependency-free).
Copilot AI lite review requested due to automatic review settings August 6, 2026 04:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@ithewei

ithewei commented Aug 6, 2026

Copy link
Copy Markdown
Owner Author

撤回:hlog 的 %p/%t 目前没有实际需求,用户如需可自行在 message 里拼接 pid/tid(如 hlogi("[%ld] ...", (long)hv_gettid()))。保持 hlog 格式符最小化。

@ithewei ithewei closed this Aug 6, 2026
@ithewei
ithewei deleted the feat/hlog-pid-tid branch August 6, 2026 04:08
@mtdxc

mtdxc commented Aug 6, 2026 via email

Copy link
Copy Markdown
Contributor

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.

3 participants