glog日志按日期自动创建文件夹并输出到对应日期

本文介绍了如何修改glog源码,使其在每次日志滚动时检查日期变化,若日期改变则创建对应日期的文件夹,并将日志输出到该文件夹中,便于日志管理和查找。主要修改了LogFileObject类,增加了DayHasChanged函数来检查日期是否改动。
摘要由CSDN通过智能技术生成

1、修改logging.cc/LogFileObject类,

增减  int32 last_main_day_;
  string cur_sub_dir_;两个变量

 

2.  修改logging.cc/LogFileObject::Write函数

  bool log_day_changed = false;
  if (static_cast<int>(file_length_ >> 20) >= MaxLogSize() ||
      PidHasChanged() || (log_day_changed = DayHasChanged(timestamp,last_main_day_))) {
          
    if (file_ != NULL) fclose(file_);
    file_ = NULL;
    file_length_ = bytes_since_flush_ = dropped_mem_length_ = 0;
    rollover_attempt_ = kRolloverAttemptFrequency-1;
    
    if(log_day_changed) {
        struct ::tm tm_time;
        localtime_r(&timestamp, &tm_time);
        ostringstream time_pid_stream;
        time_pid_stream.fill('0');
        time_pid_stream << 1900+tm_time.tm_year
                    << setw(2) << 1+

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值