Skip to content

Documentation Update for Logger Layout Pattern Precision Example #3744

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 2 commits into
base: 2.x
Choose a base branch
from

Conversation

zengshengliu
Copy link

@zengshengliu zengshengliu commented Jun 13, 2025

Correct logger precision example.
The current example is incorrect.
%c{1.2.*} does not return o.a.commons.test.Foo due to the extra period before *, instead, it will use 1.2 as the pattern and shows o.ap.commons.Foo
To get the output o.a.commons.test.Foo, the formatter needs to be %c{1.3*} where the 3* indicates number of right most token to be printed in full. (bullet point 2 in the doc)

Pattern Logger name Output Explanation
%c{1.1*} org.apache.commons.Foo o.a.c.Foo abbreviate using 1 character, show last item in full
%c{1.1.*} org.apache.commons.Foo o.a.commons.Foo first two items abbreviate with 1 character, rest in full
%c{1.2*} org.apache.commons.Foo o.a.commons.Foo abbreviate using 1 character, show last two items in full
%c{1.2.*} org.apache.commons.Foo o.ap.commons.Foo first item with 1 character, second with 2 character, rest is full

I do have a question/issue? where that logic only works if the number before the first period is 1, so
%c{1.1*} >> o.a.c.Foo
%c{1.2*} >> o.a.commons.Foo
%c{1.3*} >> o.apache.commons.Foo
works, but
%c{2.1*} >> or.a*.c*.Foo
%c{2.2*} >> or.ap*.co*.Foo
%c{2.3*} >> or.apa*.com*.Foo
does not work as expected.

Important

Base your changes on 2.x branch if you are targeting Log4j 2; use main otherwise.

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.

Correct logger precision example
@zengshengliu zengshengliu marked this pull request as ready for review June 13, 2025 16:09
Copy link

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

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.

1 participant