Skip to content
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

Logger precision formats in PatternLayout do not match documentation #2522

Open
jvz opened this issue Apr 25, 2024 · 0 comments
Open

Logger precision formats in PatternLayout do not match documentation #2522

jvz opened this issue Apr 25, 2024 · 0 comments
Labels
bug Incorrect, unexpected, or unintended behavior of existing code layouts Affects one or more Layout plugins

Comments

@jvz
Copy link
Member

jvz commented Apr 25, 2024

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 ]
@jvz jvz added bug Incorrect, unexpected, or unintended behavior of existing code layouts Affects one or more Layout plugins labels Apr 25, 2024
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 layouts Affects one or more Layout plugins
Projects
None yet
Development

No branches or pull requests

2 participants