user3278468
user3278468

Reputation: 25

Poco logger does not append logs to existing log file on process restart

I am using poco logger for my project. I want to have a behavior that if process restarts, poco does not create a new logging file. Below it my configurations: What am I doing wrong? I find that on every restart, poco overwrites the logs instead of appending to previous ones.

AutoPtr<FileChannel> pFile(new FileChannel(logfile));
pFile->setProperty("rotateOnOpen","true");
pFile->setProperty("rotation","1 M");
pFile->setProperty("archive", "timestamp");
pFile->setProperty("compress", "true");
pFile->setProperty("purgeAge", "1 months");
AutoPtr<Formatter> pformatter(new PatternFormatter("%d-%m-%Y %H:%M:%S %s: %t"));
pformatter->setProperty("times","local");
AutoPtr<Channel> pformattingchannel(new FormattingChannel(pformatter,pFile));
Logger::root().setChannel(pformattingchannel);
Logger::root().setLevel(Poco::Message::PRIO_INFORMATION);

Upvotes: 1

Views: 1082

Answers (1)

mike.dld
mike.dld

Reputation: 3049

You specifically ask to rotate log file on open:

pFile->setProperty("rotateOnOpen","true");

Documentation states:

The rotateOnOpen property specifies whether an existing log file should be rotated (and archived) when the channel is opened. Valid values are:

  • true: The log file is rotated (and archived) when the channel is opened.
  • false: Log messages will be appended to an existing log file, if it exists (unless other conditions for a rotation are met). This is the default.

Upvotes: 2

Related Questions