spdlog/example/example.cpp

48 lines
1.3 KiB
C++
Raw Normal View History

2014-02-22 04:51:54 +08:00
// example.cpp : Simple logger example
2014-01-25 21:52:10 +08:00
//
2014-03-22 22:26:08 +08:00
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-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
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-03-22 22:26:08 +08:00
2014-01-25 21:52:10 +08:00
int main(int argc, char* argv[])
{
2014-03-17 02:48:37 +08:00
const unsigned int howmany = argc <= 1 ? 1000000:atoi(argv[1]);
2014-03-29 06:38:05 +08:00
logger cout_logger ("", sinks::stdout_sink());
2014-03-29 07:25:52 +08:00
cout_logger.info() << "Hello " << "man";
2014-03-29 06:37:29 +08:00
auto fsink = std::make_shared<sinks::rotating_file_sink>("log", "txt", 1024*1024*50 , 5, 0);
auto fsink2 = std::make_shared<sinks::rotating_file_sink>("lllog", "txt", 1024*1024*50 , 5, 0);
2014-03-29 18:28:50 +08:00
auto as = std::make_shared<sinks::async_sink>(1000);
as->add_sink(sinks::null_sink::get());
2014-03-29 18:04:42 +08:00
logger my_logger ("my_logger", as);
2014-03-08 22:40:47 +08:00
2014-03-01 20:06:58 +08:00
auto start = system_clock::now();
for(unsigned int i = 1; i <= howmany ; ++i)
my_logger.info() << "Hello logger: " << i;
2014-03-04 07:23:38 +08:00
2014-03-31 04:47:42 +08:00
auto s = howmany - as->q().size();
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-03-31 04:47:42 +08:00
cout_logger.info() << "Total:" << format(s);
2014-03-29 07:25:52 +08:00
cout_logger.info() << "Delta:" << format(delta_d);
2014-03-31 04:47:42 +08:00
cout_logger.info() << "Rate:" << format(s/delta_d) << "/sec";
2014-03-01 20:06:58 +08:00
return 0;
}
2014-01-25 21:52:10 +08:00