2014-02-21 15:51:54 -05:00
|
|
|
// example.cpp : Simple logger example
|
2014-01-25 08:52:10 -05:00
|
|
|
//
|
2014-03-22 10:26:08 -04:00
|
|
|
|
2014-01-26 14:23:26 -05:00
|
|
|
#include "c11log/logger.h"
|
2014-03-28 12:03:24 -04:00
|
|
|
#include "c11log/sinks/async_sink.h"
|
2014-01-26 14:23:26 -05:00
|
|
|
#include "c11log/sinks/file_sinks.h"
|
2014-03-06 18:33:53 -05:00
|
|
|
#include "c11log/sinks/console_sinks.h"
|
2014-01-26 14:23:26 -05:00
|
|
|
|
|
|
|
#include "utils.h"
|
2014-01-25 08:52:10 -05:00
|
|
|
|
2014-03-08 09:18:57 -05:00
|
|
|
using std::cout;
|
|
|
|
using std::endl;
|
|
|
|
using namespace std::chrono;
|
|
|
|
using namespace c11log;
|
|
|
|
using namespace utils;
|
2014-01-31 18:47:37 -05:00
|
|
|
|
2014-03-22 10:26:08 -04:00
|
|
|
|
2014-01-25 08:52:10 -05:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2014-03-16 14:48:37 -04:00
|
|
|
|
2014-03-19 21:47:57 -04:00
|
|
|
if(argc || argv) {};
|
2014-03-28 17:27:13 -04:00
|
|
|
const unsigned int howmany = argc <= 1 ? 1000 :atoi(argv[1]);
|
2014-03-08 09:18:57 -05:00
|
|
|
|
2014-03-14 08:35:46 -04:00
|
|
|
auto fsink = std::make_shared<sinks::rotating_file_sink>("log", "txt", 1024*1024*50 , 5, 0);
|
2014-03-03 17:08:30 -05:00
|
|
|
auto null_sink = std::make_shared<sinks::null_sink>();
|
2014-03-14 08:35:46 -04:00
|
|
|
|
2014-03-28 17:27:13 -04:00
|
|
|
|
2014-03-28 12:03:24 -04:00
|
|
|
logger cout_logger ("cout", {sinks::stdout_sink()});
|
2014-03-08 09:18:57 -05:00
|
|
|
|
2014-03-16 13:51:43 -04:00
|
|
|
logger my_logger ("my_logger", {null_sink});
|
2014-03-08 09:40:47 -05:00
|
|
|
|
2014-03-01 07:06:58 -05:00
|
|
|
auto start = system_clock::now();
|
|
|
|
for(unsigned int i = 0; i < howmany ; i++)
|
2014-03-28 17:27:13 -04:00
|
|
|
my_logger.info("Hello logger");
|
2014-03-03 18:23:38 -05:00
|
|
|
|
2014-03-28 12:03:24 -04:00
|
|
|
|
2014-03-01 07:06:58 -05:00
|
|
|
auto delta = system_clock::now() - start;
|
2014-03-28 09:05:09 -04:00
|
|
|
auto delta_d = duration_cast<duration<double>> (delta).count();
|
2014-03-28 17:27:13 -04:00
|
|
|
cout_logger.info("Total ") << format(howmany);
|
|
|
|
cout_logger.info("Delta ") << format(delta_d);
|
|
|
|
cout_logger.info("Rate: ") << format(howmany/delta_d) << "/sec";
|
2014-03-01 07:06:58 -05:00
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
2014-03-08 09:40:47 -05:00
|
|
|
|
2014-03-03 18:23:38 -05:00
|
|
|
/*
|
2014-02-21 15:51:54 -05:00
|
|
|
if(argc !=3) {
|
|
|
|
std::cerr << "Usage: " << argv[0] << " qsize, threads" << std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int qsize = atoi(argv[1]);
|
|
|
|
int threads = atoi(argv[2]);
|
2014-02-08 18:25:23 -05:00
|
|
|
|
2014-03-01 07:06:58 -05:00
|
|
|
|
2014-02-21 18:16:59 -05:00
|
|
|
auto null_sink = std::make_shared<sinks::null_sink>();
|
|
|
|
auto stdout_sink = std::make_shared<sinks::stdout_sink>();
|
|
|
|
auto async = std::make_shared<sinks::async_sink>(qsize);
|
2014-03-01 07:06:58 -05:00
|
|
|
auto fsink = std::make_shared<sinks::rotating_file_sink>("log", "txt", 1024*1024*50 , 5, std::chrono::milliseconds(1000));
|
2014-02-08 18:25:23 -05:00
|
|
|
|
2014-02-21 15:51:54 -05:00
|
|
|
async->add_sink(fsink);
|
2014-02-08 18:25:23 -05:00
|
|
|
|
2014-03-01 07:06:58 -05:00
|
|
|
//auto &logger = c11log::get_logger("async");
|
|
|
|
//logger.add_sink(fsink);
|
|
|
|
|
|
|
|
|
2014-02-08 18:25:23 -05:00
|
|
|
|
2014-02-21 15:51:54 -05:00
|
|
|
testlog(threads);
|
2014-03-03 17:08:30 -05:00
|
|
|
*/
|
2014-02-08 18:25:23 -05:00
|
|
|
}
|
2014-01-25 08:52:10 -05:00
|
|
|
|