Poco记录器在进程重新启动时不会将日志附加到现有日志文件中

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

本文关键字:日志 文件 进程 记录器 重新启动 Poco      更新时间:2023-10-16

我正在为我的项目使用poco记录器。我想有一个行为,如果进程重启,poco不创建一个新的日志文件。下面是我的配置:我做错了什么?我发现每次重新启动时,poco都会覆盖日志,而不是附加到之前的日志中。

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);

您特别要求在打开时旋转日志文件:

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

文档:

rotateOnOpen属性指定在打开通道时是否应该旋转(并存档)现有的日志文件。有效值为:

  • true:打开通道时,日志文件被旋转(并存档)。
  • false:日志消息将被附加到现有的日志文件,如果它存在(除非满足其他条件的旋转)。