Skip to content

chore(release): 1.3.0 — Log4j2 appender (#6)#7

Merged
JohnPitter merged 6 commits into
mainfrom
release/1.3.0
May 6, 2026
Merged

chore(release): 1.3.0 — Log4j2 appender (#6)#7
JohnPitter merged 6 commits into
mainfrom
release/1.3.0

Conversation

@JohnPitter
Copy link
Copy Markdown
Owner

Summary

  • Merges PR Add the Log4j2 appender for log collection as an optional add-on. #6 by @Carlosho23 — adds optional JObsLog4j2Appender for applications using Log4j2 instead of Logback (mirrors the existing Logback appender, with OTel trace/span correlation, sanitization, and circular-logging guard).
  • Bumps all module versions (root, BOM, starter, sample apps) to 1.3.0.
  • Updates README and CHANGELOG (Logback → "Logback or Log4j2").

Test plan

🤖 Generated with Claude Code

cOliveiraNextage and others added 6 commits April 8, 2026 14:37
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>
@JohnPitter JohnPitter merged commit 64b93db into main May 6, 2026
11 checks passed
@JohnPitter JohnPitter deleted the release/1.3.0 branch May 6, 2026 23:47
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