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);
}
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.
So is there a way to tell glog to flush every time after LOG?
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.
EDIT: SO proves again that it is a great source of info:
#include <glog/logging.h>
#include <**gflags**/gflags.h>
...
FLAGS_logbuflevel=-1;
I use gflags with glog and if you run --help the option logbuflevel might be what you are looking for.