Skip to content

feat: add SLF4J logging to all service classes - #110

Open
adityamparikh wants to merge 2 commits into
apache:mainfrom
adityamparikh:feat/add-slf4j-logging
Open

feat: add SLF4J logging to all service classes#110
adityamparikh wants to merge 2 commits into
apache:mainfrom
adityamparikh:feat/add-slf4j-logging

Conversation

@adityamparikh

Copy link
Copy Markdown
Contributor

Summary

  • Add SLF4J loggers to CollectionService, IndexingService, SchemaService, SearchService, and JsonUtils
  • Log exceptions in all catch blocks instead of silently swallowing them
  • Use appropriate log levels: error for operational failures, warn for recoverable issues, debug for expected conditions (Solr 10 metrics unavailability, individual doc failures)
  • Safe for STDIO mode: logback-spring.xml already suppresses console logging in the stdio profile

Test plan

  • ./gradlew build passes
  • ./gradlew nativeTest -Pnative passes (119/119 tests)
  • STDIO mode unaffected (logging suppressed by logback config)
  • No regressions

🤖 Generated with Claude Code

Add SLF4J loggers to CollectionService, IndexingService, SchemaService,
SearchService, and JsonUtils. Log exceptions in all catch blocks instead
of silently swallowing them. Use appropriate log levels: error for
operational failures, warn for recoverable issues, debug for expected
conditions (Solr 10 metrics unavailability, individual doc failures).

Safe for STDIO mode: logback-spring.xml already suppresses console
logging in the stdio profile.

Closes #1

Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: adityamparikh <aditya.m.parikh@gmail.com>
@adityamparikh
adityamparikh force-pushed the feat/add-slf4j-logging branch from 9a726a7 to 1464f56 Compare August 19, 2026 11:58
@adityamparikh

Copy link
Copy Markdown
Contributor Author

Rebased onto main (a84033b). This branch was stale enough that the conflicts mattered — it still carried pre-#176 code, so a naive resolution would have reverted three upstream fixes. Taking main's body and adding only the logging:

  • checkHealth: kept Instant.now() and the 6-arg SolrHealthStatus; the branch still had new Date() and the old 8-arg form (refactor: replace mutable Date with Instant in DTO records #113 replaced Date with Instant). Added the logger.warn on top.
  • SchemaService: kept toJson(objectMapper, Map.of("error", String.valueOf(e.getMessage()))); the branch still had the string-concatenated "{\"error\": \"" + e.getMessage() that fix: correct indexing, collection-name and service defects #176 replaced because a message containing a quote or newline emitted invalid JSON. Added logger.error on top.
  • fetchCacheMetrics/fetchHandlerMetrics: kept main's @Nullable return annotations alongside the branch's collectionName parameter rename and logger.debug calls.
  • Import blocks: kept org.jspecify.annotations.Nullable next to the new slf4j imports rather than letting one side win.

Net effect is unchanged from the original intent — loggers on the five service classes, exceptions logged rather than silently swallowed — with none of #113/#176 undone.

Verified: ./gradlew build green on JDK 25.

Adopts the narrowing from apache#111 so the two PRs compose instead of colliding.

Both PRs rewrite the same two catch clauses in fetchCacheMetrics and
fetchHandlerMetrics. apache#111 narrows RuntimeException to SolrException; this PR
was binding the exception for logging while leaving RuntimeException in place.
Whichever merged second would either conflict or silently revert the other's
intent — so this branch now carries the narrowed form too, and the end state is
the same in either merge order.

RemoteSolrException extends SolrException (verified against solrj 10.0.0), so
the Solr 10 path where /admin/mbeans is gone still degrades to null rather than
propagating. What no longer gets swallowed is unrelated RuntimeExceptions --
which is the point of apache#111, and is what the new debug logging is there to
surface.

Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
@adityamparikh

Copy link
Copy Markdown
Contributor Author

Adopted #111's narrowing (506f2bb) so these two PRs no longer collide.

Both touch the same two catch clauses in fetchCacheMetrics / fetchHandlerMetrics. This PR was
binding the exception for logging while keeping RuntimeException; #111 narrows it to
SolrException. Whichever merged second would have conflicted, or silently reverted the other's
intent — the worse outcome, since nothing would look wrong.

This branch now carries the narrowed catch as well, so the end state is the same in either merge
order. If #111 merges first this rebases cleanly; if this merges first, #111 becomes a no-op on
these lines and keeps its AGENTS.md correction.

Verified: RemoteSolrException extends SolrException in solrj 10.0.0, so Solr 10 still degrades
to null where /admin/mbeans is gone. Full build green — 372 tests, 0 failures.

Worth noting the two changes reinforce each other: narrowing the catch means unrelated runtime
failures propagate instead of being reported as "metrics unavailable", and the debug logging
added here is what makes the genuinely-unavailable case diagnosable rather than silent.

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