diff --git a/quill/include/quill/detail/misc/FileUtilities.h b/quill/include/quill/detail/misc/FileUtilities.h index e323b1a2..1afa9936 100644 --- a/quill/include/quill/detail/misc/FileUtilities.h +++ b/quill/include/quill/detail/misc/FileUtilities.h @@ -75,8 +75,9 @@ QUILL_NODISCARD QUILL_ATTRIBUTE_COLD std::pair extract * @return a filepath with the date appended */ QUILL_NODISCARD QUILL_ATTRIBUTE_COLD fs::path append_date_to_filename( - fs::path const& filename, std::chrono::system_clock::time_point timestamp = {}, bool append_time = false, - Timezone timezone = Timezone::LocalTime, bool zero_out_seconds = false) noexcept; + fs::path const& filename, std::chrono::system_clock::time_point timestamp = {}, + bool append_time = false, Timezone timezone = Timezone::LocalTime, bool zero_out_minutes = false, + bool zero_out_seconds = false) noexcept; /** * Append an index to the given filename diff --git a/quill/src/detail/misc/FileUtilities.cpp b/quill/src/detail/misc/FileUtilities.cpp index ab71cc4e..9cad4999 100644 --- a/quill/src/detail/misc/FileUtilities.cpp +++ b/quill/src/detail/misc/FileUtilities.cpp @@ -86,8 +86,9 @@ std::pair extract_stem_and_extension(fs::path const& f /***/ fs::path append_date_to_filename(fs::path const& filename, std::chrono::system_clock::time_point timestamp, /* = {} */ - bool append_time, /* = false */ - Timezone timezone, /* = Timezone::LocalTime */ + bool append_time, /* = false */ + Timezone timezone, /* = Timezone::LocalTime */ + bool zero_out_minutes, /* = false */ bool zero_out_seconds /* = false */) noexcept { // Get the time now as tm from user or default to now @@ -106,6 +107,11 @@ fs::path append_date_to_filename(fs::path const& filename, std::chrono::system_c detail::localtime_rs(&time_now, &now_tm); } + if (zero_out_minutes) + { + now_tm.tm_min = 0; + } + if (zero_out_seconds) { now_tm.tm_sec = 0; diff --git a/quill/src/handlers/TimeRotatingFileHandler.cpp b/quill/src/handlers/TimeRotatingFileHandler.cpp index e846157c..efb89fc1 100644 --- a/quill/src/handlers/TimeRotatingFileHandler.cpp +++ b/quill/src/handlers/TimeRotatingFileHandler.cpp @@ -96,12 +96,14 @@ void TimeRotatingFileHandler::write(fmt_buffer_t const& formatted_log_message, q if (_append_to_filename == FilenameAppend::None) { + bool const zero_out_minutes = (_when == "H") || (_when == "daily"); + // when the log files don't include the date and time information as part of their name // we add that as part of the rotation fs::path const previous_file = _filename; bool const append_time_to_filename = true; fs::path const new_file = detail::append_date_to_filename( - _filename, _file_creation_time, append_time_to_filename, _using_timezone, true); + _filename, _file_creation_time, append_time_to_filename, _using_timezone, zero_out_minutes, true); detail::rename_file(previous_file, new_file);