Easylogging++(截止v9.96.7)重大BUG,致程序崩溃

        最近在某大型视觉导航程序工程里集成了强大的Easylogging++日志模块,用得很爽。直到一连串死机BUG的出现......

1 问题        

        正常情况下我们使用Easylogging++不会出现什么问题,我也是这样认为的,并且坚信。当你在多线程里这样疯狂输出日志时:

#include <chrono>
#include <thread>
#include "easylogging++.h"

INITIALIZE_EASYLOGGINGPP

void fun0()
{
    while (1)
    {
        LOG(INFO) << "this is sub thread: " << std::this_thread::get_id();

        std::chrono::milliseconds dura(10);
        std::this_thread::sleep_for(dura);
    }
}

void fun1()
{
    while (1)
    {
        LOG(INFO) << "this is sub thread: " << std::this_thread::get_id();

        std::chrono::milliseconds dura(10);
        std::this_thread::sleep_for(dura);
    }
}

void fun2()
{
    while (1)
    {
        LOG(INFO) << "this is sub thread: " << std::this_thread::get_id();

        std::chrono::milliseconds dura(10);
        std::this_thread::sleep_for(dura);
    }
}

void fun3()
{
    while (1)
    {
        LOG(INFO) << "this is sub thread: " << std::this_thread::get_id();

        std::chrono::milliseconds dura(10);
        std::this_thread::sleep_for(dura);
    }
}

void fun4()
{
    while (1)
    {
        LOG(INFO) << "this is sub thread: " << std::this_thread::get_id();

        std::chrono::milliseconds dura(10);
        std::this_thread::sleep_for(dura);
    }
}

void fun5()
{
    while (1)
    {
        LOG(INFO) << "this is sub thread: " << std::this_thread::get_id();

        std::chrono::milliseconds dura(10);
        std::this_thread::sleep_for(dura);
    }
}

void fun6()
{
    while (1)
    {
        LOG(INFO) << "this is sub thread: " << std::this_thread::get_id();

        std::chrono::milliseconds dura(10);
        std::this_thread::sleep_for(dura);
    }
}

void fun7()
{
    while (1)
    {
        LOG(INFO) << "this is sub thread: " << std::this_thread::get_id();

        std::chrono::milliseconds dura(10);
        std::this_thread::sleep_for(dura);
    }
}

void fun8()
{
    while (1)
    {
        LOG(INFO) << "this is sub thread: " << std::this_thread::get_id();

        std::chrono::milliseconds dura(10);
        std::this_thread::sleep_for(dura);
    }
}

void fun9()
{
    while (1)
    {
        LOG(INFO) << "this is sub thread: " << std::this_thread::get_id();

        std::chrono::milliseconds dura(10);
        std::this_thread::sleep_for(dura);
    }
}

void fun10()
{
    while (1)
    {
        LOG(INFO) << "this is sub thread: " << std::this_thread::get_id();

        std::chrono::milliseconds dura(10);
        std::this_thread::sleep_for(dura);
    }
}

int main(int argc, char **argv)
{
    /// 使用默认配置
    el::Configurations defaultConf;
    defaultConf.setToDefault();

    defaultConf.setGlobally(el::ConfigurationType::Enabled, "true");
    defaultConf.setGlobally(el::ConfigurationType::ToFile, "true");
    defaultConf.setGlobally(el::ConfigurationType::ToStandardOutput, "false");
    defaultConf.setGlobally(el::ConfigurationType::Format, "[%datetime{%H:%m:%s:%g}] [%level] %msg");
    defaultConf.setGlobally(el::ConfigurationType::Filename, "vslam.log");
    defaultConf.setGlobally(el::ConfigurationType::MillisecondsWidth, "3");
    defaultConf.setGlobally(el::ConfigurationType::PerformanceTracking, "false");
    defaultConf.setGlobally(el::ConfigurationType::MaxLogFileSize, "104857600");   // 100MB
    defaultConf.setGlobally(el::ConfigurationType::LogFlushThreshold, "0");

    defaultConf.set(el::Level::Trace, el::ConfigurationType::Enabled, "true");
    defaultConf.set(el::Level::Info, el::ConfigurationType::Enabled, "true");
    defaultConf.set(el::Level::Debug, el::ConfigurationType::Enabled, "true");
    defaultConf.set(el::Level::Error, el::ConfigurationType::Enabled, "true");
    defaultConf.set(el::Level::Warning, el::ConfigurationType::Enabled, "true");

    el::Loggers::reconfigureAllLoggers(defaultConf);

    LOG(INFO) << argv[0] << " start !!!!";

    LOG(INFO) << "start vslam !!!!";

    std::thread t0(fun0);
    std::thread t1(fun1);
    std::thread t2(fun2);
    std::thread t3(fun3);
    std::thread t4(fun4);
    std::thread t5(fun5);
    std::thread t6(fun6);
    std::thread t7(fun7);
    std::thread t8(fun8);
    std::thread t9(fun9);
    std::thread t10(fun10);

    while(1)
    {
        LOG(INFO) << "this is main thread: " << std::this_thread::get_id();

        std::chrono::milliseconds dura(1);
        std::this_thread::sleep_for(dura);
    }

    LOG(INFO) << "bye! bye! vslam will exit.";

    return 0;
}


        出现了致命BUG

 2 尝试解决

        将

  inline bool isFlushNeeded(Level level) {
    return ++m_unflushedCount.find(level)->second >= m_typedConfigurations->logFlushThreshold(level);
  }

        修改成

  inline bool isFlushNeeded(Level level) {
    if (!m_unflushedCount.empty())
    {
      auto it = m_unflushedCount.find(level);
      if (it != m_unflushedCount.end())
      {
        return ++it->second >= m_typedConfigurations->logFlushThreshold(level);
      }
    }

    return false;
  }

        以为解决了,可是过了半小时后

 

各路大神们,求解决方法

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值