logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Curt Arnold <carn...@apache.org>
Subject Re: question on conversion character %c
Date Fri, 19 May 2006 15:58:54 GMT

On May 19, 2006, at 9:41 AM, V Jayakumar wrote:

> In my pattern layout, if I use the conversion character %c, it  
> prints the value based on the category as expected:
>
> Example :
>
> com.abc.def.ghi - Message 1
> com.abc.def.ghi - Message 2
> com.abc.def - Message 3
> com.abc.def - Message 4
>
> My requirement is to see the log messages as
>
> def.ghi - Message 1
> def.ghi - Message 2
> def - Message 3
> def - Message 4
>
> i.e. I do not want the first two components of the category name
>
> Could someone explain how to achieve this, please ?
>
> Thanks in advance for the help.
>


There are several means to abbreviate category names using the  
PatternLayout.  In log4j 1.2, you could:

%.7c - print just the rightmost 7 characters
%c{2} - print the rightmost two parts of the name

In log4j 1.3, additional abbreviation syntax was added:

%c{1.} - will abbreviate the non-final parts of the name, resulting  
in "c.a.d.ghi" for example.
%c{1~.} - will abbreviate the non-final parts of the name and add a  
tilde when characters were dropped, resulting in "c~.a~.d~.ghi" for  
example.

 From a code review of NameAbbreviator (http://svn.apache.org/repos/ 
asf/logging/log4j/trunk/src/java/org/apache/log4j/pattern/ 
NameAbbreviator.java),
  it looks like either: %c{0.0.*}  or %c{..*} would do what you  
want.  The first two elements of the name would be output zero width  
and all remaining fields would not be abbreviated.  However, I have  
not tested that particular pattern.




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


Mime
View raw message