In my terrifying experience with this library I came to see that this flag FLAGS_log_dir
and this function google::SetLogDestination()
compete with each other. Wonderful.
I learned that you can use either but not both.
option 1: use flags
FLAGS_log_dir=/path/to/your/logdir
google::InitGoogleLogging(exec_name.c_str());
and generate a bunch of files named your_exec.some_number.machine_name.log.log_severity....
and their respective symbolic link inside the /path/to/your/logdir
. A pair of files will be generated for each log_severity you have used in your program (INFO, WARNING, ERROR, FATAL). Fun fact: INFO files contain everything, WARNING files contain everything from warning downwards, and so on. God knows why these symlinks are needed.
option 2: use file names
std::string log_dir = "/path/to/log/dir";
for (int severity = 0; severity < google::NUM_SEVERITIES; ++severity) {
std::string fpath = fs::path(fs::path(log_dir) / fs::path(exec_name).filename());
google::SetLogDestination(severity, fpath.c_str());
google::SetLogSymlink(severity, "");
}
google::InitGoogleLogging(exec_name.c_str());
where fs
is the filesystem library of c++17. This is send all logs to the same file (just one, not many) and finally remove that annoying symbolic link.