mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-28 17:19:34 +08:00
async_sink
This commit is contained in:
@@ -4,21 +4,32 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
|
||||
void fn();
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
c11log::logger logger("test");
|
||||
|
||||
auto sink = std::make_shared<c11log::sinks::stdout_sink>();
|
||||
auto async = std::make_shared<c11log::sinks::async_sink>(100);
|
||||
async->add_sink(sink);
|
||||
auto screen_sink = std::make_shared<c11log::sinks::stdout_sink>();
|
||||
auto file_sink = std::make_shared<c11log::sinks::midnight_file_sink>("logtest");
|
||||
auto async = std::make_shared<c11log::sinks::async_sink>(1000);
|
||||
async->add_sink(file_sink);
|
||||
logger.add_sink(async);
|
||||
logger.info() << "Hello logger!";
|
||||
utils::run(std::chrono::seconds(10), fn);
|
||||
//logger.add_sink(file_sink);
|
||||
|
||||
|
||||
auto fn = [&logger]()
|
||||
{
|
||||
logger.info() << "Hello logger!";
|
||||
};
|
||||
utils::bench("test log", std::chrono::seconds(3), fn);
|
||||
logger.info() << "bye";
|
||||
utils::bench("shutdown", [&async]() {
|
||||
async->shutdown(std::chrono::seconds(10));
|
||||
});
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void fn()
|
||||
{}
|
||||
|
||||
|
15
test/utils.h
15
test/utils.h
@@ -20,7 +20,7 @@ std::string format(const T& value)
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
inline void run(const std::chrono::milliseconds &duration, const std::function<void() >& fn)
|
||||
inline void bench(const std::string& fn_name, const std::chrono::milliseconds &duration, const std::function<void() >& fn)
|
||||
{
|
||||
using namespace std::chrono;
|
||||
typedef steady_clock the_clock;
|
||||
@@ -38,10 +38,21 @@ inline void run(const std::chrono::milliseconds &duration, const std::function<v
|
||||
auto p = now - lastPrintTime;
|
||||
if (now - lastPrintTime >= print_interval)
|
||||
{
|
||||
std::cout << format(counter) << " per sec" << std::endl;
|
||||
std::cout << fn_name << ": " << format(counter) << " per sec" << std::endl;
|
||||
counter = 0;
|
||||
lastPrintTime = the_clock::now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void bench(const std::string& fn_name, const std::function<void() >& fn)
|
||||
{
|
||||
|
||||
using namespace std::chrono;
|
||||
auto start = steady_clock::now();
|
||||
fn();
|
||||
auto delta = steady_clock::now() - start;
|
||||
|
||||
std::cout << fn_name << ": " << duration_cast<milliseconds>(delta).count() << " ms" << std::endl;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user