From 03d9abe8e269ed54e8f7210f16f938695ecb58f2 Mon Sep 17 00:00:00 2001 From: gabi Date: Wed, 5 Nov 2014 22:54:13 +0200 Subject: [PATCH 1/5] mingw support --- README.md | 1 + example/Makefile.mingw | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 example/Makefile.mingw diff --git a/README.md b/README.md index 56c9c814..3afaba94 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Just copy the files to your build tree and use a C++11 compiler * gcc 4.8.1 and above * clang 3.5 * visual studio 2013 +* mingw with g++ 4.9.x ##Features * Very fast - performance is the primary goal (see becnhmarks below) diff --git a/example/Makefile.mingw b/example/Makefile.mingw new file mode 100644 index 00000000..fc47241d --- /dev/null +++ b/example/Makefile.mingw @@ -0,0 +1,32 @@ +CXX = g++ +CXXFLAGS = -D_WIN32_WINNT=0x600 -march=native -Wall -Wextra -Wshadow -pedantic -std=c++11 -pthread -Wl,--no-as-needed -I../include +CXX_RELEASE_FLAGS = -O3 +CXX_DEBUG_FLAGS= -g + + +all: example bench +debug: example-debug bench-debug + +example: example.cpp + $(CXX) example.cpp -o example $(CXXFLAGS) $(CXX_RELEASE_FLAGS) + +bench: bench.cpp + $(CXX) bench.cpp -o bench $(CXXFLAGS) $(CXX_RELEASE_FLAGS) + + +example-debug: example.cpp + $(CXX) example.cpp -o example-debug $(CXXFLAGS) $(CXX_DEBUG_FLAGS) + +bench-debug: bench.cpp + $(CXX) bench.cpp -o bench-debug $(CXXFLAGS) $(CXX_DEBUG_FLAGS) + + + +clean: + rm -f *.o logs/*.txt example example-debug bench bench-debug + + +rebuild: clean all +rebuild-debug: clean debug + + From 58688d7d1c1fc2a7de856b50ca31d107fa2b8ca8 Mon Sep 17 00:00:00 2001 From: gabi Date: Wed, 5 Nov 2014 23:07:20 +0200 Subject: [PATCH 2/5] Removed close() from sink to have RAII semantics --- example/bench.cpp | 2 -- example/example.cpp | 2 +- include/spdlog/details/logger_impl.h | 4 +--- include/spdlog/details/registry.h | 4 ++-- include/spdlog/details/spdlog_impl.h | 4 ++-- include/spdlog/logger.h | 3 ++- include/spdlog/sinks/async_sink.h | 8 -------- include/spdlog/sinks/file_sinks.h | 13 +------------ include/spdlog/sinks/null_sink.h | 5 +---- include/spdlog/sinks/ostream_sink.h | 4 ---- include/spdlog/sinks/sink.h | 1 - include/spdlog/spdlog.h | 4 ++-- 12 files changed, 12 insertions(+), 42 deletions(-) diff --git a/example/bench.cpp b/example/bench.cpp index c91cb4d3..d4d290f7 100644 --- a/example/bench.cpp +++ b/example/bench.cpp @@ -112,7 +112,6 @@ void bench(int howmany, std::shared_ptr log) auto delta = system_clock::now() - start; auto delta_d = duration_cast> (delta).count(); cout << format(int(howmany / delta_d)) << "/sec" << endl; - log->close(); } @@ -146,6 +145,5 @@ void bench_mt(int howmany, std::shared_ptr log, int thread_count auto delta = system_clock::now() - start; auto delta_d = duration_cast> (delta).count(); cout << format(int(howmany / delta_d)) << "/sec" << endl; - log->close(); } diff --git a/example/example.cpp b/example/example.cpp index 12dfe81c..3e273b8f 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -29,7 +29,7 @@ #include "spdlog/spdlog.h" -int main(int, char* []) +int maina(int, char* []) { namespace spd = spdlog; diff --git a/include/spdlog/details/logger_impl.h b/include/spdlog/details/logger_impl.h index 3aed971b..81c47c57 100644 --- a/include/spdlog/details/logger_impl.h +++ b/include/spdlog/details/logger_impl.h @@ -137,11 +137,9 @@ inline bool spdlog::logger::should_log(spdlog::level::level_enum msg_level) cons return msg_level >= _level.load(); } -inline void spdlog::logger::close() +inline void spdlog::logger::stop() { set_level(level::OFF); - for (auto &sink : _sinks) - sink->close(); } diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index e84adad0..9159dec8 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -104,12 +104,12 @@ public: } - void close_all() + void stop_all() { std::lock_guard lock(_mutex); _level = level::OFF; for (auto& l : _loggers) - l.second->close(); + l.second->stop(); } diff --git a/include/spdlog/details/spdlog_impl.h b/include/spdlog/details/spdlog_impl.h index a9b48165..13c9df06 100644 --- a/include/spdlog/details/spdlog_impl.h +++ b/include/spdlog/details/spdlog_impl.h @@ -116,7 +116,7 @@ inline void spdlog::set_level(level::level_enum log_level) return details::registry::instance().set_level(log_level); } -inline void spdlog::close() +inline void spdlog::stop() { - return details::registry::instance().close_all(); + return details::registry::instance().stop_all(); } diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 6c3b9e04..48cb1ddb 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -67,7 +67,8 @@ public: const std::string& name() const; bool should_log(level::level_enum) const; - void close(); + //Stop logging + void stop(); template details::line_logger log(level::level_enum lvl, const Args&... args); template details::line_logger log(const Args&... args); diff --git a/include/spdlog/sinks/async_sink.h b/include/spdlog/sinks/async_sink.h index 2f61ec78..373475d4 100644 --- a/include/spdlog/sinks/async_sink.h +++ b/include/spdlog/sinks/async_sink.h @@ -57,8 +57,6 @@ public: //Wait to remaining items (if any) in the queue to be written and shutdown void shutdown(const std::chrono::milliseconds& timeout); - void close() override; - protected: @@ -150,10 +148,6 @@ inline void spdlog::sinks::async_sink::shutdown(const std::chrono::milliseconds& _shutdown(); } -inline void spdlog::sinks::async_sink::close() -{ - _shutdown(); -} inline void spdlog::sinks::async_sink::_shutdown() @@ -166,7 +160,5 @@ inline void spdlog::sinks::async_sink::_shutdown() _back_thread.join(); } - for (auto &s : _sinks) - s->close(); } diff --git a/include/spdlog/sinks/file_sinks.h b/include/spdlog/sinks/file_sinks.h index 377ce150..ee773e59 100644 --- a/include/spdlog/sinks/file_sinks.h +++ b/include/spdlog/sinks/file_sinks.h @@ -50,10 +50,7 @@ public: { _file_helper.open(filename); } - void close() override - { - _file_helper.close(); - } + protected: void _sink_it(const details::log_msg& msg) override { @@ -86,10 +83,6 @@ public: _file_helper.open(calc_filename(_base_filename, 0, _extension)); } - void close() override - { - _file_helper.close(); - } protected: void _sink_it(const details::log_msg& msg) override @@ -171,10 +164,6 @@ public: _file_helper.open(calc_filename(_base_filename, _extension)); } - void close() override - { - _file_helper.close(); - } protected: void _sink_it(const details::log_msg& msg) override diff --git a/include/spdlog/sinks/null_sink.h b/include/spdlog/sinks/null_sink.h index dcdcd141..2cd416a9 100644 --- a/include/spdlog/sinks/null_sink.h +++ b/include/spdlog/sinks/null_sink.h @@ -34,16 +34,13 @@ namespace sinks { template -class null_sink : public base_sink +class null_sink : public base_sink < Mutex > { protected: void _sink_it(const details::log_msg&) override {} - void close() override - {} }; - typedef null_sink null_sink_st; typedef null_sink null_sink_mt; diff --git a/include/spdlog/sinks/ostream_sink.h b/include/spdlog/sinks/ostream_sink.h index 00702c34..5f33743b 100644 --- a/include/spdlog/sinks/ostream_sink.h +++ b/include/spdlog/sinks/ostream_sink.h @@ -44,10 +44,6 @@ public: ostream_sink& operator=(const ostream_sink&) = delete; virtual ~ostream_sink() = default; - - void close() override - {} - protected: virtual void _sink_it(const details::log_msg& msg) override { diff --git a/include/spdlog/sinks/sink.h b/include/spdlog/sinks/sink.h index 50297783..0905d52f 100644 --- a/include/spdlog/sinks/sink.h +++ b/include/spdlog/sinks/sink.h @@ -35,7 +35,6 @@ class sink public: virtual ~sink() {} virtual void log(const details::log_msg& msg) = 0; - virtual void close() = 0; }; } } diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index fc432b10..7cc08bfb 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -88,8 +88,8 @@ std::shared_ptr create(const std::string& logger_name, const Arg // Set global formatter object void set_formatter(formatter_ptr f); -// Close all loggers and stop logging -void close(); +// Stop logging by setting all the loggers to log level OFF +void stop(); // From ca42657d3cb98cfdcb3e70df5269cfbf9ab2ea5d Mon Sep 17 00:00:00 2001 From: gabi Date: Wed, 5 Nov 2014 23:15:18 +0200 Subject: [PATCH 3/5] small improvment in async shutdown --- include/spdlog/sinks/async_sink.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/spdlog/sinks/async_sink.h b/include/spdlog/sinks/async_sink.h index 373475d4..21620633 100644 --- a/include/spdlog/sinks/async_sink.h +++ b/include/spdlog/sinks/async_sink.h @@ -142,7 +142,7 @@ inline void spdlog::sinks::async_sink::shutdown(const std::chrono::milliseconds& auto until = log_clock::now() + timeout; while (_q.size() > 0 && log_clock::now() < until) { - std::this_thread::sleep_for(std::chrono::milliseconds(2)); + std::this_thread::sleep_for(std::chrono::milliseconds(5)); } } _shutdown(); From a66d80c1d4afd5fe3b5d57e9e64bcffa93ecbb0b Mon Sep 17 00:00:00 2001 From: gabi Date: Wed, 5 Nov 2014 23:15:34 +0200 Subject: [PATCH 4/5] bench --- example/bench.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/bench.cpp b/example/bench.cpp index d4d290f7..1c406068 100644 --- a/example/bench.cpp +++ b/example/bench.cpp @@ -105,7 +105,7 @@ void bench(int howmany, std::shared_ptr log) auto start = system_clock::now(); for (auto i = 0; i < howmany; ++i) { - log->info("Hello logger: msg number ") << i << "**************************" << i + 1 << "," << 1 + 2;; + log->info("Hello logger: msg number ", i); } From 35c71f4d7b70f45621cf48f70a6bb10b3648ac5c Mon Sep 17 00:00:00 2001 From: gabi Date: Wed, 5 Nov 2014 23:16:24 +0200 Subject: [PATCH 5/5] bench --- {bench-comparison => bench}/Makefile | 0 {bench-comparison => bench}/boost-bench-mt.cpp | 0 {bench-comparison => bench}/boost-bench.cpp | 0 {bench-comparison => bench}/logs/.gitignore | 0 {bench-comparison => bench}/run_all.sh | 0 {bench-comparison => bench}/spdlog-bench-mt.cpp | 0 {bench-comparison => bench}/spdlog-bench.cpp | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename {bench-comparison => bench}/Makefile (100%) rename {bench-comparison => bench}/boost-bench-mt.cpp (100%) rename {bench-comparison => bench}/boost-bench.cpp (100%) rename {bench-comparison => bench}/logs/.gitignore (100%) rename {bench-comparison => bench}/run_all.sh (100%) rename {bench-comparison => bench}/spdlog-bench-mt.cpp (100%) rename {bench-comparison => bench}/spdlog-bench.cpp (100%) diff --git a/bench-comparison/Makefile b/bench/Makefile similarity index 100% rename from bench-comparison/Makefile rename to bench/Makefile diff --git a/bench-comparison/boost-bench-mt.cpp b/bench/boost-bench-mt.cpp similarity index 100% rename from bench-comparison/boost-bench-mt.cpp rename to bench/boost-bench-mt.cpp diff --git a/bench-comparison/boost-bench.cpp b/bench/boost-bench.cpp similarity index 100% rename from bench-comparison/boost-bench.cpp rename to bench/boost-bench.cpp diff --git a/bench-comparison/logs/.gitignore b/bench/logs/.gitignore similarity index 100% rename from bench-comparison/logs/.gitignore rename to bench/logs/.gitignore diff --git a/bench-comparison/run_all.sh b/bench/run_all.sh similarity index 100% rename from bench-comparison/run_all.sh rename to bench/run_all.sh diff --git a/bench-comparison/spdlog-bench-mt.cpp b/bench/spdlog-bench-mt.cpp similarity index 100% rename from bench-comparison/spdlog-bench-mt.cpp rename to bench/spdlog-bench-mt.cpp diff --git a/bench-comparison/spdlog-bench.cpp b/bench/spdlog-bench.cpp similarity index 100% rename from bench-comparison/spdlog-bench.cpp rename to bench/spdlog-bench.cpp