Add the Log4j2 appender for log collection as an optional add-on.#5
Closed
Carlosho23 wants to merge 3 commits into
Closed
Add the Log4j2 appender for log collection as an optional add-on.#5Carlosho23 wants to merge 3 commits into
Carlosho23 wants to merge 3 commits into
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
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.
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 theLogRepository.It extracts
traceIdandspanIdfrom the MDC or falls back to the current OpenTelemetrySpanContext.It avoids circular logging by ignoring log events originating from the
io.github.jobspackages.Gracefully handles the absence of the OpenTelemetry API on the classpath.
JObsLogAutoConfiguration: Updated to include a newLog4j2Configurationinner class.This configuration automatically registers the
JObsLog4j2Appenderbean 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.