【问题标题】:GLOG multithread logGLOG 多线程日志
【发布时间】:2018-05-20 09:55:26
【问题描述】:

我想使用 Glog lib 来记录我的应用程序日志。我的应用程序是多线程的。正如 glog 中所建议的,我应该使用 RAW_LOG 来保证线程安全。这是我的示例代码。

  #include "stdafx.h"
  #define GLOG_NO_ABBREVIATED_SEVERITIES
  #include <windows.h>
  #include <glog/logging.h>
  #include <glog/raw_logging.h>
  using namespace std;

  int main(int /*argc*/, char** argv)
  {
      FLAGS_alsologtostderr = 1;

      google::SetLogDestination(google::GLOG_INFO, "E:/mylog.log");
      google::InitGoogleLogging(argv[0]);
      //LOG(INFO) << "Infomration";
      RAW_LOG_INFO("Test");

      RAW_LOG(INFO,"This is INFO");
      RAW_LOG(WARNING,"This is WARNING");
      RAW_LOG(ERROR, "This is Error");
      return 0;
   }

但是如果我使用 RAW_LOG 则不会生成日志文件,但如果我使用 LOG() 函数则会生成日志文件。

请告诉我如何使用 RAW_LOG 函数或者 LOG() 函数是否线程安全。

【问题讨论】:

    标签: c++ logging glog


    【解决方案1】:

    这是来自 raw_logging.h

    // * it logs straight and ONLY to STDERR w/o buffering
    

    它只能记录到 stderr 并且仅用于在低级代码中进行调试 所以RAW_LOG(INFO,"...") 永远不会生成任何日志文件。

    【讨论】:

      猜你喜欢
      • 2023-01-11
      • 1970-01-01
      • 1970-01-01
      • 2017-03-16
      • 1970-01-01
      • 2020-07-11
      • 1970-01-01
      • 1970-01-01
      • 2013-10-17
      相关资源
      最近更新 更多