Search code examples
c++c++11loggingglog

VLOG doesn't work for Google Logging Library (glog)


My purpose is simple: to somehow see the logs printed by VLOG(5), which is provided by the glog library.

I have the following code:

google::InitGoogleLogging(argv[0]);
google::ParseCommandLineFlags(&argc, &argv, true);
FLAGS_logtostderr = 1;
FLAGS_v = 10;
LOG(INFO) << "info"; // OK, I see it
LOG(WARNING) << "warning"; // OK
VLOG(5) << "vlog"; // Nothing :(

No matter I manually set the flags here (FLAGS_logtostderr and FLAGS_v) or I pass it through the command line (--v=10), I just never find the string "vlog" anywhere: neither stdout, stderr nor some log file under \tmp. I think I didn't change the output path though.

Do I miss anything here? Any idea how to enable VLOG?


Solution

  • Personally, I've never tried it with

    FLAGS_logtostderr = 1;

    FLAGS_v = 10;

    The VLOG works fine for me if I set "GLOG_v=x" as an environmental variable on both linux and windows. E.g.

    Alternatively, if you want to test it on the command line you can do the following:

    Windows: C:>set GLOG_v=5 C:>set GLOG_logtostderr=1 C:>YourProgramName

    Linux: $ GLOG_v=7 GLOG_logtostderr=1 ./YourProgramName