mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-30 02:19:35 +08:00
file sinks refactoring
This commit is contained in:
@@ -8,27 +8,36 @@
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
|
||||
auto null_sink = std::make_shared<c11log::sinks::null_sink>();
|
||||
auto async = std::make_shared<c11log::sinks::async_sink>(100);
|
||||
auto fsink = std::make_shared<c11log::sinks::rotating_file_sink>("newlog", "txt", 1024*1024*10 , 2);
|
||||
|
||||
async->add_sink(fsink);
|
||||
|
||||
c11log::logger logger("test");
|
||||
|
||||
auto screen_sink = std::make_shared<c11log::sinks::stdout_sink>();
|
||||
auto file_sink = std::make_shared<c11log::sinks::midnight_file_sink>("logtest");
|
||||
auto async = std::make_shared<c11log::sinks::async_sink>(1000);
|
||||
async->add_sink(file_sink);
|
||||
logger.add_sink(async);
|
||||
//logger.add_sink(file_sink);
|
||||
|
||||
|
||||
auto fn = [&logger]()
|
||||
std::atomic<uint32_t> counter { 0 };
|
||||
auto counter_ptr = &counter;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
logger.info() << "Hello logger!";
|
||||
};
|
||||
utils::bench("test log", std::chrono::seconds(3), fn);
|
||||
logger.info() << "bye";
|
||||
utils::bench("shutdown", [&async]() {
|
||||
async->shutdown(std::chrono::seconds(10));
|
||||
});
|
||||
|
||||
new std::thread([&logger, counter_ptr]() {
|
||||
while (true)
|
||||
{
|
||||
logger.info() << "Hello from thread" << std::this_thread::get_id();
|
||||
(*counter_ptr)++;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
while (true)
|
||||
{
|
||||
counter = 0;
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
std::cout << "Counter = " << utils::format(counter.load()) << std::endl;
|
||||
}
|
||||
async->shutdown(std::chrono::seconds(10));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user