0

My understanding of this is that the file will be limited to the specified size. But I don't understand the max_files = 3, are we going to have one or three files?

I run the example here and got one file.

#include <iostream>

#include "spdlog/sinks/rotating_file_sink.h"

void rotating_example()
{
    // Create a file rotating logger with 5mb size max and 3 rotated files
    auto max_size = 1048576 * 5;
    auto max_files = 3;
    auto logger = spdlog::rotating_logger_mt("some_logger_name", "logs/rotating.txt", max_size, max_files);

    logger->info("loggers can be retrieved from a global registry using the spdlog::get(logger_name)");
}

int main()
{
    rotating_example();
    return 0;
}
KcFnMi
  • 5,516
  • 10
  • 62
  • 136
  • 1
    hope this can help you about rotated files https://www.networkworld.com/article/3218728/how-log-rotation-works-with-logrotate.html – long.kl Jan 11 '22 at 09:39

1 Answers1

1

It is up to 3 files. Once the log file, say mylog.txt size reaches 5MB it gets rotated, i.e. renamed to mylog.1txt and a new empty one with the original name mylog.txt is created. Once the new one reaches 5MB the previous one is renamed to mylog.2txt and the current one to mylog.1txt and a new empty one is created again with the original name mylog.txt. Once the limit is reached files are no longer rotated and after reaching the limit the current file is truncated instead.

The spdlog implementation is relatively straightforward. It is very easy to analyse it. See rotating algorithm and renaming algorithm

tomaszmi
  • 443
  • 2
  • 6