Skip to content

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

Open
kamcheungting-db wants to merge 2 commits into
apache:mainfrom
kamcheungting-db:logging-block5-spdlog
Open

feat(logging): add spdlog backend behind ICEBERG_SPDLOG (5/6)#726
kamcheungting-db wants to merge 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 (ON by default). When OFF, the build has no spdlog dependency at all 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/internal/ and is not installed — apps get it via the default logger or the "spdlog" registry type.

Testsspdlog_logger_test (compiled only when spdlog is ON): level mapping incl. fatal→critical, source-location forwarding, and the pattern property. clang/libc++ with spdlog 1.15.3.

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 5 times, most recently from 661dc05 to 7e81c6d Compare June 24, 2026 17:58
Fourth block: the application-facing macros, the only part most callers touch.

- ICEBERG_LOG_{TRACE,DEBUG,INFO,WARN,ERROR,CRITICAL,FATAL} plus the generic
  ICEBERG_LOG(level, ...), ICEBERG_LOG_TO(logger, level, ...) for an explicit
  logger, and ICEBERG_LOG_RUNTIME_FMT for a runtime (non-literal) format string.
- ICEBERG_LOG_ACTIVE_LEVEL is a compile-time severity floor: statements below it
  are removed entirely via `if constexpr` (no format call site, no source
  location emitted). ICEBERG_LOG_FATAL is never gated by the floor -- its abort
  is always compiled in; it emits, best-effort Flush()es the same logger it
  emitted to, then std::abort().
- Filtering is decided solely by Logger::ShouldLog(); formatting is wrapped in
  try/catch so logging never throws (a format failure routes to EmitFormatError).
- Bare Java-style aliases (LOG_INFO, ...) are opt-in via ICEBERG_LOG_SHORT_MACROS
  to avoid polluting consumers / colliding with glog/abseil.

Header-only addition to logger.h. macros_test covers injection, the
guard-before-format short-circuit, never-throws, and FATAL aborts;
macros_active_level_test verifies compile-time stripping in a kOff translation unit.

Co-authored-by: Isaac
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
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.

1 participant