Skip to content

Feature/2.x/enumerating and exposing named patters #3789

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

Conversation

ashr123
Copy link

@ashr123 ashr123 commented Jun 28, 2025

I've created an enum for named patterns, that way I think it will be easier to maintain.
In addition the enum modifier is public because it lets users to reuse those patterns in there application

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

I got the following error:

[ERROR] Failed to execute goal biz.aQute.bnd:bnd-baseline-maven-plugin:7.1.0:baseline (check-api-compat) on project log4j-core: An error occurred while calculating the baseline: Baseline problems detected. See the report in /Users/royash/IdeaProjects/logging-log4j2/log4j-core/target/baseline/log4j-core-2.26.0-SNAPSHOT.txt.
[ERROR] ===============================================================
[ERROR]   Name                                               Type       Delta      New        Old        Suggest    
[ERROR]   org.apache.logging.log4j.core                      BUNDLE     MAJOR      2.26.0.SNAPSHOT 2.25.0     -          
[ERROR] ===============================================================
[ERROR]   Name                                               Type       Delta      New        Old        Suggest    If Prov.
[ERROR]   org.apache.logging.log4j.core                      PACKAGE    UNCHANGED  2.24.2     2.24.2     ok         -
[ERROR]   org.apache.logging.log4j.core.appender             PACKAGE    MINOR      2.26.0     2.20.3     ok         -
[ERROR]   org.apache.logging.log4j.core.appender.db          PACKAGE    UNCHANGED  2.21.0     2.21.0     ok         -
[ERROR]   org.apache.logging.log4j.core.appender.db.jdbc     PACKAGE    UNCHANGED  2.20.1     2.20.1     ok         -
[ERROR]   org.apache.logging.log4j.core.appender.mom         PACKAGE    UNCHANGED  2.25.0     2.25.0     ok         -
[ERROR]   org.apache.logging.log4j.core.appender.mom.jeromq  PACKAGE    UNCHANGED  2.21.0     2.21.0     ok         -
[ERROR]   org.apache.logging.log4j.core.appender.mom.kafka   PACKAGE    UNCHANGED  2.20.1     2.20.1     ok         -
[ERROR]   org.apache.logging.log4j.core.appender.nosql       PACKAGE    UNCHANGED  2.20.1     2.20.1     ok         -
[ERROR]   org.apache.logging.log4j.core.appender.rewrite     PACKAGE    UNCHANGED  2.20.1     2.20.1     ok         -
[ERROR]   org.apache.logging.log4j.core.appender.rolling     PACKAGE    MINOR      2.26.0     2.21.1     ok         -
[ERROR]   org.apache.logging.log4j.core.appender.rolling.action PACKAGE    MINOR      2.26.0     2.24.0     ok         -
[ERROR]   org.apache.logging.log4j.core.appender.routing     PACKAGE    MINOR      2.26.0     2.20.1     ok         -
[ERROR]   org.apache.logging.log4j.core.async                PACKAGE    MINOR      2.26.0     2.25.0     ok         -
[ERROR]   org.apache.logging.log4j.core.config               PACKAGE    MINOR      2.26.0     2.25.0     ok         -
[ERROR]   org.apache.logging.log4j.core.config.arbiters      PACKAGE    UNCHANGED  2.21.0     2.21.0     ok         -
[ERROR]   org.apache.logging.log4j.core.config.builder.api   PACKAGE    UNCHANGED  2.25.0     2.25.0     ok         -
[ERROR]   org.apache.logging.log4j.core.config.builder.impl  PACKAGE    UNCHANGED  2.25.0     2.25.0     ok         -
[ERROR]   org.apache.logging.log4j.core.config.composite     PACKAGE    UNCHANGED  2.20.1     2.20.1     ok         -
[ERROR]   org.apache.logging.log4j.core.config.json          PACKAGE    UNCHANGED  2.20.1     2.20.1     ok         -
[ERROR]   org.apache.logging.log4j.core.config.plugins       PACKAGE    UNCHANGED  2.20.1     2.20.1     ok         -
[ERROR]   org.apache.logging.log4j.core.config.plugins.convert PACKAGE    UNCHANGED  2.24.0     2.24.0     ok         -
[ERROR]   org.apache.logging.log4j.core.config.plugins.processor PACKAGE    UNCHANGED  2.25.0     2.25.0     ok         -
[ERROR]   org.apache.logging.log4j.core.config.plugins.util  PACKAGE    UNCHANGED  2.20.2     2.20.2     ok         -
[ERROR]   org.apache.logging.log4j.core.config.plugins.validation PACKAGE    UNCHANGED  2.20.1     2.20.1     ok         -
[ERROR]   org.apache.logging.log4j.core.config.plugins.validation.constraints PACKAGE    UNCHANGED  2.20.1     2.20.1     ok         -
[ERROR]   org.apache.logging.log4j.core.config.plugins.validation.validators PACKAGE    UNCHANGED  2.20.1     2.20.1     ok         -
[ERROR]   org.apache.logging.log4j.core.config.plugins.visitors PACKAGE    UNCHANGED  2.20.1     2.20.1     ok         -
[ERROR]   org.apache.logging.log4j.core.config.properties    PACKAGE    UNCHANGED  2.20.1     2.20.1     ok         -
[ERROR]   org.apache.logging.log4j.core.config.status        PACKAGE    UNCHANGED  2.20.2     2.20.2     ok         -
[ERROR]   org.apache.logging.log4j.core.config.xml           PACKAGE    UNCHANGED  2.20.2     2.20.2     ok         -
[ERROR]   org.apache.logging.log4j.core.config.yaml          PACKAGE    UNCHANGED  2.20.1     2.20.1     ok         -
[ERROR]   org.apache.logging.log4j.core.filter               PACKAGE    UNCHANGED  2.25.0     2.25.0     ok         -
[ERROR]   org.apache.logging.log4j.core.filter.mutable       PACKAGE    UNCHANGED  2.20.1     2.20.1     ok         -
[ERROR]   org.apache.logging.log4j.core.impl                 PACKAGE    UNCHANGED  2.24.1     2.24.1     ok         -
[ERROR]   org.apache.logging.log4j.core.jackson              PACKAGE    UNCHANGED  2.24.1     2.24.1     ok         -
[ERROR]   org.apache.logging.log4j.core.jmx                  PACKAGE    UNCHANGED  2.23.0     2.23.0     ok         -
[ERROR]   org.apache.logging.log4j.core.layout               PACKAGE    MINOR      2.26.0     2.25.0     ok         -
[ERROR]   org.apache.logging.log4j.core.lookup               PACKAGE    UNCHANGED  2.24.1     2.24.1     ok         -
[ERROR]   org.apache.logging.log4j.core.net                  PACKAGE    UNCHANGED  2.20.3     2.20.3     ok         -
[ERROR]   org.apache.logging.log4j.core.net.ssl              PACKAGE    UNCHANGED  2.20.3     2.20.3     ok         -
[ERROR]   org.apache.logging.log4j.core.osgi                 PACKAGE    UNCHANGED  2.20.1     2.20.1     ok         -
[ERROR]   org.apache.logging.log4j.core.parser               PACKAGE    UNCHANGED  2.20.1     2.20.1     ok         -
[ERROR] * org.apache.logging.log4j.core.pattern              PACKAGE    MINOR      2.24.1     2.24.1     2.25.0     -
[ERROR]   MINOR                PACKAGE    org.apache.logging.log4j.core.pattern
[ERROR]     ADDED              ENUM       org.apache.logging.log4j.core.pattern.NamedPattern
[ERROR]       ADDED            ACCESS     final
[ERROR]       ADDED            EXTENDS    java.lang.Enum
[ERROR]       ADDED            IMPLEMENTS java.io.Serializable
[ERROR]       ADDED            IMPLEMENTS java.lang.Comparable
[ERROR]       ADDED            IMPLEMENTS java.lang.constant.Constable
[ERROR]       ADDED            FIELD      ABSOLUTE
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          ACCESS     static
[ERROR]         ADDED          RETURN     org.apache.logging.log4j.core.pattern.NamedPattern
[ERROR]       ADDED            FIELD      ABSOLUTE_MICROS
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          ACCESS     static
[ERROR]         ADDED          RETURN     org.apache.logging.log4j.core.pattern.NamedPattern
[ERROR]       ADDED            FIELD      ABSOLUTE_NANOS
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          ACCESS     static
[ERROR]         ADDED          RETURN     org.apache.logging.log4j.core.pattern.NamedPattern
[ERROR]       ADDED            FIELD      ABSOLUTE_PERIOD
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          ACCESS     static
[ERROR]         ADDED          RETURN     org.apache.logging.log4j.core.pattern.NamedPattern
[ERROR]       ADDED            FIELD      COMPACT
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          ACCESS     static
[ERROR]         ADDED          RETURN     org.apache.logging.log4j.core.pattern.NamedPattern
[ERROR]       ADDED            FIELD      DATE
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          ACCESS     static
[ERROR]         ADDED          RETURN     org.apache.logging.log4j.core.pattern.NamedPattern
[ERROR]       ADDED            FIELD      DATE_PERIOD
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          ACCESS     static
[ERROR]         ADDED          RETURN     org.apache.logging.log4j.core.pattern.NamedPattern
[ERROR]       ADDED            FIELD      DEFAULT
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          ACCESS     static
[ERROR]         ADDED          RETURN     org.apache.logging.log4j.core.pattern.NamedPattern
[ERROR]       ADDED            FIELD      DEFAULT_MICROS
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          ACCESS     static
[ERROR]         ADDED          RETURN     org.apache.logging.log4j.core.pattern.NamedPattern
[ERROR]       ADDED            FIELD      DEFAULT_NANOS
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          ACCESS     static
[ERROR]         ADDED          RETURN     org.apache.logging.log4j.core.pattern.NamedPattern
[ERROR]       ADDED            FIELD      DEFAULT_PERIOD
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          ACCESS     static
[ERROR]         ADDED          RETURN     org.apache.logging.log4j.core.pattern.NamedPattern
[ERROR]       ADDED            FIELD      ISO8601
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          ACCESS     static
[ERROR]         ADDED          RETURN     org.apache.logging.log4j.core.pattern.NamedPattern
[ERROR]       ADDED            FIELD      ISO8601_BASIC
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          ACCESS     static
[ERROR]         ADDED          RETURN     org.apache.logging.log4j.core.pattern.NamedPattern
[ERROR]       ADDED            FIELD      ISO8601_BASIC_PERIOD
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          ACCESS     static
[ERROR]         ADDED          RETURN     org.apache.logging.log4j.core.pattern.NamedPattern
[ERROR]       ADDED            FIELD      ISO8601_OFFSET_DATE_TIME_HH
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          ACCESS     static
[ERROR]         ADDED          RETURN     org.apache.logging.log4j.core.pattern.NamedPattern
[ERROR]       ADDED            FIELD      ISO8601_OFFSET_DATE_TIME_HHCMM
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          ACCESS     static
[ERROR]         ADDED          RETURN     org.apache.logging.log4j.core.pattern.NamedPattern
[ERROR]       ADDED            FIELD      ISO8601_OFFSET_DATE_TIME_HHMM
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          ACCESS     static
[ERROR]         ADDED          RETURN     org.apache.logging.log4j.core.pattern.NamedPattern
[ERROR]       ADDED            FIELD      ISO8601_PERIOD
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          ACCESS     static
[ERROR]         ADDED          RETURN     org.apache.logging.log4j.core.pattern.NamedPattern
[ERROR]       ADDED            FIELD      ISO8601_PERIOD_MICROS
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          ACCESS     static
[ERROR]         ADDED          RETURN     org.apache.logging.log4j.core.pattern.NamedPattern
[ERROR]       ADDED            FIELD      US_MONTH_DAY_YEAR2_TIME
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          ACCESS     static
[ERROR]         ADDED          RETURN     org.apache.logging.log4j.core.pattern.NamedPattern
[ERROR]       ADDED            FIELD      US_MONTH_DAY_YEAR4_TIME
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          ACCESS     static
[ERROR]         ADDED          RETURN     org.apache.logging.log4j.core.pattern.NamedPattern
[ERROR]       ADDED            METHOD     clone()
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          ACCESS     protected
[ERROR]         ADDED          RETURN     java.lang.Object
[ERROR]       ADDED            METHOD     compareTo(java.lang.Enum)
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          RETURN     int
[ERROR]       ADDED            METHOD     compareTo(java.lang.Object)
[ERROR]         ADDED          ACCESS     abstract
[ERROR]         ADDED          RETURN     int
[ERROR]       ADDED            METHOD     describeConstable()
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          RETURN     java.util.Optional
[ERROR]       ADDED            METHOD     equals(java.lang.Object)
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          RETURN     boolean
[ERROR]       ADDED            METHOD     finalize()
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          ACCESS     protected
[ERROR]         ADDED          RETURN     void
[ERROR]       ADDED            METHOD     getDeclaringClass()
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          RETURN     java.lang.Class
[ERROR]       ADDED            METHOD     getLegacyPattern()
[ERROR]         ADDED          RETURN     java.lang.String
[ERROR]       ADDED            METHOD     getNonLegacyPattern()
[ERROR]         ADDED          RETURN     java.lang.String
[ERROR]       ADDED            METHOD     hashCode()
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          RETURN     int
[ERROR]       ADDED            METHOD     name()
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          RETURN     java.lang.String
[ERROR]       ADDED            METHOD     ordinal()
[ERROR]         ADDED          ACCESS     final
[ERROR]         ADDED          RETURN     int
[ERROR]       ADDED            METHOD     toString()
[ERROR]         ADDED          RETURN     java.lang.String
[ERROR]       ADDED            METHOD     valueOf(java.lang.String)
[ERROR]         ADDED          ACCESS     static
[ERROR]         ADDED          RETURN     org.apache.logging.log4j.core.pattern.NamedPattern
[ERROR]       ADDED            METHOD     values()
[ERROR]         ADDED          ACCESS     static
[ERROR]         ADDED          RETURN     org.apache.logging.log4j.core.pattern.NamedPattern[]
[ERROR]   org.apache.logging.log4j.core.script               PACKAGE    MINOR      2.26.0     2.20.2     ok         -
[ERROR]   org.apache.logging.log4j.core.selector             PACKAGE    UNCHANGED  2.20.1     2.20.1     ok         -
[ERROR]   org.apache.logging.log4j.core.time                 PACKAGE    UNCHANGED  2.20.1     2.20.1     ok         -
[ERROR]   org.apache.logging.log4j.core.tools                PACKAGE    UNCHANGED  2.20.1     2.20.1     ok         -
[ERROR]   org.apache.logging.log4j.core.util                 PACKAGE    UNCHANGED  2.25.0     2.25.0     ok         -
[ERROR]   org.apache.logging.log4j.core.util.datetime        PACKAGE    UNCHANGED  2.21.2     2.21.2     ok         -
[ERROR]   org.apache.logging.log4j.core.util.internal.instant PACKAGE    UNCHANGED  2.25.0     2.25.0     ok         -
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :log4j-core
See [the build instructions](https://logging.apache.org/log4j/2.x/development.html#building) 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.

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 @ashr123,

Thanks for the PR!

From my perspective, this refactoring does improve the readability of the decodeNamedPattern method—cleaner logic and better structure are always welcome. That said, readability can be subjective, so I'd also like to hear what @vy (the original author) thinks about the change.

Regarding the visibility of the new NamedPattern enum: as I mentioned in #3788 (reply in thread):

I'm not sure there's a strong case for making such an enum public. Unless there's a clear user-facing need, we prefer to keep our API surface area minimal.

Would it be possible to make the NamedPattern enum package-private? Or would that conflict with the purpose of your change?

Currently, the PR triggers an API compatibility check failure:

[ERROR]   Name                                               Type       Delta      New        Old        Suggest    If Prov.
[ERROR] * org.apache.logging.log4j.core.pattern              PACKAGE    MINOR      2.24.1     2.24.1     2.25.0     -
[ERROR]   MINOR                PACKAGE    org.apache.logging.log4j.core.pattern
[ERROR]     ADDED              ENUM       org.apache.logging.log4j.core.pattern.NamedPattern

This is caused by our BND Baseline mechanism, which flags any additions to the public API. If you do intend to make NamedPattern public, you'll need to update the @Version annotation in the package-info.java file for the org.apache.logging.log4j.core.pattern package. If not, making the enum package-private would avoid triggering this check.

Looking forward to your thoughts!

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

@ashr123
Copy link
Author

ashr123 commented Jun 30, 2025

@ppkarwasz I see…
From my perspective this PR have 2 purposes:

  1. Introduce mechanism for internal reuse and maintain named-patterns more easly
  2. optionally, let other developers reuse those patterns (it's not conflicting with the purpose of my PR)

I'm also curious to find out what @vy thinks about it and I'll do whatever you decide

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