chore(release): 1.3.0 — Log4j2 appender (#6)#7
Merged
Conversation
The J-Obs UI dashboard previously constructed URLs using only its own base path (`j-obs.path`, defaulting to `/j-obs`), which caused all links and asset requests to fail with a 404 when the application was deployed under a `server.servlet.context-path`.
This commit refactors `TemplateService` to be aware of the application's context path.
- `TemplateService` now injects `Environment` to read `server.servlet.context-path`.
- A new `fullPath()` method combines the application's context path with the J-Obs path (e.g., `/my-app/j-obs`).
- All controllers and template rendering logic now use `templateService.fullPath()` to generate correct, context-aware URLs for `{{BASE_PATH}}`.
- The API Docs page (`api-docs.html`) is updated to use a new `{{CONTEXT_PATH}}` variable for Swagger UI and OpenAPI spec links, ensuring they are also correctly prefixed.
This change ensures that the J-Obs UI is fully functional when hosted within a Spring Boot application that has a global context path configured.
Adds support for capturing logs from Log4j2, mirroring the existing Logback integration. This allows applications using Log4j2 as their logging framework to have their logs collected and displayed within the J-Obs UI. - **`JObsLog4j2Appender`**: A new Log4j2 appender that captures log events, sanitizes them, and forwards them to the `LogRepository`. - It extracts `traceId` and `spanId` from the MDC or falls back to the current OpenTelemetry `SpanContext`. - It avoids circular logging by ignoring log events originating from the `io.github.jobs` packages. - Gracefully handles the absence of the OpenTelemetry API on the classpath. - **`JObsLogAutoConfiguration`**: Updated to include a new `Log4j2Configuration` inner class. - This configuration automatically registers the `JObsLog4j2Appender` bean and attaches it to the Log4j2 root logger. - It is conditionally enabled only when Log4j2 is on the classpath and the Logback appender is not present, ensuring no conflicts.
…re-add-log4j2 # Conflicts: # j-obs-spring-boot-starter/src/main/java/io/github/jobs/spring/web/template/TemplateService.java
The Log4j2 appender auto-configuration has been refined to ensure correct conditional activation and robustness, particularly when Logback is also present or Log4j2 is bridged to SLF4J.
- **`JObsLogAutoConfiguration`**:
- The `Log4j2Configuration` now uses `@ConditionalOnMissingClass("ch.qos.logback.classic.Logger")` instead of `@ConditionalOnMissingBean` to determine if Logback is absent. This ensures Logback takes priority by default (as is common in Spring Boot applications) and the Log4j2 appender only activates when Logback is explicitly not on the classpath.
- The logic for attaching the `JObsLog4j2Appender` to the Log4j2 root logger has been made more resilient. It now explicitly checks if `LogManager.getContext()` returns a native `org.apache.logging.log4j.core.LoggerContext` before adding the appender, preventing issues when Log4j2 is bridged to SLF4J.
- **`JObsLogAutoConfigurationTest`**:
- Added new tests to verify the conditional logic:
- Confirms that the Logback appender is used when both Logback and Log4j2 are present.
- Confirms that the Log4j2 appender is used when Logback is absent from the classpath.
This ensures reliable and correct logging appender activation based on the available logging frameworks.
Bump all module versions to 1.3.0, update README and BOM, and document the new optional Log4j2 appender (PR #6) in CHANGELOG. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
JObsLog4j2Appenderfor applications using Log4j2 instead of Logback (mirrors the existing Logback appender, with OTel trace/span correlation, sanitization, and circular-logging guard).Test plan
mvn testforj-obs-spring-boot-starter(exit 0)mvn install -DskipTestsforj-obs-core+ starter (exit 0)🤖 Generated with Claude Code