logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "log4cxx" <log4...@gallandfamily.com>
Subject Re: Create a new log file at every start of the programm
Date Mon, 20 Aug 2007 21:22:04 GMT
I know it's not exactly what you are looking for, but perhaps you can adapt a method that we
use in our projects. We have many instances running of the same program, and for historical
purposes, always named log files with the Process ID in them to keep them separate. To do
this in log4cxx, before initializing, I add an environment variable:

#ifdef _MSC_VER
	long processId = _getpid();
	char logpid[20];
	sprintf_s(logpid, "LOGPID=%ld", processId);
	long processId = getpid();
	char logpid[20];
	sprintf(logpid, "LOGPID=%ld", processId);
#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"/>
    <triggeringPolicy class="org.apache.log4j.rolling.SizeBasedTriggeringPolicy">
      <param name="MaxFileSize" value="30MB"/>
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%d{MM/dd HH:mm:ss.SSS} %c - %m%n"/>
    <param name="file" value="MyApp_${LOGPID}.log"/>
    <param name="append" value="false"/>

I'm not sure who handles it (log4cxx or the system), but somehow the variable gets properly

Hope this helps.


You wrote:

    Hi Anand,

    thanks for your reply. But I think it should be a normal function for a
    logging library to create logfiles for each start of an application. The
    renaming was only an example. Of course it would also be okay using the
    rollOver Function of log4cxx.

    But logging seems either size or time related.

    Hm, if there's no alternative I've got to do it my own.

    Best regards,

Hi Alex,

Did you find solution to your problem? Can you please share it?


View raw message