mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-29 09:59:33 +08:00
Updated tests
This commit is contained in:
@@ -85,8 +85,9 @@ TEST_CASE("daily_logger", "[daily_logger]]")
|
||||
// calculate filename (time based)
|
||||
std::string basename = "logs/daily_log";
|
||||
std::tm tm = spdlog::details::os::localtime();
|
||||
fmt::MemoryWriter w;
|
||||
w.write("{}_{:04d}-{:02d}-{:02d}_{:02d}-{:02d}", basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min);
|
||||
fmt::memory_buffer w;
|
||||
fmt::format_to(
|
||||
w, "{}_{:04d}-{:02d}-{:02d}_{:02d}-{:02d}", basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min);
|
||||
|
||||
auto logger = spdlog::daily_logger_mt("logger", basename, 0, 0);
|
||||
logger->flush_on(spdlog::level::info);
|
||||
@@ -95,7 +96,7 @@ TEST_CASE("daily_logger", "[daily_logger]]")
|
||||
logger->info("Test message {}", i);
|
||||
}
|
||||
|
||||
auto filename = w.str();
|
||||
auto filename = fmt::to_string(w);
|
||||
REQUIRE(count_lines(filename) == 10);
|
||||
}
|
||||
|
||||
@@ -107,8 +108,8 @@ TEST_CASE("daily_logger with dateonly calculator", "[daily_logger_dateonly]]")
|
||||
// calculate filename (time based)
|
||||
std::string basename = "logs/daily_dateonly";
|
||||
std::tm tm = spdlog::details::os::localtime();
|
||||
fmt::MemoryWriter w;
|
||||
w.write("{}_{:04d}-{:02d}-{:02d}", basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
|
||||
fmt::memory_buffer w;
|
||||
fmt::format_to(w, "{}_{:04d}-{:02d}-{:02d}", basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
|
||||
|
||||
auto logger = spdlog::create<sink_type>("logger", basename, 0, 0);
|
||||
for (int i = 0; i < 10; ++i)
|
||||
@@ -117,7 +118,7 @@ TEST_CASE("daily_logger with dateonly calculator", "[daily_logger_dateonly]]")
|
||||
logger->info("Test message {}", i);
|
||||
}
|
||||
logger->flush();
|
||||
auto filename = w.str();
|
||||
auto filename = fmt::to_string(w);
|
||||
REQUIRE(count_lines(filename) == 10);
|
||||
}
|
||||
|
||||
@@ -126,9 +127,9 @@ struct custom_daily_file_name_calculator
|
||||
static spdlog::filename_t calc_filename(const spdlog::filename_t &basename)
|
||||
{
|
||||
std::tm tm = spdlog::details::os::localtime();
|
||||
fmt::MemoryWriter w;
|
||||
w.write("{}{:04d}{:02d}{:02d}", basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
|
||||
return w.str();
|
||||
fmt::memory_buffer w;
|
||||
fmt::format_to(w, "{}{:04d}{:02d}{:02d}", basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
|
||||
return fmt::to_string(w);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -140,8 +141,8 @@ TEST_CASE("daily_logger with custom calculator", "[daily_logger_custom]]")
|
||||
// calculate filename (time based)
|
||||
std::string basename = "logs/daily_dateonly";
|
||||
std::tm tm = spdlog::details::os::localtime();
|
||||
fmt::MemoryWriter w;
|
||||
w.write("{}{:04d}{:02d}{:02d}", basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
|
||||
fmt::memory_buffer w;
|
||||
fmt::format_to(w, "{}{:04d}{:02d}{:02d}", basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
|
||||
|
||||
auto logger = spdlog::create<sink_type>("logger", basename, 0, 0);
|
||||
for (int i = 0; i < 10; ++i)
|
||||
@@ -150,7 +151,7 @@ TEST_CASE("daily_logger with custom calculator", "[daily_logger_custom]]")
|
||||
}
|
||||
|
||||
logger->flush();
|
||||
auto filename = w.str();
|
||||
auto filename = fmt::to_string(w);
|
||||
REQUIRE(count_lines(filename) == 10);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user