glog详细日志记录& amp;增强程序选项 [英] glog verbose logging & Boost program options

查看:129
本文介绍了glog详细日志记录& amp;增强程序选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在代码中使用了 boost 程序选项,并尝试使用 glog (Google日志记录库)添加详细的日志记录.

I am using boost program options in my code and trying to add verbose logging using glog (google logging library).

问题是 boost 捕获了命令行选项,并且我不能使用-v 标志来控制详细的日志记录.有没有一种方法可以从代码中设置 minloglevel ?我无法找到以编程方式执行此操作的函数或宏...

The problem is that boost captures the command line options and I can not use the --v flag for controlling the verbose logging. Is there a method for setting the minloglevel from the code? I failed locating a function or a macro for doing that programatically...

推荐答案

我遇到了同样的问题,并且正在设法在我的主要功能中设置glog标志,如下所示:

I had the same problem and am managing to set glog flags in my main function as follows:

namespace po = boost::program_options;

int main(int ac, char **av) {
    po::options_description desc("...");
    desc.add_options()
    ("verbosity,v", po::value<int>(), "set verbose logging level, defaults to 0")
    ;

    po::variables_map vm;
    try{
        po::store(po::parse_command_line(ac, av, desc), vm);
        po::notify(vm);
    }
    catch (po::required_option& e){
        ...
    }
    ...
    if (vm.count("verbosity")){
        FLAGS_v = vm["verbosity"].as<int>();
    }
    else{
        FLAGS_v = 0;
    }
    google::InitGoogleLogging("...");
}

这篇关于glog详细日志记录&amp; amp;增强程序选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆