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

Closed
xiaoyulei opened this issue Dec 14, 2016 · 5 comments
Closed

can glog write to a specified file name? #147

xiaoyulei opened this issue Dec 14, 2016 · 5 comments

Comments

@xiaoyulei
Copy link

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

@HelenXR
Copy link

HelenXR commented Apr 26, 2017

@YuleiXiao
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\logging.cc",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\logging.cc" 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";
  }
  else{
	  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:
demo

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 :-)

@jasjuang
Copy link

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

@lizijie
Copy link

lizijie commented Jan 15, 2018

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

@chenqiangzhishen
Copy link

chenqiangzhishen commented Jan 20, 2019

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

@Mag1cL
Copy link

Mag1cL 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.

@sergiud sergiud closed this as completed Mar 30, 2021
@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

7 participants