mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-13 17:22:06 +08:00
format
This commit is contained in:
parent
8e429ae5d6
commit
8bd16feb36
@ -45,7 +45,7 @@ int main(int argc, char *argv[])
|
|||||||
threads = atoi(argv[2]);
|
threads = atoi(argv[2]);
|
||||||
if (argc > 3)
|
if (argc > 3)
|
||||||
queue_size = atoi(argv[3]);
|
queue_size = atoi(argv[3]);
|
||||||
|
|
||||||
cout << "*******************************************************************************\n";
|
cout << "*******************************************************************************\n";
|
||||||
cout << "Single thread, " << format(howmany) << " iterations" << endl;
|
cout << "Single thread, " << format(howmany) << " iterations" << endl;
|
||||||
cout << "*******************************************************************************\n";
|
cout << "*******************************************************************************\n";
|
||||||
|
@ -105,7 +105,7 @@ int main(int, char *[])
|
|||||||
|
|
||||||
void async_example()
|
void async_example()
|
||||||
{
|
{
|
||||||
size_t q_size = 4096;
|
size_t q_size = 4096;
|
||||||
spdlog::set_async_mode(q_size);
|
spdlog::set_async_mode(q_size);
|
||||||
auto async_file = spd::daily_logger_st("async_file_logger", "logs/async_log.txt");
|
auto async_file = spd::daily_logger_st("async_file_logger", "logs/async_log.txt");
|
||||||
for (int i = 0; i < 100; ++i)
|
for (int i = 0; i < 100; ++i)
|
||||||
|
@ -39,7 +39,7 @@ TEST_CASE("discard policy ", "[async]")
|
|||||||
auto test_sink = std::make_shared<spdlog::sinks::test_sink_mt>();
|
auto test_sink = std::make_shared<spdlog::sinks::test_sink_mt>();
|
||||||
size_t queue_size = 2;
|
size_t queue_size = 2;
|
||||||
size_t messages = 1024;
|
size_t messages = 1024;
|
||||||
spdlog::drop("as");
|
spdlog::drop("as");
|
||||||
auto logger = spdlog::create_async("as", test_sink, queue_size, spdlog::async_overflow_policy::discard_log_msg);
|
auto logger = spdlog::create_async("as", test_sink, queue_size, spdlog::async_overflow_policy::discard_log_msg);
|
||||||
for (size_t i = 0; i < messages; i++)
|
for (size_t i = 0; i < messages; i++)
|
||||||
{
|
{
|
||||||
@ -53,28 +53,25 @@ TEST_CASE("discard policy ", "[async]")
|
|||||||
REQUIRE(test_sink->flushed_msg_counter() < messages);
|
REQUIRE(test_sink->flushed_msg_counter() < messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE("flush", "[async]")
|
TEST_CASE("flush", "[async]")
|
||||||
{
|
{
|
||||||
auto test_sink = std::make_shared<spdlog::sinks::test_sink_mt>();
|
auto test_sink = std::make_shared<spdlog::sinks::test_sink_mt>();
|
||||||
size_t queue_size = 256;
|
size_t queue_size = 256;
|
||||||
size_t messages = 256;
|
size_t messages = 256;
|
||||||
spdlog::drop("as");
|
spdlog::drop("as");
|
||||||
auto logger = std::make_shared<spdlog::async_logger>("as", test_sink, queue_size);
|
auto logger = std::make_shared<spdlog::async_logger>("as", test_sink, queue_size);
|
||||||
for (size_t i = 0; i < messages; i++)
|
for (size_t i = 0; i < messages; i++)
|
||||||
{
|
{
|
||||||
logger->info("Hello message #{}", i);
|
logger->info("Hello message #{}", i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// the dtor wait for all messages in the queue to get processed
|
// the dtor wait for all messages in the queue to get processed
|
||||||
logger->flush();
|
logger->flush();
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(250));
|
std::this_thread::sleep_for(std::chrono::milliseconds(250));
|
||||||
REQUIRE(test_sink->msg_counter() == messages);
|
REQUIRE(test_sink->msg_counter() == messages);
|
||||||
REQUIRE(test_sink->flushed_msg_counter() == messages);
|
REQUIRE(test_sink->flushed_msg_counter() == messages);
|
||||||
|
|
||||||
|
REQUIRE(test_sink->flushed_msg_counter() == messages);
|
||||||
REQUIRE(test_sink->flushed_msg_counter() == messages);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("multi threads", "[async]")
|
TEST_CASE("multi threads", "[async]")
|
||||||
@ -82,8 +79,8 @@ TEST_CASE("multi threads", "[async]")
|
|||||||
auto test_sink = std::make_shared<spdlog::sinks::test_sink_mt>();
|
auto test_sink = std::make_shared<spdlog::sinks::test_sink_mt>();
|
||||||
size_t queue_size = 128;
|
size_t queue_size = 128;
|
||||||
size_t messages = 256;
|
size_t messages = 256;
|
||||||
size_t n_threads = 10;
|
size_t n_threads = 10;
|
||||||
auto logger = std::make_shared<spdlog::async_logger>("as", test_sink, queue_size);
|
auto logger = std::make_shared<spdlog::async_logger>("as", test_sink, queue_size);
|
||||||
|
|
||||||
std::vector<std::thread> threads;
|
std::vector<std::thread> threads;
|
||||||
for (size_t i = 0; i < n_threads; i++)
|
for (size_t i = 0; i < n_threads; i++)
|
||||||
@ -102,22 +99,21 @@ TEST_CASE("multi threads", "[async]")
|
|||||||
}
|
}
|
||||||
|
|
||||||
// the dtor wait for all messages in the queue to get processed
|
// the dtor wait for all messages in the queue to get processed
|
||||||
logger.reset();
|
logger.reset();
|
||||||
REQUIRE(test_sink->msg_counter() == messages * n_threads);
|
REQUIRE(test_sink->msg_counter() == messages * n_threads);
|
||||||
REQUIRE(test_sink->flushed_msg_counter() == messages * n_threads);
|
REQUIRE(test_sink->flushed_msg_counter() == messages * n_threads);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE("to_file", "[async]")
|
TEST_CASE("to_file", "[async]")
|
||||||
{
|
{
|
||||||
|
|
||||||
prepare_logdir();
|
prepare_logdir();
|
||||||
size_t queue_size = 512;
|
size_t queue_size = 512;
|
||||||
size_t messages = 512;
|
size_t messages = 512;
|
||||||
size_t n_threads = 4;
|
size_t n_threads = 4;
|
||||||
auto file_sink = std::make_shared<spdlog::sinks::simple_file_sink_mt>("logs/async_test.log", true);
|
auto file_sink = std::make_shared<spdlog::sinks::simple_file_sink_mt>("logs/async_test.log", true);
|
||||||
auto logger = spdlog::create_async("as", file_sink, queue_size);
|
auto logger = spdlog::create_async("as", file_sink, queue_size);
|
||||||
std::vector<std::thread> threads;
|
std::vector<std::thread> threads;
|
||||||
for (size_t i = 0; i < n_threads; i++)
|
for (size_t i = 0; i < n_threads; i++)
|
||||||
{
|
{
|
||||||
threads.emplace_back([logger, messages] {
|
threads.emplace_back([logger, messages] {
|
||||||
@ -132,9 +128,7 @@ TEST_CASE("to_file", "[async]")
|
|||||||
{
|
{
|
||||||
t.join();
|
t.join();
|
||||||
}
|
}
|
||||||
logger.reset();
|
logger.reset();
|
||||||
spdlog::drop("as");
|
spdlog::drop("as");
|
||||||
REQUIRE(count_lines("logs/async_test.log") == messages * n_threads);
|
REQUIRE(count_lines("logs/async_test.log") == messages * n_threads);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user