【发布时间】:2014-06-28 04:44:35
【问题描述】:
我一直在尝试为我的 C++ 应用程序配置 google 日志库 glog,但我找不到任何有关如何使其实际工作的信息,而且错误消息也没有什么帮助。
这是我尝试执行的示例代码,我正在执行./myapp --v=2,但我得到“错误:未知命令行标志'v'”。该库是否有任何文档,或者有人知道如何正确配置它吗?
#include <glog/logging.h>
#include <gflags/gflags.h>
int main(int argc, char** argv) {
google::InitGoogleLogging(argv[0]);
google::ParseCommandLineFlags(&argc, &argv, true);
VLOG(1) << "I'm printed when you run the program with --v=1 or higher";
VLOG(2) << "I'm printed when you run the program with --v=2 or higher";
return 0;
}
【问题讨论】:
-
google-glog.googlecode.com/svn/trunk/doc/glog.html 的文档没有提及您对
google::ParseCommandLineFlags(&argc, &argv, true);的调用...如果您不包含该内容会怎样? -
如果我不包含该代码,则不会执行命令行解析并且不会启用日志记录。 google-glog“文档”引用了提到该调用的 gflags“文档”
-
另外,最好先调用
ParseCommandLineFlags,因为任何glog特定标志在解析命令行标志之前都不会生效(例如--logtostderr=true)。