Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glog error log was incorrrectly written to unexpected memory #561

Closed
fanyhawu opened this issue Jun 25, 2020 · 1 comment
Closed

glog error log was incorrrectly written to unexpected memory #561

fanyhawu opened this issue Jun 25, 2020 · 1 comment

Comments

@fanyhawu
Copy link

fanyhawu commented Jun 25, 2020

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?

@fanyhawu
Copy link
Author

even SetLogger() after init(), still same issue, I'll go to check by myself

@sergiud sergiud mentioned this issue May 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant