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).
If you want to turn off log from code level, you can use this.
Just add below line in your c++ code at src/caffe/net.cpp in
Init
method and build caffe:Partial view of the function where this line should be added:
Set log level according to your necessity.
you need to set your environment variable
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).This works in C++ source code.
The environment variable "GLOG_minloglevel" will filter some log but they have been compile in your executable file. If you want to disable them during compiling time, define a macro:
"#define GOOGLE_STRIP_LOG 1"
This is the comment in logging.h: