Skip to content

Logger precision formats in PatternLayout do not match documentation #2522

Open
@jvz

Description

@jvz

Description

In the docs at https://logging.apache.org/log4j/2.x/manual/layouts.html#patterns it gives an example pattern %c{1.2.*} that should transform something like org.apache.commons.test.Foo to o.a.c.test.Foo, but I'm seeing it transform into o.ap.commons.test.Foo instead.

In general, the configuration I want here is to collapse all the parts of the package name to single letters except for the last package name part before the class name which is what that example precision looks to do.

Configuration

Version: 2.23.1

Operating system: macOS

JDK: Java 21

Logs

[Stacktraces, errors, etc. relevant applications logs.]

Reproduction

Use %c{1.2.*} in a pattern layout with a logger name such as org.apache.logging.log4j.core.config.AbstractConfiguration which should output o.a.l.l.c.config.AbstractConfiguration. Sample config snippet:

<Configuration status="warn">
    <Properties>
        <Property name="app-log-level">${sys:app-logging-level:-info}</Property>
    </Properties>
    <Appenders>
                <Console name="console" target="SYSTEM_ERR">
                    <PatternLayout
                            pattern="%highlight{%d{ABSOLUTE} [%level{length=3}] %style{%msg}{bright}}%n\t%style{[File: %c{1.2.*}:%-3L] - [Method: %-30.30M] - [Thread: %-40.40threadName]%n\t[Context: %MDC]}{black,bright}%n%style{%rThrowable{filters(${sys:suppressPackages:-...})}}{red}"/>
                </Console>
</Appenders>
<Loggers>
        <Root level="${sys:logging-level:-info}" additivity="false">
            <AppenderRef ref="console"/>
        </Root>
</Loggers>
</Configuration>

Example output:

[File: c.fo.bar.bazzzle.AResourceLogger:52 ]

Expected output:

[File: c.f.b.bazzzle.AResourceLogger:52 ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIncorrect, unexpected, or unintended behavior of existing codelayoutsAffects one or more Layout plugins

    Type

    No type

    Projects

    Status

    To triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions