Skip to content

feat(logging): add spdlog backend behind ICEBERG_SPDLOG (5/6) - #726

Merged
wgtmac merged 2 commits into
apache:mainfrom
kamcheungting-db:logging-block5-spdlog
Aug 15, 2026
Merged

feat(logging): add spdlog backend behind ICEBERG_SPDLOG (5/6)#726
wgtmac merged 2 commits into
apache:mainfrom
kamcheungting-db:logging-block5-spdlog

Conversation

@kamcheungting-db

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

Copy link
Copy Markdown
Contributor

Part 5 of the logging stack (builds on #725). Adds the spdlog backend and the build option that selects it — the default in production builds.

What's here

  • SpdLogger wraps spdlog::logger (synchronous), maps levels (fatal/critical → spdlog critical; the abort stays in the macro layer), and forwards source location. Default sink is a colored stderr sink.
  • New ICEBERG_SPDLOG CMake option and matching Meson spdlog feature option (enabled by default). When disabled, the build has no spdlog dependency and CerrLogger is the default.
  • pattern property is honored here via spdlog set_pattern (the cerr backend keeps its fixed layout); level works on both backends.
  • SpdLogger lives in logging/spdlog_logger_internal.h and is not installed — apps get it via the default logger.
  • Runtime kFatal macro paths now use the same fatal-handler and abort sequence as ICEBERG_LOG_FATAL.

Tests — logging tests cover default-backend selection, level filtering and mapping including fatal→critical, source-location forwarding, the pattern property, and runtime fatal-handler routing.

This pull request and its description were written by Isaac.

@kamcheungting-db kamcheungting-db changed the title feat: [Iceberg Logger] [Part-5] spdlog backend (ICEBERG_SPDLOG) feat(logging): add spdlog backend behind ICEBERG_SPDLOG Jun 11, 2026
@kamcheungting-db kamcheungting-db changed the title feat(logging): add spdlog backend behind ICEBERG_SPDLOG feat(logging): add spdlog backend behind ICEBERG_SPDLOG (5/6) Jun 11, 2026
@kamcheungting-db
kamcheungting-db force-pushed the logging-block5-spdlog branch 2 times, most recently from c6831cb to 2b80ee1 Compare June 14, 2026 06:16
@kamcheungting-db
kamcheungting-db force-pushed the logging-block5-spdlog branch 14 times, most recently from dd50f86 to 17a616e Compare June 22, 2026 10:24
@kamcheungting-db
kamcheungting-db force-pushed the logging-block5-spdlog branch 6 times, most recently from 7e81c6d to 2684d7c Compare June 24, 2026 18:39
@kamcheungting-db
kamcheungting-db force-pushed the logging-block5-spdlog branch 2 times, most recently from 289b0fb to ef127cd Compare June 30, 2026 20:36
@kamcheungting-db
kamcheungting-db force-pushed the logging-block5-spdlog branch 2 times, most recently from b337dd0 to 56fbf5e Compare July 16, 2026 06:30
@kamcheungting-db
kamcheungting-db force-pushed the logging-block5-spdlog branch 3 times, most recently from db413fa to fd92bc2 Compare July 16, 2026 07:20
@manuzhang
manuzhang requested a review from Copilot July 20, 2026 07:27

Copilot AI left a comment

Copy link
Copy Markdown

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 selectable spdlog-backed logging sink to Iceberg C++ (guarded by ICEBERG_SPDLOG in CMake), introduces the public logging macro headers (log_macros.h / short_log_macros.h), and extends the test/build wiring to cover macro behavior and the spdlog backend.

Changes:

  • Add internal::SpdLogger (spdlog backend) and route the process default logger to it when ICEBERG_HAS_SPDLOG is enabled.
  • Introduce installed logging macro headers (ICEBERG_LOG_*, plus opt-in bare LOG_* aliases) and MSVC preprocessor flags needed for __VA_OPT__.
  • Add unit tests for logging macros and the spdlog backend; update CMake/Meson build definitions accordingly.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/iceberg/test/spdlog_logger_test.cc Adds unit tests for the spdlog-backed logger behavior.
src/iceberg/test/meson.build Includes the new logging-related tests in the Meson test target.
src/iceberg/test/macros_test.cc Adds tests for formatting, level gating, runtime-format safety, and fatal-abort behavior in macros.
src/iceberg/test/macros_active_level_test.cc Adds tests for compile-time log stripping via ICEBERG_LOG_ACTIVE_LEVEL.
src/iceberg/test/CMakeLists.txt Wires the new tests into CMake and adds MSVC /Zc:preprocessor for test compilation.
src/iceberg/meson.build Compiles the spdlog backend source in the Meson build.
src/iceberg/logging/short_log_macros.h Adds opt-in bare LOG_* aliases for the Iceberg-prefixed macros.
src/iceberg/logging/meson.build Generates logging/config.h and installs the new public logging headers in Meson.
src/iceberg/logging/logger.h Extends the logging API docs and adds the FatalHandler hook API.
src/iceberg/logging/logger.cc Selects spdlog vs CerrLogger as the default logger based on ICEBERG_HAS_SPDLOG and implements fatal-handler storage.
src/iceberg/logging/log_macros.h Introduces the public logging macros and internal helpers used by those macros.
src/iceberg/logging/internal/spdlog_logger.h Declares the internal spdlog-backed SpdLogger sink (not installed).
src/iceberg/logging/internal/spdlog_logger.cc Implements the spdlog-backed sink (pattern support, level mapping, forwarding).
src/iceberg/logging/config.h.in Adds the build-generated backend selection header template (ICEBERG_HAS_SPDLOG).
src/iceberg/CMakeLists.txt Generates iceberg/logging/config.h, gates spdlog linkage/compilation behind ICEBERG_SPDLOG, and exports /Zc:preprocessor on MSVC.
meson.build Adds /Zc:preprocessor to MSVC project arguments for Meson builds.
CMakeLists.txt Introduces the ICEBERG_SPDLOG option (default ON).
cmake_modules/IcebergThirdpartyToolchain.cmake Avoids resolving the spdlog dependency when ICEBERG_SPDLOG is OFF.

Comment thread src/iceberg/logging/log_macros.h
Comment thread src/iceberg/logging/internal/spdlog_logger.cc
Comment thread src/iceberg/logging/internal/spdlog_logger.cc
Comment thread src/iceberg/logging/internal/spdlog_logger.cc
Comment thread src/iceberg/logging/internal/spdlog_logger.h Outdated
Comment thread src/iceberg/CMakeLists.txt Outdated
Comment thread src/iceberg/logging/log_macros.h
@manuzhang manuzhang added this to the 0.4.0 milestone Jul 21, 2026
@wgtmac

wgtmac commented Jul 23, 2026

Copy link
Copy Markdown
Member

It's time to rebase it :)

kamcheungting-db added a commit to kamcheungting-db/iceberg-cpp that referenced this pull request Jul 30, 2026
The FatalHandler only ran for fixed ICEBERG_LOG_FATAL; reaching kFatal via the
runtime-level ICEBERG_LOG(kFatal, ...) or ICEBERG_LOG_TO(sink, kFatal, ...) aborted
without invoking it (and only formatted when ShouldLog passed). Extract the fatal
sequence into a shared DispatchFatal (format once -> emit-if-enabled -> flush ->
run handler -> abort) and route LogFatal, LogToCurrentRuntime, and
LogToExplicitRuntime through it. Adds death tests for the two runtime paths.

Co-authored-by: Isaac
Comment thread src/iceberg/logging/internal/spdlog_logger.cc Outdated
Comment thread src/iceberg/logging/internal/spdlog_logger.cc Outdated
Comment thread src/iceberg/logging/meson.build Outdated
Comment thread src/iceberg/test/spdlog_logger_test.cc Outdated
@kamcheungting-db
kamcheungting-db force-pushed the logging-block5-spdlog branch 2 times, most recently from 878625b to f0d8791 Compare August 6, 2026 00:59
@kamcheungting-db
kamcheungting-db force-pushed the logging-block5-spdlog branch 2 times, most recently from c1bcbce to e9308ff Compare August 6, 2026 01:57
Fifth block: the default production backend and the build option that selects it.

- SpdLogger wraps spdlog::logger (kCritical/kFatal -> spdlog critical, others 1:1),
  forwarding the pre-formatted message and source location. Synchronous only in
  v1 (spdlog's source_loc is a non-owning const char*, unsafe with async sinks).
  It lives in logging/internal/, is gated by #ifdef ICEBERG_HAS_SPDLOG, and is
  NOT installed -- consumers obtain it via the default logger or the registry,
  never by including spdlog headers.
- New ICEBERG_SPDLOG CMake option (default ON). config.h is ALWAYS generated
  (only ICEBERG_HAS_SPDLOG's definedness varies) so logger.cc compiles in both
  configurations; MakeDefaultLogger() prefers SpdLogger when compiled in, else
  CerrLogger.
- Critically, ICEBERG_SPDLOG=OFF now UNWIRES the previously-unconditional spdlog
  link (interface-lib lists + resolve_spdlog_dependency), not just the new
  source -- so an OFF build has no spdlog dependency at all.

spdlog_logger_test (compiled only on the ON path) covers the level mapping
including fatal->critical and source-location forwarding.

Co-authored-by: Isaac
@wgtmac
wgtmac force-pushed the logging-block5-spdlog branch from e9308ff to ac3640d Compare August 15, 2026 12:24
@wgtmac
wgtmac force-pushed the logging-block5-spdlog branch from ac3640d to cffea0e Compare August 15, 2026 12:54
@wgtmac

wgtmac commented Aug 15, 2026

Copy link
Copy Markdown
Member

I did another cleanup pass to align this PR with repository conventions: kept SpdLogger behind a non-installed internal header, made it own spdlog::logger by value, simplified the CMake/Meson feature gating, and switched the tests to an injected ostream sink for Windows portability. This keeps spdlog out of the public API while preserving clean no-spdlog builds.

Thanks for working on this, @kamcheungting-db!

@wgtmac
wgtmac merged commit 31274f5 into apache:main Aug 15, 2026
18 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.

4 participants