logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "peter kwong" <l...@writeme.com>
Subject Re: Configuring FileAppender target file path programmatically after Property Configuration
Date Mon, 25 May 2009 18:08:59 GMT
 Assaf,
  You don't really need RTTI compiled in because the dynamic casting is
not needed.
The getAppender() result can be assigned to a subclass of Appender
without casting.
Here is basically what I did (I editted the original code to just show
the essence. There may
be typos in this):

    // First set up file name string called 'fname'.
   snprintf(fname, MAX_LOG_FILENAME_LEN,"%s/mb%s.log",
                  logDir,
                  baseName);

    log4cxx::helpers::Pool p;  // buffer pool that for activateOptions()
to use
    FileAppenderPtr fa=loggerHandle_->getLoggerRepository()->
                           
getRootLogger()->getAppender("MyRollingAppenderSize");
    if (fa == 0)
    {
        // If there is no appender, then this is a serious error.
        // Logging will not work at all.
        return (-1);
    }

    // Configures the output log file name.
    fa->setFile(fname);
    fa->activateOptions(p);



BTW, when I used a rolling file appender and used configuration from both
an XML file and
programmatic definition of the log file name, I would get a file called
".1" created every time I ran the program.
I suspect it has something to do with the rolling file appender trying to
create a <file>.1 file, but since the XML
file did not have the file name, only ".1" got created. It was created as
soon as the program ran, and
not when the log file got too large and needed rolling over.

This problem was fixed by doing all the configuration programmatically
(or all via XML).

peter

  ----- Original Message -----
  From: log4cxx
  To: "Log4CXX User"
  Subject: Re: Configuring FileAppender target file path
  programmatically after Property Configuration
  Date: Wed, 20 May 2009 07:53:47 -0400


  Hi Assaf,

  We have been using this solution posted by Micha for a long time
  now. It works very well for us, in both Windows and various Unix
  systems.

  -Andy

  http://mail-archives.apache.org/mod_mbox/logging-log4cxx-user/200509.mbox/%3Cloom.20050915T064039-998@post.gmane.org%3E

  > Hi all,
  >
  > Is it possible to configure log4cxx using a property configurator
  > file, but then override the destination path of one of the
  > FileAppenders in code?

  > I ask because I have many instances of the same process running
  > and each has to log to a different (dynamically determined) file
  > location, but I still want to control the pattern, level, etc.
  > from one configuration file.
  >
  > Thanks

-- 
Be Yourself @ mail.com!
Choose From 200+ Email Addresses
Get a Free Account at www.mail.com


Mime
View raw message