2014-02-22 04:51:54 +08:00
|
|
|
// example.cpp : Simple logger example
|
2014-01-25 21:52:10 +08:00
|
|
|
//
|
2014-10-10 07:46:03 +08:00
|
|
|
#include <mutex>
|
2014-01-27 03:23:26 +08:00
|
|
|
#include "c11log/logger.h"
|
2014-03-29 00:03:24 +08:00
|
|
|
#include "c11log/sinks/async_sink.h"
|
2014-01-27 03:23:26 +08:00
|
|
|
#include "c11log/sinks/file_sinks.h"
|
2014-10-10 07:46:03 +08:00
|
|
|
#include "c11log/sinks/stdout_sinks.h"
|
2014-08-12 05:04:17 +08:00
|
|
|
#include "c11log/sinks/null_sink.h"
|
2014-01-27 03:23:26 +08:00
|
|
|
#include "utils.h"
|
2014-01-25 21:52:10 +08:00
|
|
|
|
2014-03-08 22:18:57 +08:00
|
|
|
using std::cout;
|
|
|
|
using std::endl;
|
|
|
|
using namespace std::chrono;
|
|
|
|
using namespace c11log;
|
|
|
|
using namespace utils;
|
2014-02-01 07:47:37 +08:00
|
|
|
|
2014-10-10 07:46:03 +08:00
|
|
|
|
2014-01-25 21:52:10 +08:00
|
|
|
int main(int argc, char* argv[])
|
2014-05-13 06:41:04 +08:00
|
|
|
{
|
2014-05-06 22:38:11 +08:00
|
|
|
|
2014-10-10 07:46:03 +08:00
|
|
|
const unsigned int howmany = argc <= 1 ? 10000 : atoi(argv[1]);
|
|
|
|
|
2014-10-10 08:36:50 +08:00
|
|
|
logger cout_logger("example", std::make_shared<sinks::stderr_sink_mt>());
|
2014-05-09 20:27:06 +08:00
|
|
|
cout_logger.info() << "Hello logger";
|
2014-03-29 06:37:29 +08:00
|
|
|
|
2014-10-10 07:46:03 +08:00
|
|
|
//auto nullsink = std::make_shared<sinks::null_sink<std::mutex>>();
|
2014-10-10 08:36:50 +08:00
|
|
|
auto nullsink = std::make_shared<sinks::null_sink<details::null_mutex>>();
|
|
|
|
auto fsink = std::make_shared<sinks::rotating_file_sink_st>("log", "txt", 1024*1024*50 , 5, 10);
|
|
|
|
auto as = std::make_shared<sinks::async_sink>(1000);
|
|
|
|
|
2014-03-14 20:35:46 +08:00
|
|
|
|
2014-10-10 07:46:03 +08:00
|
|
|
logger my_logger("my_logger", fsink);
|
2014-03-08 22:40:47 +08:00
|
|
|
|
2014-03-31 07:16:03 +08:00
|
|
|
|
2014-03-01 20:06:58 +08:00
|
|
|
auto start = system_clock::now();
|
2014-05-09 20:27:06 +08:00
|
|
|
for (unsigned int i = 1; i <= howmany; ++i)
|
2014-05-11 07:56:27 +08:00
|
|
|
my_logger.info() << "Hello logger: msg #" << i;
|
2014-03-04 07:23:38 +08:00
|
|
|
|
2014-10-10 08:36:50 +08:00
|
|
|
|
2014-03-01 20:06:58 +08:00
|
|
|
auto delta = system_clock::now() - start;
|
2014-03-28 21:05:09 +08:00
|
|
|
auto delta_d = duration_cast<duration<double>> (delta).count();
|
2014-03-29 06:37:29 +08:00
|
|
|
|
2014-05-13 06:41:04 +08:00
|
|
|
cout << "Total:" << format(howmany) << endl;
|
2014-10-10 07:46:03 +08:00
|
|
|
cout << "Delta:" << format(delta_d) << endl;
|
|
|
|
cout << "Rate:" << format(howmany / delta_d) << "/sec" << endl;
|
|
|
|
|
2014-03-01 20:06:58 +08:00
|
|
|
return 0;
|
2014-02-09 07:25:23 +08:00
|
|
|
}
|
2014-01-25 21:52:10 +08:00
|
|
|
|