Merge pull request #2386 from panzhongxian/v1.x
Romove the empty file if no log in first period in hourly logger
This commit is contained in:
		@@ -57,6 +57,7 @@ public:
 | 
				
			|||||||
        auto now = log_clock::now();
 | 
					        auto now = log_clock::now();
 | 
				
			||||||
        auto filename = FileNameCalc::calc_filename(base_filename_, now_tm(now));
 | 
					        auto filename = FileNameCalc::calc_filename(base_filename_, now_tm(now));
 | 
				
			||||||
        file_helper_.open(filename, truncate_);
 | 
					        file_helper_.open(filename, truncate_);
 | 
				
			||||||
 | 
					        remove_init_file_ = file_helper_.size() == 0;
 | 
				
			||||||
        rotation_tp_ = next_rotation_tp_();
 | 
					        rotation_tp_ = next_rotation_tp_();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (max_files_ > 0)
 | 
					        if (max_files_ > 0)
 | 
				
			||||||
@@ -78,10 +79,16 @@ protected:
 | 
				
			|||||||
        bool should_rotate = time >= rotation_tp_;
 | 
					        bool should_rotate = time >= rotation_tp_;
 | 
				
			||||||
        if (should_rotate)
 | 
					        if (should_rotate)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            if (remove_init_file_)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                file_helper_.close();
 | 
				
			||||||
 | 
					                details::os::remove(file_helper_.filename());
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            auto filename = FileNameCalc::calc_filename(base_filename_, now_tm(time));
 | 
					            auto filename = FileNameCalc::calc_filename(base_filename_, now_tm(time));
 | 
				
			||||||
            file_helper_.open(filename, truncate_);
 | 
					            file_helper_.open(filename, truncate_);
 | 
				
			||||||
            rotation_tp_ = next_rotation_tp_();
 | 
					            rotation_tp_ = next_rotation_tp_();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        remove_init_file_ = false;
 | 
				
			||||||
        memory_buf_t formatted;
 | 
					        memory_buf_t formatted;
 | 
				
			||||||
        base_sink<Mutex>::formatter_->format(msg, formatted);
 | 
					        base_sink<Mutex>::formatter_->format(msg, formatted);
 | 
				
			||||||
        file_helper_.write(formatted);
 | 
					        file_helper_.write(formatted);
 | 
				
			||||||
@@ -170,6 +177,7 @@ private:
 | 
				
			|||||||
    bool truncate_;
 | 
					    bool truncate_;
 | 
				
			||||||
    uint16_t max_files_;
 | 
					    uint16_t max_files_;
 | 
				
			||||||
    details::circular_q<filename_t> filenames_q_;
 | 
					    details::circular_q<filename_t> filenames_q_;
 | 
				
			||||||
 | 
					    bool remove_init_file_;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
using hourly_file_sink_mt = hourly_file_sink<std::mutex>;
 | 
					using hourly_file_sink_mt = hourly_file_sink<std::mutex>;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user