Skip to content

Fix: Ensure jvmrunargs lookup is always registered (fixes #2726) #3874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: 2.x
Choose a base branch
from

Conversation

ramanathan1504
Copy link

This pull request introduces support for a new jvmrunargs lookup in Log4j, allowing users to access JVM runtime arguments via configuration and lookups. The changes include registering the new lookup in the Interpolator, adding tests to verify its registration and behavior, and providing a sample configuration file that demonstrates its usage.

New JVM Runtime Arguments Lookup:

  • Registered the jvmrunargs lookup in the Interpolator class, enabling retrieval of JVM arguments through ${jvmrunargs:...} expressions in Log4j configurations.

Testing and Verification:

  • Added JvmRunArgsLookupTest to verify that the jvmrunargs lookup is registered and behaves as expected, including null and non-null cases.
  • Introduced JvmRunArgsIntegrationTest to ensure the lookup works correctly within a logging configuration.

Configuration Example:

  • Added a sample log4j2-test.xml configuration file that demonstrates how to use the new jvmrunargs lookup in a pattern layout for console output.

Copy link
Contributor

@ppkarwasz ppkarwasz left a comment

Choose a reason for hiding this comment

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

Hi @ramanathan1504,

Thanks for the PR! 💯

From what I can tell, the jvmrunargs lookup was already fixed in version 2.25.0, so the main code changes here may not be needed. However, the unit tests you’ve added are very valuable. They’ll help ensure the lookup keeps working. The absence of such tests is likely why a feature that never fully worked managed to ship in so many releases.

Could you:

  • Remove the main code changes but keep JvmRunArgsLookupTest.
  • Consider adding documentation for jvmrunargs (either in this PR or in a follow-up). See #3876 for details.

Copy link

github-actions bot commented Aug 10, 2025

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

….25.0

- Documented `jvmrunargs` lookup in `lookups.adoc` with usage examples.
- Verified that the lookup works correctly in Log4j 2.25.0 using sample app and JVM args.
- Included example configuration demonstrating retrieval of JVM runtime arguments.

Closes apache#2726
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: To triage
Development

Successfully merging this pull request may close these issues.

2 participants