Disable glog's "LOG(INFO)" logging

benk picture benk · May 23, 2016 · Viewed 17.4k times · Source

I'm trying to optimize my c++ program. It uses caffe.
When executing my program, caffe outputs around 1GB (!) of info logs every 15 mins. I suspect this impacts efficiency significantly. But I haven't found how to turn logging off. In this question someone suggested setting FLAGS_v manually.

With the following code I can disable VLOG logs by level, but LOG(x) logs are unaffected.

First lines in main():

FLAGS_v = 1; //disables vlog(2), vlog(3), vlog(4)
VLOG(0) << "Verbose 0";
VLOG(1) << "Verbose 1";
VLOG(2) << "Verbose 2";
VLOG(3) << "Verbose 3";
VLOG(4) << "Verbose 4";
LOG(INFO) << "LOG(INFO)";
LOG(WARNING) << "LOG(WARNING)";
LOG(ERROR) << "LOG(ERROR)";

Output:

WARNING: Logging before InitGoogleLogging() is written to STDERR
I0523 19:06:51.484634 14115 main.cpp:381] Verbose 0
I0523 19:06:51.484699 14115 main.cpp:382] Verbose 1
I0523 19:06:51.484705 14115 main.cpp:386] LOG(INFO)
W0523 19:06:51.484710 14115 main.cpp:387] LOG(WARNING)
E0523 19:06:51.484715 14115 main.cpp:388] LOG(ERROR)

Is there another flag I'm unaware of? I'm thinking of commenting every LOG(INFO) line out, but I would like a more elegant solution. (I'd prefer a c++ solution over a command line flag solution).

Answer

Shai picture Shai · May 23, 2016

you need to set your environment variable

GLOG_minloglevel=2

then run your executable.

You can find more information here (at the bottom of this page there is a section on stripping LOG()s from your code using a macro definition).