2014-10-11 06:15:26 +08:00
|
|
|
// example.cpp : Simple logger example
|
|
|
|
//
|
2014-10-30 06:11:06 +08:00
|
|
|
#include "spitlog/logger.h"
|
|
|
|
#include "spitlog/sinks/async_sink.h"
|
|
|
|
#include "spitlog/sinks/file_sinks.h"
|
|
|
|
#include "spitlog/sinks/stdout_sinks.h"
|
|
|
|
#include "spitlog/sinks/null_sink.h"
|
2014-10-11 06:15:26 +08:00
|
|
|
#include "utils.h"
|
2014-10-30 06:11:06 +08:00
|
|
|
#include "spitlog/details/registry.h"
|
2014-10-11 06:15:26 +08:00
|
|
|
|
|
|
|
using namespace std::chrono;
|
2014-10-30 06:11:06 +08:00
|
|
|
using namespace spitlog;
|
2014-10-11 06:15:26 +08:00
|
|
|
using namespace utils;
|
|
|
|
|
|
|
|
|
2014-10-19 00:04:24 +08:00
|
|
|
int main(int argc, char* argv[])
|
2014-10-11 06:15:26 +08:00
|
|
|
{
|
2014-10-26 07:29:50 +08:00
|
|
|
try {
|
2014-10-30 06:11:06 +08:00
|
|
|
const unsigned int howmany = argc <= 1 ? 1500000 : atoi(argv[1]);
|
2014-10-26 07:29:50 +08:00
|
|
|
|
2014-10-30 06:11:06 +08:00
|
|
|
//spitlog::set_format("%t");
|
|
|
|
auto console = spitlog::create<sinks::stdout_sink_st>("reporter");
|
2014-10-26 07:29:50 +08:00
|
|
|
//console->set_format("[%n %l] %t");
|
2014-10-30 06:11:06 +08:00
|
|
|
console->set_level(spitlog::level::INFO);
|
2014-10-26 07:29:50 +08:00
|
|
|
console->info("Starting bench with", howmany, "iterations..");
|
|
|
|
|
2014-10-30 06:11:06 +08:00
|
|
|
auto bench = spitlog::create<sinks::rotating_file_sink_st>("bench", "myrotating", "txt", 1024 * 1024 * 1, 10, 0);
|
2014-10-26 07:52:37 +08:00
|
|
|
|
2014-10-30 06:11:06 +08:00
|
|
|
//auto bench = spitlog::create<sinks::simple_file_sink_st>("bench", "simplelog.txt", 1);
|
|
|
|
//auto bench = spitlog::create<sinks::null_sink_st>("bench");
|
2014-10-26 07:29:50 +08:00
|
|
|
auto start = system_clock::now();
|
2014-10-26 07:52:37 +08:00
|
|
|
for (unsigned int i = 0; i < howmany; ++i)
|
2014-10-26 07:29:50 +08:00
|
|
|
{
|
2014-10-26 07:52:37 +08:00
|
|
|
bench->info("Hello logger: msg number") << i;
|
2014-10-26 07:29:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
auto delta = system_clock::now() - start;
|
|
|
|
auto delta_d = duration_cast<duration<double>> (delta).count();
|
|
|
|
|
|
|
|
console->info("Total:") << format(howmany);
|
|
|
|
console->info("Delta:") << format(delta_d);
|
|
|
|
console->info("Rate:") << format(howmany / delta_d) << "/sec";
|
|
|
|
|
|
|
|
}
|
|
|
|
catch (std::exception &ex)
|
2014-10-24 06:59:39 +08:00
|
|
|
{
|
2014-10-26 07:29:50 +08:00
|
|
|
std::cerr << "Exception: " << ex.what() << std::endl;
|
2014-10-30 06:11:06 +08:00
|
|
|
perror("Last error");
|
2014-10-24 06:59:39 +08:00
|
|
|
}
|
2014-10-11 06:15:26 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|