Skip to content

feat(logging): add CerrLogger std::cerr backend (3/6)#724

Merged
wgtmac merged 3 commits into
apache:mainfrom
kamcheungting-db:logging-block3-cerr
Jun 24, 2026
Merged

feat(logging): add CerrLogger std::cerr backend (3/6)#724
wgtmac merged 3 commits into
apache:mainfrom
kamcheungting-db:logging-block3-cerr

Conversation

@kamcheungting-db

@kamcheungting-db kamcheungting-db commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Part 3 of the logging stack — now based on main (#723 merged). Adds the first concrete sink: a dependency-free std::cerr logger, also the default backend when spdlog is off.

What's here

  • CerrLogger writes one line per record: YYYY-MM-DDThh:mm:ss.mmmZ LEVEL [tid] [file:line] message.
  • UTC millisecond timestamps, OS-native cached thread id (extracted to util/thread_util.h), lock-free level check, and a whole-line mutex so concurrent records never interleave.
  • Pure standard library, always available. Log/Flush never throw. Inherits the base Initialize("level"); pattern is ignored (fixed layout; only the spdlog backend honors pattern).

Tests (cerr_logger_test): level filtering, the fixed line layout incl. the .mmm field and [file:line], inherited Initialize, Flush, never-throw when the sink itself throws, and concurrent-write non-interleaving. Built/run under clang-libc++; ASan + TSan clean.

This pull request and its description were written by Isaac.

@kamcheungting-db kamcheungting-db changed the title feat: [Iceberg Logger] [Part-3] CerrLogger std::cerr backend feat(logging): add CerrLogger std::cerr backend Jun 11, 2026
@kamcheungting-db kamcheungting-db changed the title feat(logging): add CerrLogger std::cerr backend feat(logging): add CerrLogger std::cerr backend (3/6) Jun 11, 2026
@kamcheungting-db kamcheungting-db force-pushed the logging-block3-cerr branch 6 times, most recently from 7f46cc5 to 0dbc548 Compare June 16, 2026 03:27
@kamcheungting-db kamcheungting-db force-pushed the logging-block3-cerr branch 7 times, most recently from d3237ab to 77acb0e Compare June 22, 2026 09:23
Comment thread src/iceberg/logging/cerr_logger.h
Comment thread src/iceberg/logging/cerr_logger.cc Outdated
std::string FormatLine(const LogMessage& message) {
auto now =
std::chrono::floor<std::chrono::milliseconds>(std::chrono::system_clock::now());
return std::format("{:%Y-%m-%dT%H:%M:%S}Z {} [{}] {}:{}] {}\n", now,

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.

The format has file:line], with a closing ] but no opening [. This looks like a typo. Please use [file:line] or file:line, and add a test that checks this part of the layout.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

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.

Seems not resolved. See my comment below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. uploaded a wrong version.

Comment thread src/iceberg/logging/cerr_logger.cc Outdated
Comment thread src/iceberg/logging/cerr_logger.cc Outdated
std::string FormatLine(const LogMessage& message) {
auto now =
std::chrono::floor<std::chrono::milliseconds>(std::chrono::system_clock::now());
return std::format("{:%Y-%m-%dT%H:%M:%S}Z {} [{}] {}:{}] {}\n", now,

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.

The PR description says the layout is [file:line], but this still emits file:line]. Please update the format string, the header doc, and the regex test to use the same layout.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread src/iceberg/logging/logger.h
Comment thread src/iceberg/CMakeLists.txt Outdated
util/struct_like_set.cc
util/task_group.cc
util/temporal_util.cc
util/thread_util_internal.cc

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.

We can just use thread_util.cc as its name without internal suffix.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok

Comment thread src/iceberg/logging/cerr_logger.cc Outdated
std::string FormatLine(const LogMessage& message) {
auto now =
std::chrono::floor<std::chrono::milliseconds>(std::chrono::system_clock::now());
return std::format("{:%Y-%m-%dT%H:%M:%S}Z {} [{}] {}:{}] {}\n", now,

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.

Seems not resolved. See my comment below.


/// \brief Trailing path component of a source file path.
std::string_view Basename(std::string_view path) noexcept {
auto pos = path.find_last_of("/\\");

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.

Is this platform compatible? Should we use std::filesystem?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@kamcheungting-db kamcheungting-db force-pushed the logging-block3-cerr branch 3 times, most recently from 96caa72 to 65d2d43 Compare June 24, 2026 11:08
@kamcheungting-db kamcheungting-db requested a review from wgtmac June 24, 2026 11:30
kamcheungting-db and others added 2 commits June 24, 2026 22:37
Third block: the first concrete sink, and the process default until the spdlog
backend lands.

- CerrLogger writes to std::cerr with a fixed line layout
  `YYYY-MM-DDThh:mm:ss.mmmZ LEVEL [tid] file:line] message`. Timestamps use UTC
  std::chrono floored to milliseconds (no gmtime/localtime -- thread-unsafe);
  the thread id is the OS-native id, cached per thread.
- Level is a std::atomic<LogLevel>; a mutex guards the whole formatted-line write
  so concurrent lines never interleave. Log()/Flush() wrap stream ops in
  try/catch so the noexcept contract holds even if the stream throws.
- MakeDefaultLogger() now returns CerrLogger.

Wired into both builds and installed; cerr_logger_test covers layout, level
filtering, and concurrent-write safety.

Co-authored-by: Isaac
@wgtmac wgtmac force-pushed the logging-block3-cerr branch from 65d2d43 to 0b106c2 Compare June 24, 2026 14:48
@wgtmac wgtmac merged commit 411c0f8 into apache:main Jun 24, 2026
21 checks passed
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