首先找到glog项目工程里面的glogbase工程文件(这里是vs2013,其他版本雷同),如图
1.在utilities.h文件下新增两个函数
int32 GetMainDay();
bool DayHasChanged();
2.在utilities.cpp文件中加入函数如下,
static int32 g_main_day = 0;
int32 GetMainDay() {
return g_main_day;
}
bool DayHasChanged()
{
time_t raw_time;
struct tm* tm_info;
time(&raw_time);
tm_info = localtime(&raw_time);
if (tm_info->tm_mday != g_main_day)
{
g_main_day = tm_info->tm_mday;
return true;
}
return false;
}
3.修改logging.cc文件
if (file_length_ >> 20U >= MaxLogSize() /*|| PidHasChanged() */|| DayHasChanged()) {
if (file_ != NULL) fclose(file_);
file_ = NULL;
file_length_ = bytes_since_flush_ = dropped_mem_length_ = 0;
rollover_attempt_ = kRolloverAttemptFrequency - 1;
}
4.以上步骤还是不足够能按天修改的,继续修改代码,按照如下进行注释
ostringstream time_pid_stream;
time_pid_stream.fill('0');
time_pid_stream << 1900+tm_time.tm_year
<< setw(2) << 1+tm_time.tm_mon
<< setw(2) << tm_time.tm_mday;
//<< '-'
//<< setw(2) << tm_time.tm_hour
//<< setw(2) << tm_time.tm_min
//<< setw(2) << tm_time.tm_sec
//<< '.'
//<< GetMainDay();
5.最后一步修改代码,打开CreateLogfile这个函数,如下图函数位置
然后进入到这哥函数中,如下图所示,修改两处
int flags = O_WRONLY | O_CREAT | O_APPEND;
if (FLAGS_timestamp_in_logfile_name) {
//demand that the file is unique for our timestamp (fail if it exists).
flags = flags /*| O_EXCL*/;
}
int fd = open(filename, flags, FLAGS_logfile_mode);
if (fd == -1) return false;
6.ALL_BUILD所有项目,即可
7.效果