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 V Jayakumar <vj...@hotmail.com> on 2006/05/19 16:41:15 UTC
question on conversion character %c
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.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: question on conversion character %c
Posted by Curt Arnold <ca...@apache.org>.
On May 20, 2006, at 10:02 AM, V Jayakumar wrote:
>
> I wonder, if there is a way to supress the ".." before def* ?
>
> Thanks again,
> Jayakumar
I don't think so short of your writing a custom layout or pattern. I
don't see the use case being sufficiently general to try to support
in log4j itself.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: question on conversion character %c
Posted by V Jayakumar <vj...@hotmail.com>.
>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: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: question on conversion character %c
Posted by Curt Arnold <ca...@apache.org>.
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