mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-29 09:59:33 +08:00
1. Added test
2. Fixes
This commit is contained in:
8
test/stdafx.cpp
Normal file
8
test/stdafx.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
// stdafx.cpp : source file that includes just the standard includes
|
||||
// test.pch will be the pre-compiled header
|
||||
// stdafx.obj will contain the pre-compiled type information
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
// TODO: reference any additional headers you need in STDAFX.H
|
||||
// and not in this file
|
16
test/stdafx.h
Normal file
16
test/stdafx.h
Normal file
@@ -0,0 +1,16 @@
|
||||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently, but
|
||||
// are changed infrequently
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <thread>
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
|
||||
#include "utils.h"
|
||||
#include "../include/c11log/logger.h"
|
||||
#include "../include/c11log/sinks/async_sink.h"
|
||||
#include "../include/c11log/sinks/stdout_sinks.h"
|
||||
#include "../include/c11log/sinks/file_sinks.h"
|
24
test/test.cpp
Normal file
24
test/test.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
// test.cpp : Defines the entry point for the console application.
|
||||
//
|
||||
|
||||
#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);
|
||||
logger.add_sink(async);
|
||||
logger.info() << "Hello logger!";
|
||||
utils::run(std::chrono::seconds(10), fn);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void fn()
|
||||
{}
|
||||
|
47
test/utils.h
Normal file
47
test/utils.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <locale>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
std::string format(const T& value)
|
||||
{
|
||||
static std::locale loc("");
|
||||
std::stringstream ss;
|
||||
ss.imbue(loc);
|
||||
ss << value;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
inline void run(const std::chrono::milliseconds &duration, const std::function<void() >& fn)
|
||||
{
|
||||
using namespace std::chrono;
|
||||
typedef steady_clock the_clock;
|
||||
size_t counter = 0;
|
||||
seconds print_interval(1);
|
||||
auto start_time = the_clock::now();
|
||||
auto lastPrintTime = start_time;
|
||||
while (true)
|
||||
{
|
||||
fn();
|
||||
++counter;
|
||||
auto now = the_clock::now();
|
||||
if (now - start_time >= duration)
|
||||
break;
|
||||
auto p = now - lastPrintTime;
|
||||
if (now - lastPrintTime >= print_interval)
|
||||
{
|
||||
std::cout << format(counter) << " per sec" << std::endl;
|
||||
counter = 0;
|
||||
lastPrintTime = the_clock::now();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user