You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Shawn Heisey <ap...@elyograg.org> on 2018/08/07 15:34:12 UTC

Changing %c logger abbrevation - can't figure out how to achieve what I'm after

Currently the logging pattern for Solr's log4j config contains "%c{1.}".

When the logger is "org.apache.solr.core.SolrCore.Request" the log 
contains "o.a.s.c.S.Request".  I would like it to contain 
"o.a.s.c.SolrCore.Request" instead.  When I change the precision 
specifier to "2.", "2.1", or "1.2", I get "or.ap.so.co.So.Request".  
That's more information, but isn't what I'm after.

The log4j version is 2.11.0.  Is it possible to achieve what I'm after 
with what exists now?  If not, should I open a new issue?

Thanks,
Shawn


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Changing %c logger abbrevation - can't figure out how to achieve what I'm after

Posted by Ralph Goers <ra...@dslextreme.com>.
You want to look at the NameAbbreviator class. It has sub-classes that perform the various styles of abbreviation.

Logback also has a name abbreviator where you specify a max length. Basically, the algorithm is, a) always print the full class name, b) if the length is large enough to contain the first letter of all the package names, include them, c) if the length is large enough expand the last package name to its full length, d) repeat c for each right-most package until the length would be exceeded.

Following this pattern you might be able to achieve what you are looking for. Unfortunately, the syntax Logback uses is exactly the same for what we use for the number of items. To solve this I would probably use a syntax like {length(10)} to use the algorithm above and create a MaxLengthAbbreviator.

For the specific syntax you are asking for, essentially you are trying to declare the number of right-most packages that you want expanded with all the others being a single character. So for that the syntax could be {right(1)}.

Mind you, these are just ideas. If you can come up with better algorithms or pattern syntax, have at it!

Ralph



> On Aug 7, 2018, at 1:55 PM, Shawn Heisey <ap...@elyograg.org> wrote:
> 
> On 8/7/2018 9:43 AM, Remko Popma wrote:
>> Feel free to submit a patch/pull request with unit tests! ;-)
> 
> I will open an issue.  I can certainly attempt a patch, but I can't make
> any guarantees.  I have to *understand* the code before I can modify it!
> Since I have never looked at log4j code, I expect the road to
> understanding will not be short.
> 
> What recommendations do you have about the precision specifier syntax to
> achieve output like o.a.s.c.SolrCore.Request?
> 
> Thanks,
> Shawn
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Changing %c logger abbrevation - can't figure out how to achieve what I'm after

Posted by Shawn Heisey <ap...@elyograg.org>.
On 8/7/2018 9:43 AM, Remko Popma wrote:
> Feel free to submit a patch/pull request with unit tests! ;-)

I will open an issue.  I can certainly attempt a patch, but I can't make
any guarantees.  I have to *understand* the code before I can modify it!
 Since I have never looked at log4j code, I expect the road to
understanding will not be short.

What recommendations do you have about the precision specifier syntax to
achieve output like o.a.s.c.SolrCore.Request?

Thanks,
Shawn

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Changing %c logger abbrevation - can't figure out how to achieve what I'm after

Posted by Remko Popma <re...@gmail.com>.
Feel free to submit a patch/pull request with unit tests! ;-)

(Shameless plug) Every java main() method deserves http://picocli.info

> On Aug 8, 2018, at 0:34, Shawn Heisey <ap...@elyograg.org> wrote:
> 
> Currently the logging pattern for Solr's log4j config contains "%c{1.}".
> 
> When the logger is "org.apache.solr.core.SolrCore.Request" the log contains "o.a.s.c.S.Request".  I would like it to contain "o.a.s.c.SolrCore.Request" instead.  When I change the precision specifier to "2.", "2.1", or "1.2", I get "or.ap.so.co.So.Request".  That's more information, but isn't what I'm after.
> 
> The log4j version is 2.11.0.  Is it possible to achieve what I'm after with what exists now?  If not, should I open a new issue?
> 
> Thanks,
> Shawn
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org