C++11 G3Log的隐藏实现

C++11 G3Log的隐藏实现,c++11,mutex,glog,g2log,C++11,Mutex,Glog,G2log,我试图使用G3Log(Google logger-glog的一个版本)在静态库中进行一些日志记录。在我尝试将该静态库引入C++/CLI管理的包装器之前,所有这些都非常有效。当我这样做时,我会遇到一个可怕的问题: error C1189: #error : <mutex> is not supported when compiling with /clr or /clr:pure. 以下是CPP文件: #include "include/g2logworker.hpp" #inclu

我试图使用G3Log(Google logger-glog的一个版本)在静态库中进行一些日志记录。在我尝试将该静态库引入C++/CLI管理的包装器之前,所有这些都非常有效。当我这样做时,我会遇到一个可怕的问题:

error C1189: #error : <mutex> is not supported when compiling with /clr or /clr:pure.
以下是CPP文件:

#include "include/g2logworker.hpp"
#include "include/g2log.hpp"

Log::Log() {
    logworker = (void *)(g2::LogWorker::createWithNoSink().get());
};

void Log::Initialize(std::string log_path, std::string log_file, std::string trace_file) {
    auto worker = static_cast<g2::LogWorker *>(logworker);
    auto loghandle = worker->addSink(std::make_unique<Log>(), &Log::LogMessage);
    log_ = (void *) loghandle.get();

    auto tracehandle = worker->addSink(std::make_unique<Log>(), &Log::TraceMessage);
    trace_ = (void *) tracehandle.get();

    g2::initializeLogging(worker);
};

void Log::LogMessage( g2::LogMessageMover message) {
    fprintf(stderr, "Got the log message");
};

void Log::TraceMessage( g2::LogMessageMover message) {
    fprintf(stderr, "Got the trace message");
};
#包括“include/g2logworker.hpp”
#包括“include/g2log.hpp”
Log::Log(){
logworker=(void*)(g2::logworker::createWithNoSink().get());
};
无效日志::初始化(std::字符串日志\u路径、std::字符串日志\u文件、std::字符串跟踪\u文件){
自动工作者=静态施法(日志工作者);
自动loghandle=worker->addSink(std::make_unique(),&Log::LogMessage);
logu=(void*)loghandle.get();
auto-tracehandle=worker->addSink(std::make_unique(),&Log::TraceMessage);
trace_=(void*)tracehandle.get();
g2::初始化日志记录(工人);
};
无效日志::LogMessage(g2::LogMessageMover消息){
fprintf(stderr,“获取日志消息”);
};
无效日志::TraceMessage(g2::LogMessageMover消息){
fprintf(stderr,“获取跟踪消息”);
};

似乎是g3log/src/shared_queue.hpp包含了互斥锁的违规include

我想到了几个不同的选择 1) 将队列从仅头更改为.hpp+.cpp实现,其中互斥部分隐藏在pimpl中

2) 将队列替换为无锁队列。您可能需要有一个包装器才能提供所需的API。我还没有测试过这个,但看起来很有希望

moody camel无锁队列在g3log中非常有效。此外,在一般情况下,速度也会显著提高。
#include "include/g2logworker.hpp"
#include "include/g2log.hpp"

Log::Log() {
    logworker = (void *)(g2::LogWorker::createWithNoSink().get());
};

void Log::Initialize(std::string log_path, std::string log_file, std::string trace_file) {
    auto worker = static_cast<g2::LogWorker *>(logworker);
    auto loghandle = worker->addSink(std::make_unique<Log>(), &Log::LogMessage);
    log_ = (void *) loghandle.get();

    auto tracehandle = worker->addSink(std::make_unique<Log>(), &Log::TraceMessage);
    trace_ = (void *) tracehandle.get();

    g2::initializeLogging(worker);
};

void Log::LogMessage( g2::LogMessageMover message) {
    fprintf(stderr, "Got the log message");
};

void Log::TraceMessage( g2::LogMessageMover message) {
    fprintf(stderr, "Got the trace message");
};