can glog write to a specified file name?
I want to write log to a specified file name, is there any parameter or interface to pass the name?
@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:

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 :-)
+1 to write to a specified file name, can we have this feature instead of having to modify the source ourselves?
@jasjuang but i seems that, filename is hard coding inside LogFileObject::CreateLogfile
+1 , same demand, would extract the log file extension (suffix) as an parameter? thanks
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.