From a3f54ce5076ed7c15aa1bad65fbc7a86c7f9e725 Mon Sep 17 00:00:00 2001 From: Dilshod Mukhtarov Date: Fri, 2 Oct 2020 19:09:48 +0400 Subject: [PATCH] Added callback example for file rotation section --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 5d849eb2..70b3f64d 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,22 @@ void rotating_example() } ``` +It's possible to use callback for manipulating (compressing, copying somewhere, etc) the newly completed and rotated log file (essentially `rotating.1.txt` in this example). If that callback compresses and appends extension (ex. `.gz`) it has to be mentioned in the parameters, otherwise keep it empty string. The callback can be any functional which accepts `spdlog::filename_t` parameter to manipulate it. +```c++ +#include "spdlog/sinks/rotating_file_sink.h" +#include +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, ".gz", [](spdlog::filename_t filename){ + std::system(std::string("gzip " + filename).c_str()); + }); +} +``` + + --- #### Daily files ```c++