【问题标题】:Poco logger does not append logs to existing log file on process restartPoco 记录器不会在进程重新启动时将日志附加到现有日志文件
【发布时间】:2016-08-16 21:53:58
【问题描述】:

我正在为我的项目使用 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);

【问题讨论】:

    标签: c++ poco


    【解决方案1】:

    您特别要求在打开时轮换日志文件:

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

    Documentation 状态:

    rotateOnOpen 属性指定在打开通道时是否应轮换(并归档)现有日志文件。有效值为:

    • true:当频道打开时,日志文件会轮转(并存档)。
    • false:如果现有日志文件存在,日志消息将附加到现有日志文件中(除非满足轮换的其他条件)。这是默认设置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-09
      • 1970-01-01
      • 2017-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-22
      • 1970-01-01
      相关资源
      最近更新 更多