logging-log4j2 icon indicating copy to clipboard operation
logging-log4j2 copied to clipboard

LOG4J2-2785: Added support for pattern Layout to abbreviate logger or class names except n rightmost words

Open spannm opened this issue 3 years ago • 8 comments

Hi, I've added a specialized abbreviator named DynamicWordAbbreviator to address the specific requirement of this feature request. Javadoc added and JUnit test updated to cover the new feature.

spannm avatar Jul 01 '21 16:07 spannm

When I have some time to tinker, I think this feature could be added to the existing abbreviator. All existing patterns effectively use rightWordCount=1, however we could make that configurable and allow existing options to work with this.

Something along the lines of

int limit = input.length();
for (int i = 0; I < rightWordCount; I++) {
    limit = input.lastIndexOf('.', limit);
    if (limit < 0) {
        return input;
    }
}
// call into standard abbreviator.

carterkozak avatar Aug 12 '21 01:08 carterkozak

[..] All existing patterns effectively use rightWordCount=1, however we could make that configurable and allow existing options to work with this.

@carterkozak I don't think this is the case. Consider patterns such as 1.1.1.*. The number of unmodified words at the right side depends on the length of the string to be abbreviated, not on the pattern. NameAbbreviator is abstract. Implementations are MaxElementAbbreviator and PatternAbbreviator. I don't see a good way of covering the feature request within these two implementations, and have therefore added DynamicWordAbbreviator.

spannm avatar Aug 27 '21 16:08 spannm

@carterkozak Here's another small update to my pull request. Can you merge it into the release branch please?

spannm avatar Sep 08 '21 06:09 spannm

"we love pull requests" they say you send them prs you listen to their criticism you incorporate their feedback you think you're done then nothing happens forever wtf

spannm avatar Feb 02 '22 18:02 spannm

@sman-81 we are all volunteers and have limited time to devote to review. Your most recent comment comes across as entitled and rude. Please work on that. In your position, I might have replied on the PR with "Is there anything I can do to get this into a mergable state?"

you listen to their criticism you incorporate their feedback

I asked you twice to avoid string.split in favor of indexOf/lastIndexOf, but it's still used.

carterkozak avatar Feb 03 '22 01:02 carterkozak

@carterkozak

I'm a volunteer just like you. My pull request is from July 1st, thus seven months old by now! The last comment from anyone other than me was August 12, 2021. Such discourages people from contributing to the project.

I asked you twice to avoid string.split in favor of indexOf/lastIndexOf, but it's still used.

And you are wrong. String#split does not create a Pattern object for certain one-character patterns such as here, as I have pointed out to you (see comment on August 5, 2021).

spannm avatar Feb 03 '22 05:02 spannm

The point is that string.split is inefficient, regardless of internal details because it's allocating several new strings unnecessarily.

carterkozak avatar Feb 03 '22 15:02 carterkozak

Hi there @carterkozak now String#split is gone. I have also squashed commits into one. Please take a look.

spannm avatar Feb 04 '22 08:02 spannm

This patch was manually extracted and merged since the backing repo has been deleted.

rgoers avatar Dec 30 '22 19:12 rgoers

Hard to believe my PR actually got merged after a little over 1,5 years :)

spannm avatar Jan 03 '23 13:01 spannm