Skip to content

Commit

Permalink
fix initial rotation bug in TimeRotatingFileHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
odygrd committed May 11, 2023
1 parent e42e579 commit 8c91d49
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- [v2.8.1](#v281)
- [v2.8.0](#v280)
- [v2.7.0](#v270)
- [v2.6.0](#v260)
Expand Down Expand Up @@ -40,6 +41,12 @@
- [v1.1.0](#v110)
- [v1.0.0](#v100)

## v2.8.1

**Fixes**

- Fixed a bug in TimeRotatingFileHandler ([#287](https://github.com/odygrd/quill/pull/287))

## v2.8.0

**Breaking Changes**
Expand Down
2 changes: 1 addition & 1 deletion quill/include/quill/Quill.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace quill
/** Version Info **/
constexpr uint32_t VersionMajor{2};
constexpr uint32_t VersionMinor{8};
constexpr uint32_t VersionPatch{0};
constexpr uint32_t VersionPatch{1};
constexpr uint32_t Version{VersionMajor * 10000 + VersionMinor * 100 + VersionPatch};

/** forward declarations **/
Expand Down
6 changes: 4 additions & 2 deletions quill/src/Quill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ std::shared_ptr<Handler> file_handler(fs::path const& filename, std::string cons
std::shared_ptr<Handler> time_rotating_file_handler(
fs::path const& base_filename, std::string const& mode /* = std::string{"a"} */,
FilenameAppend append_to_filename /* = FilenameAppend::None */,
std::string const& when /* = std::string{"H"} */, uint32_t interval /* = 1 */, uint32_t backup_count /* = 0 */,
std::string const& when /* = std::string{"H"} */, uint32_t interval /* = 1 */,
uint32_t backup_count /* = std::numeric_limits<std::uint32_t>::max() */,
Timezone timezone /* = Timezone::LocalTime */, std::string const& at_time /* = std::string{} */,
FileEventNotifier file_event_notifier /* = FileEventNotifier{} */, bool do_fsync /* = false */)
{
Expand All @@ -82,7 +83,8 @@ std::shared_ptr<Handler> time_rotating_file_handler(
std::shared_ptr<Handler> rotating_file_handler(
fs::path const& base_filename, std::string const& mode /* = std::string {"a"} */,
FilenameAppend append_to_filename /* = FilenameAppend::None */, size_t max_bytes /* = 0 */,
uint32_t backup_count /* = 0 */, bool overwrite_oldest_files /* = true */, bool clean_old_files /* = false */,
uint32_t backup_count /* = std::numeric_limits<std::uint32_t>::max() */,
bool overwrite_oldest_files /* = true */, bool clean_old_files /* = false */,
FileEventNotifier file_event_notifier /* = FileEventNotifier{} */, bool do_fsync /* = false */)
{
return create_handler<RotatingFileHandler>(base_filename.string(), mode, append_to_filename,
Expand Down
5 changes: 3 additions & 2 deletions quill/src/handlers/TimeRotatingFileHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ TimeRotatingFileHandler::TimeRotatingFileHandler(fs::path const& base_filename,
_calculate_initial_rotation_tp(_file_creation_time, _when, timezone, at_time_hours, at_time_minutes);

// Open file for logging
_created_files.emplace_front(0, _filename);
open_file(_filename, mode);
}

Expand All @@ -100,7 +101,7 @@ void TimeRotatingFileHandler::write(fmt_buffer_t const& formatted_log_message, q
detail::rename_file(previous_file, new_file);

// Also store the file name in a queue to remove_file it later if we exceed backup count
_created_files.push_front(std::make_pair(0, new_file));
_created_files.emplace_front(0, new_file);
}
else if ((_append_to_filename == FilenameAppend::Date) || (_append_to_filename == FilenameAppend::DateTime))
{
Expand All @@ -125,7 +126,7 @@ void TimeRotatingFileHandler::write(fmt_buffer_t const& formatted_log_message, q
quill::detail::rename_file(previous_file, new_file);
}

_created_files.push_front(std::make_pair(0, _filename));
_created_files.emplace_front(0, _filename);
}

// If we have too many files in the queue remove_file the oldest one
Expand Down

0 comments on commit 8c91d49

Please sign in to comment.