Fix code to support VS2013
This commit is contained in:
parent
8b27eb0f01
commit
57fe78f1c6
@ -48,7 +48,7 @@ void testlog(int threads)
|
|||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
if(argc || argv){};
|
if(argc || argv) {};
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
using namespace c11log;
|
using namespace c11log;
|
||||||
using namespace utils;
|
using namespace utils;
|
||||||
@ -60,14 +60,14 @@ int main(int argc, char* argv[])
|
|||||||
auto null_sink = std::make_shared<sinks::null_sink>();
|
auto null_sink = std::make_shared<sinks::null_sink>();
|
||||||
//auto async = std::make_shared<sinks::async_sink>(1000);
|
//auto async = std::make_shared<sinks::async_sink>(1000);
|
||||||
//async->add_sink(fsink);
|
//async->add_sink(fsink);
|
||||||
my_logger.add_sink(null_sink);
|
my_logger.add_sink(null_sink);
|
||||||
auto start = system_clock::now();
|
auto start = system_clock::now();
|
||||||
|
|
||||||
const unsigned int howmany = 10000000;
|
const unsigned int howmany = 10000000;
|
||||||
for(unsigned int i = 0; i < howmany ; i++)
|
for(unsigned int i = 0; i < howmany ; i++)
|
||||||
my_logger.info() << "Hello logger " << i;
|
my_logger.info() << "Hello logger " << i;
|
||||||
|
|
||||||
//async->shutdown(seconds(3));
|
//async->shutdown(seconds(3));
|
||||||
auto delta = system_clock::now() - start;
|
auto delta = system_clock::now() - start;
|
||||||
auto delta_d = duration_cast<duration<double>> (delta);
|
auto delta_d = duration_cast<duration<double>> (delta);
|
||||||
cout << "Total " << format(howmany) << endl;
|
cout << "Total " << format(howmany) << endl;
|
||||||
@ -77,7 +77,7 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if(argc !=3) {
|
if(argc !=3) {
|
||||||
std::cerr << "Usage: " << argv[0] << " qsize, threads" << std::endl;
|
std::cerr << "Usage: " << argv[0] << " qsize, threads" << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -58,8 +58,7 @@ public:
|
|||||||
// If the queue is full, block the calling thread until there is room.
|
// If the queue is full, block the calling thread until there is room.
|
||||||
template<typename TT>
|
template<typename TT>
|
||||||
void push(TT&& item) {
|
void push(TT&& item) {
|
||||||
constexpr std::chrono::hours one_hour(1);
|
while (!push(std::forward<TT>(item), std::chrono::hours(1)));
|
||||||
while (!push(std::forward<TT>(item), one_hour));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pop a copy of the front item in the queue into the given item ref.
|
// Pop a copy of the front item in the queue into the given item ref.
|
||||||
@ -86,8 +85,7 @@ public:
|
|||||||
// Pop a copy of the front item in the queue into the given item ref.
|
// Pop a copy of the front item in the queue into the given item ref.
|
||||||
// If the queue is empty, block the calling thread util there is item to pop.
|
// If the queue is empty, block the calling thread util there is item to pop.
|
||||||
void pop(T& item) {
|
void pop(T& item) {
|
||||||
constexpr std::chrono::hours one_hour(1);
|
while (!pop(item, std::chrono::hours(1)));
|
||||||
while (!pop(item, one_hour));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear the queue
|
// Clear the queue
|
||||||
|
@ -15,9 +15,10 @@ public:
|
|||||||
_str = other._str;
|
_str = other._str;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& str_ref() const {
|
const std::string& str_ref() const {
|
||||||
return _str;
|
return _str;
|
||||||
|
std::ostringstream oss;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear() {
|
void clear() {
|
||||||
@ -47,13 +48,15 @@ class fast_oss:public std::ostream {
|
|||||||
public:
|
public:
|
||||||
fast_oss():std::ostream(&_dev) {}
|
fast_oss():std::ostream(&_dev) {}
|
||||||
~fast_oss() = default;
|
~fast_oss() = default;
|
||||||
fast_oss(const fast_oss& other):std::basic_ios<char>(), std::ostream(),_dev(other._dev) {}
|
|
||||||
|
fast_oss(const fast_oss& other) :std::ostream(&_dev), _dev(other._dev) {
|
||||||
|
}
|
||||||
fast_oss& operator=(const fast_oss& other) {
|
fast_oss& operator=(const fast_oss& other) {
|
||||||
if(&other != this)
|
if(&other != this)
|
||||||
_dev = other._dev;
|
_dev = other._dev;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& str_ref() const {
|
const std::string& str_ref() const {
|
||||||
return _dev.str_ref();
|
return _dev.str_ref();
|
||||||
}
|
}
|
||||||
|
@ -35,17 +35,16 @@ inline std::tm c11log::details::os::localtime()
|
|||||||
|
|
||||||
inline bool operator==(const std::tm& tm1, const std::tm& tm2)
|
inline bool operator==(const std::tm& tm1, const std::tm& tm2)
|
||||||
{
|
{
|
||||||
return (tm1.tm_sec == tm2.tm_sec &&
|
return (tm1.tm_sec == tm2.tm_sec &&
|
||||||
tm1.tm_min == tm2.tm_min &&
|
tm1.tm_min == tm2.tm_min &&
|
||||||
tm1.tm_hour == tm2.tm_hour &&
|
tm1.tm_hour == tm2.tm_hour &&
|
||||||
tm1.tm_mday == tm2.tm_mday &&
|
tm1.tm_mday == tm2.tm_mday &&
|
||||||
tm1.tm_mon == tm2.tm_mon &&
|
tm1.tm_mon == tm2.tm_mon &&
|
||||||
tm1.tm_year == tm2.tm_year &&
|
tm1.tm_year == tm2.tm_year &&
|
||||||
tm1.tm_isdst == tm2.tm_isdst &&
|
tm1.tm_isdst == tm2.tm_isdst);
|
||||||
tm1.tm_gmtoff == tm2.tm_gmtoff);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator!=(const std::tm& tm1, const std::tm& tm2)
|
inline bool operator!=(const std::tm& tm1, const std::tm& tm2)
|
||||||
{
|
{
|
||||||
return !(tm1==tm2);
|
return !(tm1==tm2);
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#include "common_types.h"
|
#include "common_types.h"
|
||||||
#include "details/os.h"
|
#include "details/os.h"
|
||||||
@ -43,20 +44,21 @@ private:
|
|||||||
|
|
||||||
inline void c11log::formatters::default_formatter::_format_time(const log_clock::time_point& tp, std::ostream &dest)
|
inline void c11log::formatters::default_formatter::_format_time(const log_clock::time_point& tp, std::ostream &dest)
|
||||||
{
|
{
|
||||||
static thread_local std::tm last_tm = {0,0,0,0,0,0,0,0,0,0,0};
|
|
||||||
static thread_local char last_time_str[64];
|
__declspec(thread) static std::tm last_tm = { 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
|
__declspec(thread) static char last_time_str[64];
|
||||||
auto tm_now = details::os::localtime(log_clock::to_time_t(tp));
|
auto tm_now = details::os::localtime(log_clock::to_time_t(tp));
|
||||||
|
|
||||||
if(last_tm != tm_now)
|
if(last_tm != tm_now)
|
||||||
{
|
{
|
||||||
sprintf(last_time_str, "[%d-%02d-%02d %02d:%02d:%02d]",
|
sprintf(last_time_str, "[%d-%02d-%02d %02d:%02d:%02d]",
|
||||||
tm_now.tm_year + 1900,
|
tm_now.tm_year + 1900,
|
||||||
tm_now.tm_mon + 1,
|
tm_now.tm_mon + 1,
|
||||||
tm_now.tm_mday,
|
tm_now.tm_mday,
|
||||||
tm_now.tm_hour,
|
tm_now.tm_hour,
|
||||||
tm_now.tm_min,
|
tm_now.tm_min,
|
||||||
tm_now.tm_sec);
|
tm_now.tm_sec);
|
||||||
last_tm = tm_now;
|
last_tm = tm_now;
|
||||||
}
|
}
|
||||||
dest << last_time_str;
|
dest << last_time_str;
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,10 @@ public:
|
|||||||
_logger_name(name),
|
_logger_name(name),
|
||||||
_formatter(new formatters::default_formatter()),
|
_formatter(new formatters::default_formatter()),
|
||||||
_sinks(),
|
_sinks(),
|
||||||
_mutex(),
|
_mutex()
|
||||||
_atomic_level(level::INFO) {
|
{
|
||||||
|
//Seems that vs2013 doesnt support atomic member initialization in ctor, so its done here
|
||||||
|
_atomic_level = level::INFO;
|
||||||
}
|
}
|
||||||
|
|
||||||
~logger() = default;
|
~logger() = default;
|
||||||
|
@ -61,7 +61,7 @@ inline void c11log::sinks::async_sink::_sink_it(const std::string& msg)
|
|||||||
|
|
||||||
inline void c11log::sinks::async_sink::_thread_loop()
|
inline void c11log::sinks::async_sink::_thread_loop()
|
||||||
{
|
{
|
||||||
constexpr auto pop_timeout = std::chrono::seconds(1);
|
static std::chrono::seconds pop_timeout { 1 };
|
||||||
std::string msg;
|
std::string msg;
|
||||||
|
|
||||||
while (_active) {
|
while (_active) {
|
||||||
|
Loading…
Reference in New Issue
Block a user