Hi Ramakrishna,

We add the Process Id to our file names using environment variables. I'm not 
sure if this will work in your conversion 
pattern. If it does, please let the list know.

To do this in log4cxx, before initializing, I add an environment variable at 
the start of the program:

#ifdef _MSC_VER
long processId = _getpid();
char logpid[20];
sprintf_s(logpid, "LOGPID=%ld", processId);
_putenv(logpid);
#else
long processId = getpid();
char logpid[20];
sprintf(logpid, "LOGPID=%ld", processId);
putenv(logpid);
#endif //_MSC_VER

Then in my configuration file I do:
  <appender name="RFA" class="org.apache.log4j.rolling.RollingFileAppender">
    <rollingPolicy class="org.apache.log4j.rolling.FixedWindowRollingPolicy">
      <param name="activeFileName" value="MyApp_${LOGPID}.log"/>
      <param name="fileNamePattern" value="MyApp_${LOGPID}.log.%i"/>
      <param name="minIndex" value="0"/>
      <param name="maxIndex" value="5"/>
    </rollingPolicy>
    <triggeringPolicy 
class="org.apache.log4j.rolling.SizeBasedTriggeringPolicy">
      <param name="MaxFileSize" value="30MB"/>
    </triggeringPolicy>
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%d{MM/dd HH:mm:ss.SSS} %c - %m%n"/>
    </layout>
    <param name="file" value="MyApp_${LOGPID}.log"/>
    <param name="append" value="false"/>
  </appender>

You could try:
log4cxx.appender.testlog.layout.ConversionPattern=%d{%Y/%m/%d %H:%M:%S %z %l} | 
${LOGPROCESS} | 
${LOGPID} |%N| %c | 
%p | %x | %m%n

-Andy

On Tue, Sep 3, 2013 at 5:35 AM, Ramakrishna S <r...@yahoo-inc.com> wrote:
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
 

Reply via email to