mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-29 09:59:33 +08:00
Handle file extensions in rotating and daily loggers
This commit is contained in:
@@ -188,3 +188,55 @@ TEST_CASE("daily_logger with custom calculator", "[daily_logger_custom]]")
|
||||
REQUIRE(count_lines(filename) == 10);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* File name calculations
|
||||
*/
|
||||
|
||||
TEST_CASE("rotating_file_sink::calc_filename1", "[rotating_file_sink]]")
|
||||
{
|
||||
auto filename = spdlog::sinks::rotating_file_sink_st::calc_filename("rotated.txt", 3);
|
||||
REQUIRE(filename == "rotated.3.txt");
|
||||
}
|
||||
|
||||
TEST_CASE("rotating_file_sink::calc_filename2", "[rotating_file_sink]]")
|
||||
{
|
||||
auto filename = spdlog::sinks::rotating_file_sink_st::calc_filename("rotated", 3);
|
||||
REQUIRE(filename == "rotated.3");
|
||||
}
|
||||
|
||||
TEST_CASE("rotating_file_sink::calc_filename3", "[rotating_file_sink]]")
|
||||
{
|
||||
auto filename = spdlog::sinks::rotating_file_sink_st::calc_filename("rotated.txt", 0);
|
||||
REQUIRE(filename == "rotated.txt");
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("daily_file_sink::default_daily_file_name_calculator1", "[daily_file_sink]]")
|
||||
{
|
||||
// daily.YYYY-MM-DD_hh-mm.txt
|
||||
auto filename = spdlog::sinks::default_daily_file_name_calculator::calc_filename("daily.txt");
|
||||
std::regex re(R"(^daily_(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])_\d\d-[0-5][0-9].txt$)");
|
||||
std::smatch match;
|
||||
REQUIRE(std::regex_match(filename, match, re));
|
||||
}
|
||||
|
||||
TEST_CASE("daily_file_sink::default_daily_file_name_calculator2", "[daily_file_sink]]")
|
||||
{
|
||||
// daily.YYYY-MM-DD_hh-mm.txt
|
||||
auto filename = spdlog::sinks::default_daily_file_name_calculator::calc_filename("daily");
|
||||
std::regex re(R"(^daily_(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])_\d\d-[0-5][0-9]$)");
|
||||
std::smatch match;
|
||||
REQUIRE(std::regex_match(filename, match, re));
|
||||
}
|
||||
|
||||
TEST_CASE("daily_file_sink::dateonly_daily_file_name_calculator", "[daily_file_sink]]")
|
||||
{
|
||||
// daily.YYYY-MM-DD_hh-mm.txt
|
||||
auto filename = spdlog::sinks::dateonly_daily_file_name_calculator::calc_filename("daily.txt");
|
||||
// date regex based on https://www.regular-expressions.info/dates.html
|
||||
std::regex re(R"(^daily_(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])\.txt$)");
|
||||
std::smatch match;
|
||||
REQUIRE(std::regex_match(filename, match, re));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user