Skip to content

JCU/fix(logging): add warn.log appender (A4) and split 404s to a dedicated logger - #1420

Merged
milanmajchrak merged 1 commit into
customer/jcufrom
JCU/warn-log-appender
Aug 26, 2026
Merged

JCU/fix(logging): add warn.log appender (A4) and split 404s to a dedicated logger#1420
milanmajchrak merged 1 commit into
customer/jcufrom
JCU/warn-log-appender

Conversation

@milanmajchrak

Copy link
Copy Markdown
Collaborator

References

Description

customer/jcu produces no warn.log. It was branched from vanilla dspace-9.3 and never
received the logging config the other instances carry. This adds the A4 appender to both config
files and ports the 404 logger split, so WARN and ERROR land in their own file the way they do
everywhere else.

Instructions for Reviewers

List of changes in this PR:

  • dspace/config/log4j2.xml: new A4 RollingFile appender writing ${log.dir}/warn.log,
    archives gzipped daily like A1. <AppenderRef ref='A4' level='WARN'/> on the org.dspace
    logger and on <Root>, plus the …NotFound logger at level='OFF'.
  • dspace/config/log4j2-container.xml: the same appender and references. This is the file that
    matters in production
    — the backend container is started with LOGGING_CONFIG pointing at it
    (docker/docker-compose-rest.yml in dspace-angular), so a change to log4j2.xml alone would
    do nothing. Also clarifies the header comment, which named docker-compose-rest.yml without
    saying which repo it lives in.
  • DSpaceApiExceptionControllerAdvice.java: the notFoundLog field and a logClientError()
    helper, taken from dtq-dev-9-base. Without it every 404 lands in the new warn.log, which is
    the noise Reduce warn logs noise #1268 removed elsewhere. The unrelated CLARIN "expose the exception message to REST
    clients for 4xx" change that also sits in 9-base's copy of this file is not part of this PR.

The A4 reference has to be in both places: org.dspace is additivity='false', so its events
never reach <Root>. customer/mendelu has A4 only under <Root> and its warn.log therefore
holds third-party warnings only.

Not included, on purpose:

  • A2 / checker.log — the appender on dtq-dev has no logger pointing at it and the file stays
    at 0 bytes. Checker output already comes from log4j2-cli.xml, which this branch has.
  • A3 / file_downloads.log — it feeds off ClarinMatomoBitstreamTracker, which does not exist
    on the 9.x line. It would only create another empty file.
  • %t in the A1 pattern — it changes the dspace.log line format, so it belongs in its own PR.

How to test:

  1. Start the backend. [dspace]/log/warn.log is created at startup.
  2. Trigger a WARN that is not a 404 — an unauthenticated call to an admin-only endpoint gives a
    401 and is logged by this advice:
    curl -s -o /dev/null -w '%{http_code}' "$DSPACE_URL/api/eperson/epersons" -> 401
    Authentication is required (status:401 …) appears in dspace.log and in warn.log.
  3. Request a nonexistent item — nothing is logged for it anywhere, that is the 404 split working.
  4. Counts should match: grep -cE ' (WARN|ERROR) ' [dspace]/log/dspace.log vs the same over
    warn.log.

Checked against log4j-core 2.25.4, the version this branch pins: dspace.log is unchanged in
size, warn.log comes out byte-identical to dtq-dev's for the same events, and there is no
log4j2 status-logger output at startup.

Note for whoever deploys this: LOGGING_CONFIG and the /dspace/config mount can be overridden
by the compose overlays under /opt/dspace-envs/<instance>/, which are in no repo. Worth a
docker inspect on the running backend container to confirm it reads the image's config.

Checklist

  • My PR is created against the main branch of code — no, this targets customer/jcu; it is a customer-branch fix.
  • My PR is small in size.
  • My PR passes Checkstyle validation.
  • My PR includes Javadoc for the new field and method.
  • My PR passes all tests and includes new/updated Unit or Integration Tests — no test added; the existing ITs load src/test/resources/log4j2-test.xml, not these files, so they neither cover nor are affected by this change.
  • My PR includes details on how to test it.
  • If my PR includes new libraries/dependencies — none added.
  • If my PR modifies REST API endpoints — it does not; only which logger a message goes to.
  • If my PR includes new configurations, I've provided basic technical documentation in the PR itself.
  • If my PR fixes an issue ticket, I've linked them together — no ticket.

…cated logger

customer/jcu was branched from vanilla dspace-9.3 and never received the logging
config the other instances carry, so no warn.log is produced. Add the A4 appender
to log4j2.xml and to log4j2-container.xml - the container reads the latter via
LOGGING_CONFIG - referenced from both the org.dspace logger and Root, since
org.dspace is additivity='false'.

Also port notFoundLog / logClientError() from dtq-dev-9-base, so 404 responses go
to their own logger held at OFF instead of filling the new file.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aligns customer/jcu logging with other customer instances by adding a dedicated warn.log RollingFile appender (A4) and ensuring REST 404 responses can be suppressed via a dedicated logger, keeping warn.log actionable.

Changes:

  • Add A4 RollingFile appender (${log.dir}/warn.log) with daily gzip rollover to both Log4j2 configs.
  • Route WARN+ from org.dspace and Root to A4, while keeping org.dspace additivity behavior intact.
  • Introduce a dedicated 404 logger in DSpaceApiExceptionControllerAdvice and route 404 WARN logging through it (disabled by default in Log4j2 config).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
dspace/config/log4j2.xml Adds warn.log appender and routes WARN+ to it; defines an OFF-by-default dedicated 404 logger.
dspace/config/log4j2-container.xml Mirrors warn.log appender/routing in the production-relevant container config; documents container config usage more explicitly.
dspace-server-webapp/.../DSpaceApiExceptionControllerAdvice.java Adds dedicated 404 logger and logClientError() helper to suppress 404 WARN noise independently.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@milanmajchrak
milanmajchrak merged commit 355993d into customer/jcu Aug 26, 2026
11 checks passed
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