I am having trouble establishing the exact difference between using those two log4j conversion characters when used in a log4j PatternLayout (log4j patternLayout)
- category (%c)
- class (%C)
Can someone please give me an example where those two would be different?
Doesn't the category always match the class name?
Regards,
It will be the same if you initialize the logger in the popular way suggested by the documentation, and use it inside the
Xclass:then you'll get the same for
%cand%C, because logger name (constructed by "com.foo.X.class.getName()") would match the class name where a logging statement was issued.Call your logger "something"
and you'll have "something" for
%cand the class name for%C.Note that
%Cis computed by log4j out of the current thread's stack trace, so it carries big performance impact, unlike%c, which is simply a String. You can conduct an interesting experiment to validate it:The output for pattern
[%c][%m]assumingBis in packagecom.foowill be:The output for pattern
[%C][%m]regardless of the location ofBwill be: