I am trying to understand glog and therefore trying to run the example code on their github page.
I have installed glog
(version - 0.6.0) and its dependency gflags
(version - 2.2) on my mac OS (10.15.7)
I compile the example below
#include <glog/logging.h>
int main(int argc, char* argv[]) {
// Initialize Google’s logging library.
google::InitGoogleLogging(argv[0]);
// test with setting a value for num_cookies
int num_cookies = 3;
// ...
LOG(INFO) << "Found " << num_cookies << " cookies";
}
using the following command (and it compiles without any errors or warnings).
g glog-test.cpp -I/usr/local/include -L/usr/local/lib -lglog -lgflags -o glog-test.o
When I run the example using the following command,
./glog-test.o --logtostderr=1 --stderrthreshold=0
I expect to see the message Found 3 cookies
on my terminal, but I see nothing being printed.
I have also experimented with different values for logtostderr
(0, 1) and stderrthreshold
(0, 1, 2, 3) and nothing gets written to the directory or gets printed on the terminal.
Any help in understanding what I am doing wrong here would be much appreciated, thank you!
CodePudding user response:
Just checked, the following works..
GLOG_stderrthreshold=0 GLOG_logtostderr=1 ./glog-test.o
which gives
Found 3 cookies
I do have gflags
and installed, as seen by
cd /usr/local/lib
ls -l | grep "libgflags"
which gives
-lrwxr-xr-x 1 sn admin 48 Jun 5 2020 libgflags.2.2.2.dylib -> ../Cellar/gflags/2.2.2/lib/libgflags.2.2.2.dylib
lrwxr-xr-x 1 sn admin 46 Jun 5 2020 libgflags.2.2.dylib -> ../Cellar/gflags/2.2.2/lib/libgflags.2.2.dylib
-rw-r--r-- 1 sn admin 170520 Jun 27 00:35 libgflags.a
lrwxr-xr-x 1 sn admin 42 Jun 5 2020 libgflags.dylib -> ../Cellar/gflags/2.2.2/lib/libgflags.dylib
lrwxr-xr-x 1 sn admin 58 Jun 5 2020 libgflags_nothreads.2.2.2.dylib -> ../Cellar/gflags/2.2.2/lib/libgflags_nothreads.2.2.2.dylib
lrwxr-xr-x 1 sn admin 56 Jun 5 2020 libgflags_nothreads.2.2.dylib -> ../Cellar/gflags/2.2.2/lib/libgflags_nothreads.2.2.dylib
-rw-r--r-- 1 sn admin 168096 Jun 27 00:35 libgflags_nothreads.a
lrwxr-xr-x 1 sn admin 52 Jun 5 2020 libgflags_nothreads.dylib -> ../Cellar/gflags/2.2.2/lib/libgflags_nothreads.dylib
so I am not sure why
./glog-test.o --logtostderr=1 --stderrthreshold=0
didn't work.
CodePudding user response:
You have to parse the command line flags manually through gflags::ParseCommandLineFlags
#include <glog/logging.h>
#incldue <gflags/gflags.h>
int main(int argc, char* argv[]) {
// Initialize Google’s logging library.
google::InitGoogleLogging(argv[0]);
gflags::ParseCommandLineFlags(&argc, &argv, true);
// test with setting a value for num_cookies
int num_cookies = 3;
// ...
LOG(INFO) << "Found " << num_cookies << " cookies";
}