代码之家  ›  专栏  ›  技术社区  ›  ronag

限制半常量日志消息的日志保护

  •  0
  • ronag  · 技术社区  · 14 年前

    我在应用程序中使用boost日志进行日志记录。

    e、 (这是一个简单的例子,不是实际的实现)

    while(!framebuffer.try_pop(frame))
    {
        BOOST_LOG(trace) << "Buffer underrun.";
    }
    

    如果由于某种原因“framebuffer”长时间不接收任何帧,则日志将向许多日志消息发送路径。

    但是,我不确定在不丢失任何重要消息的情况下,使用什么策略来限制日志消息,以及如何实现它。

    1 回复  |  直到 14 年前
        1
  •  1
  •   Robert Massaioli    14 年前

    简单点怎么样,如果你想:

    int tooMany = 10;
    int count = 0;
    while(!framebuffer.try_pop(frame))
    {
        if(count < tooMany) {
            BOOST_LOG(trace) << "Buffer underrun.";
        }
        count++;
    }
    if(count >= tooMany) {
        BOOST_LOG(trace) << "Message repeated: " << count << " times.";
    }