Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File Name Not Updated When Rotating Based On Time With Zero Backup #296

Closed
teklot opened this issue May 24, 2023 · 2 comments
Closed

File Name Not Updated When Rotating Based On Time With Zero Backup #296

teklot opened this issue May 24, 2023 · 2 comments
Labels
bug Something isn't working question Further information is requested

Comments

@teklot
Copy link

teklot commented May 24, 2023

I expect the following code updates the file name when rotating based on the time but it keeps the file name the same as start time.

const auto fileHandler = quill::time_rotating_file_handler(
	logPath, "a",
	quill::FilenameAppend::DateTime,
	"M",
	1U,
	0
);

For example, if the logging starts at 5/4/23 16:25 the I expect the logs rotate every minute as below but that is not the case.

log_2023-05-04_16-25-00.log
log_2023-05-04_16-26-00.log
log_2023-05-04_16-27-00.log
...

Does this make sense?

@teklot teklot changed the title File Name Not Change When Rotating Based On Time With Zero Backup File Name Not Updated When Rotating Based On Time With Zero Backup May 24, 2023
@odygrd
Copy link
Owner

odygrd commented May 26, 2023

When you use quill::FilenameAppend::DateTime it appends the start date and time to the name of the log file. In that case it is using indexes to indicate the rotation otherwise it gets very confusing to read the log file you would had for example :

log_2023-05-04_16-25-00_2023-05-04_16-25-00.log
log_2023-05-04_16-25-00_2023-05-04_16-26-00.log
log_2023-05-04_16-25-00_2023-05-04_16-27-00.log

This example (using master) will achieve what you are looking for

#include "quill/Quill.h"

static char const* base_filename = "logfile.log";

int main()
{
  // Start the backend logging thread
  quill::start();

  // Create a rotating file handler with a max file size per log file and maximum rotation up to 5 times
  std::shared_ptr<quill::Handler> file_handler = quill::time_rotating_file_handler
    (base_filename, "w", quill::FilenameAppend::None, "M", 1, 5);

  // Create a logger using this handler
  quill::Logger* logger_bar = quill::create_logger("rotating", std::move(file_handler));

  for (uint32_t i = 0; i < 15; ++i)
  {
    LOG_INFO(logger_bar, "Hello from {} {}", "rotating logger", i);
    std::this_thread::sleep_for(std::chrono::seconds{61});
  }
}

The most reset logfile has always the name of the base_filename .
When you use backup_count == 0 you will always see logfile.log but it will contain the most reset log
If you change it to backup_count >= 1 then you will see the rotated files

edit : it seems there is a bug at this and I am currently looking

@odygrd odygrd added question Further information is requested bug Something isn't working labels May 26, 2023
@odygrd
Copy link
Owner

odygrd commented May 27, 2023

I have pushed a fix in master for this, it will be in 2.9.1
I tested it with the above example.

Let me know if you still have issues after this fix and thanks for reporting 👍

@odygrd odygrd closed this as completed May 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants