2014-01-25 08:52:10 -05:00
|
|
|
// test.cpp : Defines the entry point for the console application.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
|
|
|
|
|
2014-01-25 10:28:56 -05:00
|
|
|
|
2014-01-25 08:52:10 -05:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
|
2014-01-25 10:28:56 -05:00
|
|
|
|
2014-01-25 18:53:23 -05:00
|
|
|
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);
|
2014-01-25 10:28:56 -05:00
|
|
|
|
2014-01-25 18:53:23 -05:00
|
|
|
async->add_sink(fsink);
|
2014-01-25 10:28:56 -05:00
|
|
|
|
2014-01-25 18:53:23 -05:00
|
|
|
c11log::logger logger("test");
|
|
|
|
logger.add_sink(async);
|
2014-01-25 10:28:56 -05:00
|
|
|
|
2014-01-25 18:53:23 -05:00
|
|
|
std::atomic<uint32_t> counter { 0 };
|
|
|
|
auto counter_ptr = &counter;
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
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));
|
2014-01-25 08:52:10 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|