2014-10-10 18:15:26 -04:00
|
|
|
// example.cpp : Simple logger example
|
|
|
|
//
|
|
|
|
#include <mutex>
|
|
|
|
#include "c11log/logger.h"
|
|
|
|
#include "c11log/sinks/async_sink.h"
|
|
|
|
#include "c11log/sinks/file_sinks.h"
|
|
|
|
#include "c11log/sinks/stdout_sinks.h"
|
|
|
|
#include "c11log/sinks/null_sink.h"
|
|
|
|
#include "utils.h"
|
2014-10-24 11:01:11 -04:00
|
|
|
#include "c11log/details/registry.h"
|
2014-10-10 18:15:26 -04:00
|
|
|
|
|
|
|
using namespace std::chrono;
|
|
|
|
using namespace c11log;
|
|
|
|
using namespace utils;
|
|
|
|
|
|
|
|
|
2014-10-18 12:04:24 -04:00
|
|
|
int main(int argc, char* argv[])
|
2014-10-10 18:15:26 -04:00
|
|
|
{
|
2014-10-23 18:59:39 -04:00
|
|
|
const unsigned int howmany = argc <= 1 ? 600000 : atoi(argv[1]);
|
2014-10-10 18:15:26 -04:00
|
|
|
|
2014-10-24 11:01:11 -04:00
|
|
|
auto console = c11log::create<sinks::stderr_sink_st>("reporter");
|
|
|
|
console->set_format("[%n %l] %t");
|
|
|
|
console->set_level(c11log::level::INFO);
|
|
|
|
console->info("Starting bench with", howmany, "iterations..");
|
2014-10-10 18:15:26 -04:00
|
|
|
|
2014-10-24 11:01:11 -04:00
|
|
|
auto bench = c11log::create<sinks::rotating_file_sink_st>("bench", "myrotating", "txt", 1024 * 1024 * 5, 3, 100);
|
2014-10-10 18:15:26 -04:00
|
|
|
auto start = system_clock::now();
|
|
|
|
for (unsigned int i = 1; i <= howmany; ++i)
|
2014-10-23 18:59:39 -04:00
|
|
|
{
|
2014-10-24 11:01:11 -04:00
|
|
|
bench->info() << "Hello logger: msg number " << i;
|
2014-10-23 18:59:39 -04:00
|
|
|
}
|
2014-10-13 20:44:40 -04:00
|
|
|
|
2014-10-10 18:15:26 -04:00
|
|
|
auto delta = system_clock::now() - start;
|
|
|
|
auto delta_d = duration_cast<duration<double>> (delta).count();
|
|
|
|
|
2014-10-24 11:01:11 -04:00
|
|
|
console->info("Total:") << format(howmany);
|
|
|
|
console->info("Delta:") << format(delta_d);
|
|
|
|
console->info("Rate:") << format(howmany / delta_d) << "/sec";
|
2014-10-10 18:15:26 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|