Description
Hi,
I know glog ERROR log message will be written to stderr by default. Most of the time, it work as expected, but occasionally I found it will not be written into stderr and was written into some unexpected memory.
I have checked my source code and then I found there's something that I may did incorrectly:
class NullLogger : public google::base::Logger
{
virtual void Write(bool, time_t, const char*, int) {
}
virtual void Flush() {
}
virtual google::uint32 LogSize() {
return 0;
}
};
void init()
{
...
google::SetLogDestination(google::GLOG_INFO, fullpath.c_str());
// do not generate separate files for warning and error.
static NullLogger nullLogger;
google::base::SetLogger(google::GLOG_WARNING,&nullLogger);
google::base::SetLogger(google::GLOG_ERROR,&nullLogger);
google::InitGoogleLogging("");
}
note I called google::base::SetLogger() before google::InitGoogleLogging().
If I called google::InitGoogleLogging() first, then call google::base::SetLogger(), just like following code, everything seems work fine, but I can't explain why.
void init()
{
...
google::SetLogDestination(google::GLOG_INFO, fullpath.c_str());
google::InitGoogleLogging("");
// do not generate separate files for warning and error.
static NullLogger nullLogger;
google::base::SetLogger(google::GLOG_WARNING,&nullLogger);
google::base::SetLogger(google::GLOG_ERROR,&nullLogger);
}
I know for glog some operations should be done before google::InitGoogleLogging(), such as "setting value of FLAGS_log_dir".
I have checked google::InitGoogleLogging() source code, it looks it only defines the g_main_thread_id and marked if it has been initialized. my question is: if I call google::base::SetLogger() before google::InitGoogleLogging(), will there be some issue that you can imagine?
Activity