Skip to content

Respect log4j1.compatibility for programmatic configuration - #3812

Open
jhl221123 wants to merge 1 commit into
apache:2.xfrom
jhl221123:respect-compatibility-mode
Open

jhl221123 wants to merge 1 commit into
apache:2.xfrom
jhl221123:respect-compatibility-mode

Conversation

@jhl221123

Copy link
Copy Markdown
Contributor

This PR addresses issue #3667 by adding guard logic to methods in Category and LogManager that can modify the configuration. These changes ensure that programmatic configuration using the Log4j 1.x API is ignored unless the log4j1.compatibility flag is explicitly set to true.

I have confirmed the fix by running the reproducer provided in the issue, which now yields the following corrected output for the latest snapshot:

Testing 2.22.0
00:11:30.417 [main] INFO  org.example.App - Initializing Log4j 1.2 API...
00:11:30.423 [main] INFO  org.example.App - Log4j 1.2 API initialized.
Recorded 2 events (expected 2)

Testing 2.23.0
00:11:32.276 [main] INFO  org.example.App - Initializing Log4j 1.2 API...
Recorded 1 events (expected 2)

Testing 2.25.0
2025-07-09T15:11:36.970645Z main INFO Initializing Log4j 1.2 API...Recorded 1 events (expected 2)

Testing 2.26.0-SNAPSHOT
2025-07-09T15:11:39.258845Z main INFO Initializing Log4j 1.2 API...2025-07-09T15:11:39.262583Z main INFO Log4j 1.2 API initialized.Recorded 2 events (expected 2)

Additionally, I have updated the existing unit tests and added new tests to verify that the guard logic works as expected when the compatibility mode is disabled. I am not entirely confident that the new unit tests are perfect. Please let me know if there are any areas for improvement.

Checklist

Before we can review and merge your changes, please go through the checklist below. If you're still working on some items, feel free to submit your pull request as a draft—our CI will help guide you through the remaining steps.

✅ Required checks

  • License: I confirm that my changes are submitted under the Apache License, Version 2.0.

  • Commit signatures: All commits are signed and verifiable. (See GitHub Docs on Commit Signature Verification).

  • Code formatting: The code is formatted according to the project’s style guide.

    How to check and fix formatting
    • To check formatting: ./mvnw spotless:check
    • To fix formatting: ./mvnw spotless:apply

    See the build instructions for details.

  • Build & Test: I verified that the project builds and all unit tests pass.

    How to build the project

    Run: ./mvnw verify

    See the build instructions for details.

🧪 Tests (select one)

  • I have added or updated tests to cover my changes.
  • No additional tests are needed for this change.

📝 Changelog (select one)

  • I added a changelog entry in src/changelog/.2.x.x. (See Changelog Entry File Guide).
  • This is a trivial change and does not require a changelog entry.

@github-actions

github-actions Bot commented Jul 9, 2025

Copy link
Copy Markdown
Contributor
Job Requested goals Build Tool Version Build Outcome Build Scan®
build-macos-latest clean install 3.9.8 ❌ Build Scan PUBLISHED
build-ubuntu-latest clean install 3.9.8 ✅ Build Scan PUBLISHED
build-windows-latest clean install 3.9.8 ✅ Build Scan PUBLISHED
Generated by gradle/develocity-actions

@ramanathan1504 ramanathan1504 added bug Incorrect, unexpected, or unintended behavior of existing code java Pull requests that update Java code legacy-1.2-bridge port-done No further port needed: all required ports are merged, or none was needed labels Nov 7, 2026
@ramanathan1504 ramanathan1504 added this to the 2.27.0 milestone Nov 7, 2026
@ramanathan1504 ramanathan1504 added the priority: P2 Confirmed bug without event loss, hang, crash or leak label Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Incorrect, unexpected, or unintended behavior of existing code java Pull requests that update Java code legacy-1.2-bridge port-done No further port needed: all required ports are merged, or none was needed priority: P2 Confirmed bug without event loss, hang, crash or leak

Projects

Status: To triage

Development

Successfully merging this pull request may close these issues.

2 participants