From fb6df0512fc995d07f757a220af2dae927edffe8 Mon Sep 17 00:00:00 2001 From: Daniel Chabrowski Date: Sat, 24 Feb 2018 23:56:56 +0100 Subject: [PATCH] modernize-use-override --- include/spdlog/async_logger.h | 6 +++--- include/spdlog/common.h | 4 ++-- include/spdlog/formatter.h | 5 ++--- include/spdlog/sinks/ansicolor_sink.h | 8 +++++--- include/spdlog/sinks/base_sink.h | 4 ++-- include/spdlog/sinks/dist_sink.h | 5 +---- include/spdlog/sinks/file_sinks.h | 6 ++++-- include/spdlog/sinks/msvc_sink.h | 4 +--- include/spdlog/sinks/null_sink.h | 2 +- include/spdlog/sinks/ostream_sink.h | 3 +-- include/spdlog/sinks/sink.h | 5 +---- include/spdlog/sinks/stdout_sinks.h | 5 +++-- include/spdlog/sinks/syslog_sink.h | 3 ++- include/spdlog/sinks/wincolor_sink.h | 18 +++++++++--------- include/spdlog/sinks/windebug_sink.h | 2 +- 15 files changed, 38 insertions(+), 42 deletions(-) diff --git a/include/spdlog/async_logger.h b/include/spdlog/async_logger.h index e9fcd5f4..4b1190cc 100644 --- a/include/spdlog/async_logger.h +++ b/include/spdlog/async_logger.h @@ -31,7 +31,7 @@ namespace details class async_log_helper; } -class async_logger SPDLOG_FINAL :public logger +class async_logger SPDLOG_FINAL : public logger { public: template @@ -65,8 +65,8 @@ public: void flush() override; // Error handler - virtual void set_error_handler(log_err_handler) override; - virtual log_err_handler error_handler() override; + void set_error_handler(log_err_handler) override; + log_err_handler error_handler() override; protected: void _sink_it(details::log_msg& msg) override; diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 97e58247..c5ecc73a 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -136,7 +136,7 @@ namespace os std::string errno_str(int err_num); } } -class spdlog_ex: public std::exception +class spdlog_ex : public std::exception { public: spdlog_ex(const std::string& msg):_msg(msg) @@ -149,9 +149,9 @@ public: { return _msg.c_str(); } + private: std::string _msg; - }; // diff --git a/include/spdlog/formatter.h b/include/spdlog/formatter.h index b69d7eb1..580deac2 100644 --- a/include/spdlog/formatter.h +++ b/include/spdlog/formatter.h @@ -21,18 +21,18 @@ class flag_formatter; class formatter { public: - virtual ~formatter() {} + virtual ~formatter() = default; virtual void format(details::log_msg& msg) = 0; }; class pattern_formatter SPDLOG_FINAL : public formatter { - public: explicit pattern_formatter(const std::string& pattern, pattern_time_type pattern_time = pattern_time_type::local, const std::string& eol = spdlog::details::os::default_eol); pattern_formatter(const pattern_formatter&) = delete; pattern_formatter& operator=(const pattern_formatter&) = delete; void format(details::log_msg& msg) override; + private: const std::string _eol; const std::string _pattern; @@ -45,4 +45,3 @@ private: } #include "details/pattern_formatter_impl.h" - diff --git a/include/spdlog/sinks/ansicolor_sink.h b/include/spdlog/sinks/ansicolor_sink.h index 2063b079..1b70c735 100644 --- a/include/spdlog/sinks/ansicolor_sink.h +++ b/include/spdlog/sinks/ansicolor_sink.h @@ -23,7 +23,7 @@ namespace sinks * If no color terminal detected, omit the escape codes. */ template -class ansicolor_sink: public base_sink +class ansicolor_sink : public base_sink { public: ansicolor_sink(FILE* file): target_file_(file) @@ -37,7 +37,8 @@ public: colors_[level::critical] = bold + on_red; colors_[level::off] = reset; } - virtual ~ansicolor_sink() + + ~ansicolor_sink() override { _flush(); } @@ -79,7 +80,7 @@ public: const std::string on_white = "\033[47m"; protected: - virtual void _sink_it(const details::log_msg& msg) override + void _sink_it(const details::log_msg& msg) override { // Wrap the originally formatted message in color codes. // If color is not supported in the terminal, log as is instead. @@ -102,6 +103,7 @@ protected: { fflush(target_file_); } + FILE* target_file_; bool should_do_colors_; std::unordered_map colors_; diff --git a/include/spdlog/sinks/base_sink.h b/include/spdlog/sinks/base_sink.h index 23c85653..63d67445 100644 --- a/include/spdlog/sinks/base_sink.h +++ b/include/spdlog/sinks/base_sink.h @@ -22,11 +22,10 @@ namespace spdlog namespace sinks { template -class base_sink:public sink +class base_sink : public sink { public: base_sink():_mutex() {} - virtual ~base_sink() = default; base_sink(const base_sink&) = delete; base_sink& operator=(const base_sink&) = delete; @@ -36,6 +35,7 @@ public: std::lock_guard lock(_mutex); _sink_it(msg); } + void flush() SPDLOG_FINAL override { std::lock_guard lock(_mutex); diff --git a/include/spdlog/sinks/dist_sink.h b/include/spdlog/sinks/dist_sink.h index 604c5a7d..39f162c5 100644 --- a/include/spdlog/sinks/dist_sink.h +++ b/include/spdlog/sinks/dist_sink.h @@ -22,13 +22,12 @@ namespace spdlog namespace sinks { template -class dist_sink: public base_sink +class dist_sink : public base_sink { public: explicit dist_sink() :_sinks() {} dist_sink(const dist_sink&) = delete; dist_sink& operator=(const dist_sink&) = delete; - virtual ~dist_sink() = default; protected: std::vector> _sinks; @@ -51,8 +50,6 @@ protected: } public: - - void add_sink(std::shared_ptr sink) { std::lock_guard lock(base_sink::_mutex); diff --git a/include/spdlog/sinks/file_sinks.h b/include/spdlog/sinks/file_sinks.h index baef4a46..f4abd81b 100644 --- a/include/spdlog/sinks/file_sinks.h +++ b/include/spdlog/sinks/file_sinks.h @@ -26,7 +26,7 @@ namespace sinks * Trivial file sink with single file as target */ template -class simple_file_sink SPDLOG_FINAL : public base_sink < Mutex > +class simple_file_sink SPDLOG_FINAL : public base_sink { public: explicit simple_file_sink(const filename_t &filename, bool truncate = false):_force_flush(false) @@ -46,10 +46,12 @@ protected: if(_force_flush) _file_helper.flush(); } + void _flush() override { _file_helper.flush(); } + private: details::file_helper _file_helper; bool _force_flush; @@ -112,7 +114,6 @@ protected: _file_helper.flush(); } - private: // Rotate files: // log.txt -> log.1.txt @@ -142,6 +143,7 @@ private: } _file_helper.reopen(true); } + filename_t _base_filename; std::size_t _max_size; std::size_t _max_files; diff --git a/include/spdlog/sinks/msvc_sink.h b/include/spdlog/sinks/msvc_sink.h index 879ae81f..d230613e 100644 --- a/include/spdlog/sinks/msvc_sink.h +++ b/include/spdlog/sinks/msvc_sink.h @@ -23,15 +23,13 @@ namespace sinks * MSVC sink (logging using OutputDebugStringA) */ template -class msvc_sink : public base_sink < Mutex > +class msvc_sink : public base_sink { public: explicit msvc_sink() { } - - 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 deda0373..9a4fd08d 100644 --- a/include/spdlog/sinks/null_sink.h +++ b/include/spdlog/sinks/null_sink.h @@ -16,7 +16,7 @@ namespace sinks { template -class null_sink : public base_sink < Mutex > +class null_sink : public base_sink { protected: void _sink_it(const details::log_msg&) override diff --git a/include/spdlog/sinks/ostream_sink.h b/include/spdlog/sinks/ostream_sink.h index 8ab9caab..9648cc05 100644 --- a/include/spdlog/sinks/ostream_sink.h +++ b/include/spdlog/sinks/ostream_sink.h @@ -16,13 +16,12 @@ namespace spdlog namespace sinks { template -class ostream_sink: public base_sink +class ostream_sink : public base_sink { public: explicit ostream_sink(std::ostream& os, bool force_flush=false) :_ostream(os), _force_flush(force_flush) {} ostream_sink(const ostream_sink&) = delete; ostream_sink& operator=(const ostream_sink&) = delete; - virtual ~ostream_sink() = default; protected: void _sink_it(const details::log_msg& msg) override diff --git a/include/spdlog/sinks/sink.h b/include/spdlog/sinks/sink.h index af61b54c..8fb045c6 100644 --- a/include/spdlog/sinks/sink.h +++ b/include/spdlog/sinks/sink.h @@ -3,7 +3,6 @@ // Distributed under the MIT License (http://opensource.org/licenses/MIT) // - #pragma once #include "../details/log_msg.h" @@ -20,7 +19,7 @@ public: _level = level::trace; } - virtual ~sink() {} + virtual ~sink() = default; virtual void log(const details::log_msg& msg) = 0; virtual void flush() = 0; @@ -30,7 +29,6 @@ public: private: level_t _level; - }; inline bool sink::should_log(level::level_enum msg_level) const @@ -50,4 +48,3 @@ inline level::level_enum sink::level() const } } - diff --git a/include/spdlog/sinks/stdout_sinks.h b/include/spdlog/sinks/stdout_sinks.h index 6867ba4e..0bdb8cec 100644 --- a/include/spdlog/sinks/stdout_sinks.h +++ b/include/spdlog/sinks/stdout_sinks.h @@ -50,13 +50,14 @@ class stderr_sink SPDLOG_FINAL : public base_sink { using MyType = stderr_sink; public: - stderr_sink() - {} + explicit stderr_sink() {} + static std::shared_ptr instance() { static std::shared_ptr instance = std::make_shared(); return instance; } + protected: void _sink_it(const details::log_msg& msg) override { diff --git a/include/spdlog/sinks/syslog_sink.h b/include/spdlog/sinks/syslog_sink.h index c4a726a8..98fad055 100644 --- a/include/spdlog/sinks/syslog_sink.h +++ b/include/spdlog/sinks/syslog_sink.h @@ -44,7 +44,8 @@ public: //set ident to be program name if empty ::openlog(_ident.empty()? nullptr:_ident.c_str(), syslog_option, syslog_facility); } - ~syslog_sink() + + ~syslog_sink() override { ::closelog(); } diff --git a/include/spdlog/sinks/wincolor_sink.h b/include/spdlog/sinks/wincolor_sink.h index bd612407..0ceb172a 100644 --- a/include/spdlog/sinks/wincolor_sink.h +++ b/include/spdlog/sinks/wincolor_sink.h @@ -21,8 +21,8 @@ namespace sinks /* * Windows color console sink. Uses WriteConsoleA to write to the console with colors */ -template -class wincolor_sink: public base_sink +template +class wincolor_sink : public base_sink { public: const WORD BOLD = FOREGROUND_INTENSITY; @@ -42,7 +42,7 @@ public: colors_[level::off] = 0; } - virtual ~wincolor_sink() + ~wincolor_sink() override { this->flush(); } @@ -58,7 +58,7 @@ public: } protected: - virtual void _sink_it(const details::log_msg& msg) override + void _sink_it(const details::log_msg& msg) override { auto color = colors_[msg.level]; auto orig_attribs = set_console_attribs(color); @@ -66,7 +66,7 @@ protected: SetConsoleTextAttribute(out_handle_, orig_attribs); //reset to orig colors } - virtual void _flush() override + void _flush() override { // windows console always flushed? } @@ -92,8 +92,8 @@ private: // // windows color console to stdout // -template -class wincolor_stdout_sink: public wincolor_sink +template +class wincolor_stdout_sink : public wincolor_sink { public: wincolor_stdout_sink() : wincolor_sink(GetStdHandle(STD_OUTPUT_HANDLE)) @@ -106,8 +106,8 @@ using wincolor_stdout_sink_st = wincolor_stdout_sink; // // windows color console to stderr // -template -class wincolor_stderr_sink: public wincolor_sink +template +class wincolor_stderr_sink : public wincolor_sink { public: wincolor_stderr_sink() : wincolor_sink(GetStdHandle(STD_ERROR_HANDLE)) diff --git a/include/spdlog/sinks/windebug_sink.h b/include/spdlog/sinks/windebug_sink.h index 16e8e540..37d67245 100644 --- a/include/spdlog/sinks/windebug_sink.h +++ b/include/spdlog/sinks/windebug_sink.h @@ -17,7 +17,7 @@ namespace sinks /* * Windows debug sink (logging using OutputDebugStringA, synonym for msvc_sink) */ -template +template using windebug_sink = msvc_sink; using windebug_sink_mt = msvc_sink_mt;