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

Enable simple class name in logger name customization #747

Closed
twessendorf opened this issue Jan 20, 2022 · 1 comment · Fixed by #748
Closed

Enable simple class name in logger name customization #747

twessendorf opened this issue Jan 20, 2022 · 1 comment · Fixed by #748
Labels
Milestone

Comments

@twessendorf
Copy link

Is your feature request related to a problem? Please describe.
I didn't succeed in shortening the logger name to simple class name. Although it is stated that shortenedLoggerNameLength behaves similar to normal pattern style, <shortenedLoggerNameLength>0</shortenedLoggerNameLength> doesn't result in simple class name as %logger{0} does. In fact, foo.bar.baz.MyClass is shortened to f.b.b.MyClass instead of MyClass.

Describe the solution you'd like
I'd like shortenedLoggerNameLength to behave the same way as normal pattern style for 0 parameter to enable simple class name logger customization.

@brenuart
Copy link
Collaborator

Hi @twessendorf ,

First of all, sorry for the late answer :-(
Secondly, there is indeed a problem with how the logger name is shortened when the length is set to 0 (as you noticed). It works however as expected when the length is greater than zero.

As a workaround you can make use of the PatternJsonProvider as shown below:

<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
    <providers>
        <pattern>
            <pattern>
                { "logger": "%logger{0}" }
            </pattern>
        </pattern>
    </providers>
</encoder>

Note that you cannot rely on the LogstashEncoder and you will have to redefine all the required JsonProviders manually...

@brenuart brenuart added this to the 7.1 milestone Jan 24, 2022
brenuart added a commit that referenced this issue Jan 24, 2022
`ClassNameOnlyAbbreviator` should be used instead of `TargetLengthBasedClassNameAbbreviator` when the desired length is set to `0`.

Closes #747
brenuart added a commit that referenced this issue Jan 24, 2022
`ClassNameOnlyAbbreviator` should be used instead of `TargetLengthBasedClassNameAbbreviator` when the desired length is set to `0`.

Closes #747
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants