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

can glog write to a specified file name? #147

xiaoyulei opened this issue Dec 14, 2016 · 5 comments


Copy link

@xiaoyulei xiaoyulei commented Dec 14, 2016

I want to write log to a specified file name, is there any parameter or interface to pass the name?


This comment has been minimized.

Copy link

@HelenXR HelenXR commented Apr 26, 2017

There is no ready interface to implement this feature,but

  • If you just want to modify the file name suffix, you can modify the file "glog\src\",like below:
//Add your suffix name, for example".helenxr.txt".
bool LogFileObject::CreateLogfile(const string& time_pid_string) {
  string string_filename = base_filename_+ filename_extension_+
                           time_pid_string + ".helenxr.txt";
  • If you want to completely customize the file name, then some trouble, first you need to understand that GLOG will create 4 level log files (INFO, WARNING, ERROR, FATAL), and high levels of log files will be written not only written to their lower level than their files, so you should pay attention to distinguish between these 4 files in the custom file name. The following is my verification feasible, change the file"glog\src\" like below:
bool LogFileObject::CreateLogfile(const string& time_pid_string) {
  //string string_filename = base_filename_+ filename_extension_+
  //                         time_pid_string + ".helenxr.txt";
  string custom_file_name_head = "helenxr",custom_file_name_end = ".txt";
  if(base_filename_.find("INFO") != std::string::npos){
		custom_file_name_head += "_info";
  else if(base_filename_.find("WARNING") != std::string::npos){
	  custom_file_name_head += "_warning";
  else if(base_filename_.find("ERROR") != std::string::npos){
	  custom_file_name_head += "_error";
  else if(base_filename_.find("FATAL") != std::string::npos){
	  custom_file_name_head += "_fatal";
	  custom_file_name_head += "_other"; 		
string string_filename = custom_file_name_head + custom_file_name_end;

Then,LOG(ERROR) << "your error message!",The files that are created:

Note this log file will created the current path in your application.
The above method I just verify the feasibility, of course, you can achieve this function and package an interface to better.
good luck :-)


This comment has been minimized.

Copy link

@jasjuang jasjuang commented Nov 30, 2017

+1 to write to a specified file name, can we have this feature instead of having to modify the source ourselves?


This comment has been minimized.

Copy link

@lizijie lizijie commented Jan 15, 2018

@jasjuang but i seems that, filename is hard coding inside LogFileObject::CreateLogfile


This comment has been minimized.

Copy link

@chenqiangzhishen chenqiangzhishen commented Jan 20, 2019

+1 , same demand, would extract the log file extension (suffix) as an parameter? thanks


This comment has been minimized.

Copy link

@FletcherClinkz FletcherClinkz commented Apr 24, 2019

Write to a specified file name may couldn't work. But the symbol link file name can be specified. For example: call
google::SetLogSymlink(google::GLOG_INFO, "some_specified_name")
before LOG will generate symbol link file of INFO logs in log_link (which is set by FLAGS_log_link) path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
6 participants
You can’t perform that action at this time.