You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-user@logging.apache.org by Ramakrishna S <rk...@yahoo-inc.com> on 2013/09/03 11:35:56 UTC

ConversionPattern to print process id and name in log4cxx

Hi All,

I have migrated customized logger to use log4cxx instead of log4cpp.
I have following ConversionPattern in config file which is working fine in the log4cpp but not in log4cxx.
log4cxx.appender.testlog.layout.ConversionPattern=%d{%Y/%m/%d %H:%M:%S %z %l} | %R | %P |%N| %c | %p | %x | %m%n

I got the following error with the above pattern.
log4cxx: Unrecognized conversion specifier [R] in conversion pattern.
log4cxx: Unrecognized format specifier P
log4cxx: Unrecognized conversion specifier [P] in conversion pattern.
log4cxx: Unrecognized format specifier N
log4cxx: Unrecognized conversion specifier [N] in conversion pattern.
log4cxx: Large window sizes are not allowed.

I have removed "%R", "%P", "%N" from conversion pattern then I didn't get the error.
Is there any replacement to print process id and process name(%P and %N) in log4cxx?

Thanks
Ramakrishna S


Re: ConversionPattern to print process id and name in log4cxx

Posted by "Jacob L. Anawalt" <ja...@geckosoftware.com>.
On 9/3/2013 3:35 AM, Ramakrishna S wrote:
> Is there any replacement to print process id and process name(%P and %N) in log4cxx?
>

I don't think there is process id and name in log4cxx since it is patterned 
after log4j where the name would be java or java.exe and the normal API doesn't 
give you it's process ID. I didn't notice a conversion for it under any of the 
PatternLayout conversion characters.

I'm not as up-to-date on log4cxx as I ought to be, but if the MDC (mapped 
diagnostic context) is supported in your version, you can configure key/value 
pairs for your "ProcessID" and "ProcessName" using C library calls to get the 
values early in the program startup, and then set your logging format to use 
%X{ProcessID} and %X{ProcessName}.

-- 
Jacob Anawalt
Gecko Software, Inc.
janawalt@geckosoftware.com
435-752-8026