[ 
https://issues.apache.org/jira/browse/LOG4J2-621?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15251527#comment-15251527
 ] 

Kamal Mettananda edited comment on LOG4J2-621 at 4/21/16 8:16 AM:
------------------------------------------------------------------

Hi all

I looked at this request which seems to be a very useful feature IMHO, 
specially given that it provides a way to remove the first known packages list 
from the Logger name or caller's name in [Patter 
Layout|http://logging.apache.org/log4j/2.x/manual/layouts.html#PatternLayout].

It seems we can implement this change by supporting a negative integer in the 
precision section of the following pattern configurations.

* c\{precision}
* logger\{precision}
* C\{precision}
* class\{precision}

So the sample configurations after this feature addition would look like below.

*Logger name:* org.apache.logging.log4j.core.pattern.LoggerName
*Caller's name:* org.apache.logging.log4j.core.pattern.CallerClass
*Log message:* This is a test message.


||Configuration || Output ||
| %c{-1} %m| apache.logging.log4j.core.pattern.LoggerName This is a test 
message.| 
| %c{-3} %m| log4j.core.pattern.LoggerName This is a test message.| 
| %c{-20} %m| org.apache.logging.log4j.core.pattern.LoggerName This is a test 
message.| 
| %logger{-1} %m| apache.logging.log4j.core.pattern.LoggerName This is a test 
message.| 
| %C{-1} %m| apache.logging.log4j.core.pattern.CallerClass This is a test 
message.| 
| %C{-3} %m| log4j.core.pattern.CallerClass This is a test message.| 
| %C{-20} %m| org.apache.logging.log4j.core.pattern.CallerClass This is a test 
message.| 
| %class{-1} %m| apache.logging.log4j.core.pattern.CallerClass This is a test 
message.| 



was (Author: lkamal):
Hi all

I looked at this request which seems to be a very useful feature IMHO, 
specially given that it provides a way to remove the first known packages list 
from the Logger name or caller's name in [Patter 
Layout|http://logging.apache.org/log4j/2.x/manual/layouts.html#PatternLayout].

It seems we can implement this change by supporting a negative integer in the 
precision section of the following pattern configurations.

* c\{precision}
* logger\{precision}
* C{precision}
* class{precision}


> Pattern To Drop First X Package Parts
> -------------------------------------
>
>                 Key: LOG4J2-621
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-621
>             Project: Log4j 2
>          Issue Type: Wish
>          Components: Layouts
>    Affects Versions: 2.0-rc1
>            Reporter: Lee Theobald
>            Priority: Trivial
>
> Currently you can have a pattern that will print out the last X parts of you 
> package.  So if my package was {{uk.co.ltheobald.foo.bar}}, then using 
> {{%logger\{2\}}} will print {{foo.bar}}.  But when I have a number of 
> different package levels, this becomes less useful (in my opinion).
> What I'd find more useful is the inverse where I can ditch the first X parts. 
>  Something like {{%logger\{-3\}}} for example.  That way I'd end up with:
> {{uk.co.ltheobald.Main logging}} as {{Main}}
> {{uk.co.ltheobald.foo.MyClass}} logging as {{foo.MyClass}}
> {{uk.co.ltheobald.foo.bar.MyOtherClass}} logging as {{foo.bar.MyOtherClass}}
> Removing from the start of the logger name allows me to consistently trim off 
> package names that I know are always the same.  I'll see if I can produce a 
> code example for this if I get time but I wanted to log it in the meanwhile.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to