Skip to content

BP-69: Convert bookkeeper-server to slog (phase 3)#4756

Merged
merlimat merged 5 commits intoapache:masterfrom
merlimat:bp-69-slog-bookkeeper-server
Apr 28, 2026
Merged

BP-69: Convert bookkeeper-server to slog (phase 3)#4756
merlimat merged 5 commits intoapache:masterfrom
merlimat:bp-69-slog-bookkeeper-server

Conversation

@merlimat
Copy link
Copy Markdown
Contributor

Summary

Part of BP-69 (SLF4J to slog migration). Converts the bookkeeper-server module to use slog for structured logging.

This PR is stacked on #4754 (common, phase 1) and #4755 (stats, phase 2), but has its own minimal base commit so it can merge independently:

  1. BP-69 base: add slog dependency and LICENSE entries — minimal scaffolding: adds slog to root pom.xml, updates LICENSE-*.bin.txt files, and adds lombok.config for the @CustomLog annotation.
  2. BP-69: Convert bookkeeper-server from SLF4J to slog — the actual module conversion (252 files).

Conversion patterns applied

  • LoggerFactory.getLogger(Foo.class) / @Slf4j → Lombok @CustomLog generating a slog Logger.
  • log.info("text {} {}", a, b)log.info().attr("nameA", a).attr("nameB", b).log("text") — values become typed structured attributes.
  • log.error("msg", exception)log.error().exception(exception).log("msg").
  • if (log.isDebugEnabled()) { ... } → lambda form log.debug(e -> e.attr(...).log(...)) where the cost of evaluation matters.
  • Consistent attribute naming: ledgerId, entryId, thread, directory, fileInfo, etc.

No changes to log output format — slog with the SLF4J backend produces equivalent output.

Test plan

  • mvn -pl bookkeeper-server compile passes
  • mvn -pl bookkeeper-server checkstyle:check passes
  • mvn -pl bookkeeper-server test passes in CI
  • Full CI matrix green

Minimal scaffolding commit for the BP-69 slog migration series:

- Add `io.github.merlimat.slog:slog:0.9.7` to the root pom.xml
  dependencyManagement and to the global compile classpath alongside
  the existing SLF4J API (which stays as the rendering backend).
- Add lombok.config at the repo root so `@CustomLog` generates a slog
  `Logger` instead of an SLF4J one.
- Register the slog jar in LICENSE-all.bin.txt, LICENSE-server.bin.txt
  and LICENSE-bkctl.bin.txt so the CI check-binary-license script
  finds it accounted for in the bundled-jars list.

No actual Java file is converted in this commit. Individual module
migrations stack on top of this one.
Also includes a few follow-ups now that 0.9.8 is in use:
- Wrap method-call attr values in Supplier for lazy evaluation on debug/
  trace log calls that were originally guarded by isXxxEnabled. The
  fluent slog form would otherwise eagerly evaluate the attr arguments
  even when the level is disabled.
- Simplify the response promise in PacketProcessorBase: always attach a
  ChannelFutureListener (the listener body itself uses log.debug() and
  is cheap when debug is off) rather than the side-effecting lambda.
  Mock newPromise() with RETURNS_SELF in ReadEntryProcessorTest so the
  chained .addListener() returns the same mock.
- Update MdcContextTest assertions for the new bare slog messages
  (ledgerId / entryId / firstEntry / lastEntry are now structured attrs
  rather than baked into the message string). With the slog 0.9.8 fix,
  MDC propagates through the log4j2 backend and the test verifies that.
…ormat

The slog conversion of SimpleTestCommand turned the original
LOG.info("{} entries written to ledger {}", numEntries, ledgerId)
into a structured form that lost the substring TestCLI and
TestBookieShellCluster's test001_SimpleTest assert on ("100 entries
written to ledger"). The default log4j2 PatternLayout in the
bookkeeper image prints %m only, so the structured attrs are not
visible to the integration tests that inspect command stdout.

Use logf() to bake the values into the message so it again matches
the integration-test expectations. The progress-line log on line 118
similarly drops a non-descriptive single-letter "i" attr in favor
of the formatted '<count> entries written'.
Same regression as SimpleTestCommand: the slog conversion lost the
verbatim message text 'LastLogMark : Journal Id - <id>(<hex>.txn),
Pos - <offset>' that the integration test
BkCtlTest.showLastMark asserts on. Default log4j2 PatternLayout
prints %m only, so structured attrs are not visible to integration
tests that inspect command stdout.

Use logf() to bake the values into the message.
@merlimat merlimat merged commit a3ec40b into apache:master Apr 28, 2026
20 checks passed
@merlimat merlimat deleted the bp-69-slog-bookkeeper-server branch April 28, 2026 15:20
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