2014-02-22 04:51:54 +08:00
|
|
|
// example.cpp : Simple logger example
|
2014-01-25 21:52:10 +08:00
|
|
|
//
|
2014-02-22 04:51:54 +08:00
|
|
|
#include <string>
|
2014-01-29 10:00:05 +08:00
|
|
|
#include <functional>
|
2014-01-27 03:23:26 +08:00
|
|
|
#include "c11log/logger.h"
|
|
|
|
#include "c11log/sinks/async_sink.h"
|
|
|
|
#include "c11log/sinks/file_sinks.h"
|
2014-03-07 07:33:53 +08:00
|
|
|
#include "c11log/sinks/console_sinks.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-01-25 21:52:10 +08:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2014-03-04 07:23:38 +08:00
|
|
|
if(argc || argv) {};
|
2014-03-08 22:18:57 +08:00
|
|
|
|
2014-03-14 20:35:46 +08:00
|
|
|
auto fsink = std::make_shared<sinks::rotating_file_sink>("log", "txt", 1024*1024*50 , 5, 0);
|
2014-03-04 06:08:30 +08:00
|
|
|
auto null_sink = std::make_shared<sinks::null_sink>();
|
2014-03-14 20:35:46 +08:00
|
|
|
|
2014-03-08 22:18:57 +08:00
|
|
|
|
2014-03-08 22:40:47 +08:00
|
|
|
logger cout_logger ("cout", {null_sink, sinks::stdout_sink()});
|
2014-03-08 22:18:57 +08:00
|
|
|
|
|
|
|
cout_logger.info() << "Hello cout logger!";
|
|
|
|
|
2014-03-14 20:35:46 +08:00
|
|
|
|
|
|
|
logger my_logger ("my_logger", {fsink});
|
2014-03-08 22:40:47 +08:00
|
|
|
|
2014-03-01 20:06:58 +08:00
|
|
|
auto start = system_clock::now();
|
2014-03-02 22:36:06 +08:00
|
|
|
|
2014-03-16 03:05:11 +08:00
|
|
|
const unsigned int howmany = 15000000;
|
2014-03-01 20:06:58 +08:00
|
|
|
for(unsigned int i = 0; i < howmany ; i++)
|
2014-03-02 22:36:06 +08:00
|
|
|
my_logger.info() << "Hello logger " << i;
|
2014-03-04 07:23:38 +08:00
|
|
|
|
|
|
|
//async->shutdown(seconds(3));
|
2014-03-01 20:06:58 +08:00
|
|
|
auto delta = system_clock::now() - start;
|
|
|
|
auto delta_d = duration_cast<duration<double>> (delta);
|
|
|
|
cout << "Total " << format(howmany) << endl;
|
|
|
|
cout << "Delta " << format(delta_d.count()) << endl;
|
|
|
|
cout << "Rate: " << format(howmany/delta_d.count()) << "/sec" << endl;
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
2014-03-08 22:40:47 +08:00
|
|
|
|
2014-03-04 07:23:38 +08:00
|
|
|
/*
|
2014-02-22 04:51:54 +08: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-09 07:25:23 +08:00
|
|
|
|
2014-03-01 20:06:58 +08:00
|
|
|
|
2014-02-22 07:16:59 +08: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 20:06:58 +08:00
|
|
|
auto fsink = std::make_shared<sinks::rotating_file_sink>("log", "txt", 1024*1024*50 , 5, std::chrono::milliseconds(1000));
|
2014-02-09 07:25:23 +08:00
|
|
|
|
2014-02-22 04:51:54 +08:00
|
|
|
async->add_sink(fsink);
|
2014-02-09 07:25:23 +08:00
|
|
|
|
2014-03-01 20:06:58 +08:00
|
|
|
//auto &logger = c11log::get_logger("async");
|
|
|
|
//logger.add_sink(fsink);
|
|
|
|
|
|
|
|
|
2014-02-09 07:25:23 +08:00
|
|
|
|
2014-02-22 04:51:54 +08:00
|
|
|
testlog(threads);
|
2014-03-04 06:08:30 +08:00
|
|
|
*/
|
2014-02-09 07:25:23 +08:00
|
|
|
}
|
2014-01-25 21:52:10 +08:00
|
|
|
|