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(); //