spdlog icon indicating copy to clipboard operation
spdlog copied to clipboard

How can I Set/Change the log rename in log rotation?

Open Candy-Cao opened this issue 3 years ago • 2 comments

Candy-Cao avatar Sep 20 '22 07:09 Candy-Cao

rotating log rename with index,but i want to replace it with datatime;

Candy-Cao avatar Sep 20 '22 08:09 Candy-Cao

i want to replace it with datatime;

datetime? if so, you can use spdlog::sinks::daily_file_sink. Wiki: https://github.com/gabime/spdlog/wiki/4.-Sinks

tt4g avatar Sep 20 '22 08:09 tt4g

But what if you don't want a new file every day? Rotating file by size and then add the current timestamp to the freshly renamed file. That would be a great feature!

jgreber avatar Sep 22 '22 18:09 jgreber

@jgreber Timestamp and index rotation are not supported.

See spdlog::sinks::rotating_file_sink rotation method. Rotation is done by calculating the index to be given at the end of the file from max_files_.

https://github.com/gabime/spdlog/blob/81de01c02c2b49aa723806b0c1d557dd05721635/include/spdlog/sinks/rotating_file_sink-inl.h#L115-L137

If the timestamp is added to the filename, rotation will not be possible. This is because the timestamp set in the file will not be known when calculating the index.

tt4g avatar Sep 22 '22 21:09 tt4g