diff --git a/example/example.cpp b/example/example.cpp index ac9ed75f..c8b17b58 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -48,7 +48,7 @@ void testlog(int threads) int main(int argc, char* argv[]) { - if(argc || argv){}; + if(argc || argv) {}; using namespace std::chrono; using namespace c11log; using namespace utils; @@ -60,14 +60,14 @@ int main(int argc, char* argv[]) auto null_sink = std::make_shared(); //auto async = std::make_shared(1000); //async->add_sink(fsink); - my_logger.add_sink(null_sink); + my_logger.add_sink(fsink); auto start = system_clock::now(); const unsigned int howmany = 10000000; for(unsigned int i = 0; i < howmany ; i++) my_logger.info() << "Hello logger " << i; - - //async->shutdown(seconds(3)); + + //async->shutdown(seconds(3)); auto delta = system_clock::now() - start; auto delta_d = duration_cast> (delta); cout << "Total " << format(howmany) << endl; @@ -77,7 +77,7 @@ int main(int argc, char* argv[]) return 0; - /* + /* if(argc !=3) { std::cerr << "Usage: " << argv[0] << " qsize, threads" << std::endl; return 0; diff --git a/include/c11log/details/blocking_queue.h b/include/c11log/details/blocking_queue.h index 99a08467..13576582 100644 --- a/include/c11log/details/blocking_queue.h +++ b/include/c11log/details/blocking_queue.h @@ -58,8 +58,7 @@ public: // If the queue is full, block the calling thread until there is room. template void push(TT&& item) { - constexpr std::chrono::hours one_hour(1); - while (!push(std::forward(item), one_hour)); + while (!push(std::forward(item), std::chrono::hours(1))); } // 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. // If the queue is empty, block the calling thread util there is item to pop. void pop(T& item) { - constexpr std::chrono::hours one_hour(1); - while (!pop(item, one_hour)); + while (!pop(item, std::chrono::hours(1))); } // Clear the queue diff --git a/include/c11log/details/fast_oss.h b/include/c11log/details/fast_oss.h index 8ca13cf3..26402002 100644 --- a/include/c11log/details/fast_oss.h +++ b/include/c11log/details/fast_oss.h @@ -15,9 +15,10 @@ public: _str = other._str; return *this; } - + const std::string& str_ref() const { return _str; + std::ostringstream oss; } void clear() { @@ -47,13 +48,15 @@ class fast_oss:public std::ostream { public: fast_oss():std::ostream(&_dev) {} ~fast_oss() = default; - fast_oss(const fast_oss& other):std::basic_ios(), std::ostream(),_dev(other._dev) {} + + fast_oss(const fast_oss& other) :std::basic_ios(), std::ostream(&_dev), _dev(other._dev) {} + fast_oss& operator=(const fast_oss& other) { if(&other != this) _dev = other._dev; return *this; } - + const std::string& str_ref() const { return _dev.str_ref(); } diff --git a/include/c11log/details/os.h b/include/c11log/details/os.h index 6d560c82..dcc1f532 100644 --- a/include/c11log/details/os.h +++ b/include/c11log/details/os.h @@ -26,6 +26,8 @@ inline std::tm localtime() } + + inline bool operator==(const std::tm& tm1, const std::tm& tm2) { return (tm1.tm_sec == tm2.tm_sec && @@ -45,3 +47,6 @@ inline bool operator!=(const std::tm& tm1, const std::tm& tm2) } } } + + + diff --git a/include/c11log/logger.h b/include/c11log/logger.h index 293b7fd8..c13fea32 100644 --- a/include/c11log/logger.h +++ b/include/c11log/logger.h @@ -30,8 +30,10 @@ public: _logger_name(name), _formatter(new formatters::default_formatter()), _sinks(), - _mutex(), - _atomic_level(level::INFO) { + _mutex() + { + //Seems that vs2013 doesnt support atomic member initialization in ctor, so its done here + _atomic_level = level::INFO; } ~logger() = default; diff --git a/include/c11log/sinks/async_sink.h b/include/c11log/sinks/async_sink.h index 2aa7d37a..c5fa4b18 100644 --- a/include/c11log/sinks/async_sink.h +++ b/include/c11log/sinks/async_sink.h @@ -61,7 +61,7 @@ inline void c11log::sinks::async_sink::_sink_it(const std::string& msg) 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; while (_active) { diff --git a/include/c11log/sinks/stdout_sinks.h b/include/c11log/sinks/stdout_sinks.h index cffd397f..a0639c83 100644 --- a/include/c11log/sinks/stdout_sinks.h +++ b/include/c11log/sinks/stdout_sinks.h @@ -25,15 +25,6 @@ protected: std::mutex _mutex; }; -inline std::shared_ptr cout_sink() { - static const ostream_sink& instance{std::cout}; - return std::shared_ptr(&instance, [=](ostream_sink*) {}); -} - -inline std::shared_ptr cerr_sink() { - static const ostream_sink& instance = ostream_sink(std::cerr); - return std::shared_ptr(&instance, [=](ostream_sink*) {}); -} }