Change logging directory in google glog

How to change output directory in google glog?

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

tried:

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

but nothing was written!

Btw: if you offer another easy, convenient and reliable library, let me know!

Thanks for any help!

+6
source share
3 answers

You can also do one of the following:

Pass the log directory as a command line argument if you have the GFlgas library installed:

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

If you do not want to pass it on the command line and instead install it in the source:

 FLAGS_log_dir = "/some/log/directory"; 

If the Google gflags library is not installed, you can set it as an environment variable:

 GLOG_log_dir=/some/log/directory ./your_application 
+8
source

Here is the test that I did, you can try,

 #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 that you have already read this (well, I do not comment)

Hope this helps, good luck.


PS: I tested QtCreator (Qt5.1), and also on Windows7, did not output anything. I have no idea how to fix this now.

+3
source

I use this:

 fLS::FLAGS_log_dir = "c:/Documents/logs"; 
+1
source

Source: https://habr.com/ru/post/955653/


All Articles