From: Václav H. <v.h...@sh...> - 2009-08-25 05:45:04
|
ss ak wrote, On 25.8.2009 1:15: > How do i set > Append=true. > > I didnt find any properties to set on the fileappender.... > this is the only code i am using... > >> here is the code >> log4cplus::BasicConfigurator config; >> >> config.configure(); >> >> log4cplus::Logger logger = Logger::getInstance("main"); >> >> log4cplus::SharedAppenderPtr > fileapp(new log4cplus::FileAppender("logfile.log")); >> >> logger.addAppender(fileapp); >> >> logger.setLogLevel(log4cplus::DEBUG_LOG_LEVEL); > It outputs on the console too... I did not realise it before, yes, it does output to console. That is because BasicConfigurator automatically adds ConsoleAppender to rootLogger. If you want to avoid that, use PropertyConfigurator instead. To make the FileAppender append to existing file, configure it with the Append=true property. Something like this: log4cplus::helpers::Properties props; props.setProperty (LOG4CPLUS_TEXT ("Append"), LOG4CPLUS_TEXT ("true")); props.setProperty (LOG4CPLUS_TEXT ("File"), LOG4CPLUS_TEXT ("logfile.log")); log4cplus::SharedAppenderPtr fileapp (new log4cplus::FileAppender (props)); -- VH |