是否有“内置方式”记录一切与glog到程序崩溃? [英] Is there a "built in way" to log everything with glog up to the program crash?

查看:1450
本文介绍了是否有“内置方式”记录一切与glog到程序崩溃?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有兴趣使用一些日志记录来帮助我检测我的代码中的潜在问题,并检测我的程序崩溃的位置。我的问题是,我使用的(谷歌glog)不记录的东西,如果他们发生就在程序崩溃之前。所以我试着做这样的事情(这是3个参数的模板):

I'm interested in using some logging to help me detect potential problems in my code, and to detect where my program crashed. My problem is that lib that I used (google glog) doesn't log the stuff if they occur just before the program crash. So I tried to do something like this (this is template for 3 arguments):

mutex logMtx;
template<class T, class U, class V>
void mutexLOG_INFO(T t, U u, V v)
{
    stringstream ss;
    ss<<t;
    ss<<u;
    ss<<v;
    LOG(INFO)<<ss.str();
    mutex::scoped_lock sl(logMtx);
    google::FlushLogFiles(0);
}

它的工作原理AFAIK(从我的测试),但正如你可以看到不是很好,因为我需要为每个级别(INFO,WARNING ..)和每个参数的数量做我自己的功能。

It works AFAIK (from my testing), but as you can see it is not very nice, because I need to do my own function for every level (INFO,WARNING..) and for every number of parameters. Also I hate reinventing the wheel.

因此,有一种方法可以让LOG在每次LOG之后刷新。

So is there a way to tell glog to flush every time after LOG?

PS我知道这是g-log,而不是g-db(oops,name taken :)但我喜欢有很好地打印我的STL数据的选项,我使用gdb只是为了检测死亡的地方。

P.S. I know that this is g-log, not g-db (oops, name taken :) but I prefer to have the option to print nicely my STL data, I use gdb only to detect where things died.

编辑:SO再次证明它是一个伟大的信息来源:

SO proves again that it is a great source of info:

#include <glog/logging.h>
#include <**gflags**/gflags.h>
...
FLAGS_logbuflevel=-1;


推荐答案

我使用gflags和glog,帮助选项logbuflevel可能是您正在寻找的。

I use gflags with glog and if you run --help the option logbuflevel might be what you are looking for.

    -logbuflevel (Buffer log messages logged at this level or lower (-1 means
  don't buffer; 0 means buffer INFO only; ...)) type: int32 default: 0

这篇关于是否有“内置方式”记录一切与glog到程序崩溃?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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