Change logging directory in Google glog

2019-04-23 12:45发布

How can I change the output directory in Google glog?

I only found google::SetLogDestination(google::LogSeverity, const char* path)

tried it with:

google::SetLogDestination(ERROR, "C:\\log\\error.log);
google::InitGoogleLogging("Test");  

LOG(ERROR) << "TEST";

but nothing was written!

Btw.: if you suggest another lightweight, easy to use and thread safe library please let me know!

Thx for any help!

标签: c++ logging glog
3条回答
何必那么认真
2楼-- · 2019-04-23 12:55

Here is the test what I did, you may try it,

#include <glog/logging.h>

using namespace std;

int main(int /*argc*/, char** argv)
{
    FLAGS_logtostderr = true;
    google::SetLogDestination(google::GLOG_INFO,"c:/lovelyGoogle" );
    google::InitGoogleLogging(argv[0]);

    LOG(INFO) << "This is INFO";
    LOG(WARNING) << "This is WARNING";
    LOG(ERROR) << "This is Error";

    system("pause");
    return 0;
}

Tested under Visual studio 2012, google-glog 0.3.3 on Windows 7.
It generated lvoelyGoogle20131016-141423.5160 on my C driver.
If you set FLAGS_logtostderr = false, the log file will not be generated,

I believe you have already read this (well, I have no comment on it)

hope this helpful, good luck.


PS: I have tested on QtCreator (Qt5.1) as well on Windows7, nothing output. I have no idea how to fix it now.

查看更多
混吃等死
3楼-- · 2019-04-23 13:01

You can also do one of the following:

Pass the log directory as a commandline argument as long as you have the GFlgas library installed:

./your_application --log_dir=/some/log/directory

If you don't want to pass it in the commandline and instead set it in the source:

FLAGS_log_dir = "/some/log/directory";

If the Google gflags library isn't installed you can set it as an environment variable:

GLOG_log_dir=/some/log/directory ./your_application
查看更多
Deceive 欺骗
4楼-- · 2019-04-23 13:13

I use this:

fLS::FLAGS_log_dir = "c:/Documents/logs";
查看更多
登录 后发表回答