Hi ,
     I'm using lo4cxx to in an environment that variable users making logs
,so not releasing the resources after the using of Appenders is really a
disaster .
     But ,I'm confused with the two ways of removing Appenders.When I keep
generating Appenders and releasing them with the removeAppender(),the memory
 will not increase ,while the memory usage keeps growing as using  the
removeAllAppenders() .

    I wonder how this two accomplish their removing actions.

    And here are my test codes.Thanks !

#include <log4cxx/logger.h>

#include <log4cxx/propertyconfigurator.h>
#include <log4cxx/logger.h>
#include <log4cxx/basicconfigurator.h>
#include <log4cxx/patternlayout.h>
#include <log4cxx/consoleappender.h>
#include <log4cxx/fileappender.h>
#include <log4cxx/rollingfileappender.h>
#include <log4cxx/asyncappender.h>
#include <log4cxx/dailyrollingfileappender.h>
#include <log4cxx/propertyconfigurator.h>
#include <log4cxx/ndc.h>

using namespace log4cxx;


using namespace std;

using namespace log4cxx;



int main(int argc, char* argv[])

{
LoggerPtr r_logPtr;
 log4cxx::LogString conversionPattern;


conversionPattern = "%d{%m/%d %H:%M:%S} %m %n";


int count = 0;

while(1)
{
 {
            log4cxx::PatternLayoutPtr layout(new
log4cxx::PatternLayout(conversionPattern));
            log4cxx::RollingFileAppenderPtr file(new
log4cxx::RollingFileAppender(layout, log4cxx::LogString("abc.log"), true));
            file->setName("a");
            file->setMaxBackupIndex(10);
            file->setMaxFileSize(log4cxx::LogString("10MB"));
      log4cxx::helpers::Pool p;
     file->activateOptions(p);
     char buf[128];
       sprintf(buf, "%d", count++%10);
      r_logPtr = log4cxx::Logger::getLogger(buf);
           r_logPtr->addAppender(file);
        }
 usleep(1);
getchar();
{
 log4cxx::RollingFileAppenderPtr fileAppenderPtr =
r_logPtr->getAppender("a");
printf("fileAppenderPtr's name:%s\n", fileAppenderPtr->getName().c_str());
 r_logPtr->removeAppender(fileAppenderPtr);
}
//r_logPtr->removeAllAppenders();
 printf("count:%d", count);
fflush(stdout);
getchar();
     return 0;

}

           yours sincerely ,

            Kyle Mick

Reply via email to