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.
Thank you for your reply. With log4j 1.3, both %c{0.0.*} and %c{..*}
worked.
In both the cases, output in the log looked like
..def.ghi - Message 1
..def.ghi - Message 2
..def - Message 3
..def - Message 4
I wonder, if there is a way to supress the ".." before def* ?
Thanks again,
Jayakumar
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]