Commit fb6df051 authored by Daniel Chabrowski's avatar Daniel Chabrowski

modernize-use-override

parent 7f4c1bb7
...@@ -31,7 +31,7 @@ namespace details ...@@ -31,7 +31,7 @@ namespace details
class async_log_helper; class async_log_helper;
} }
class async_logger SPDLOG_FINAL :public logger class async_logger SPDLOG_FINAL : public logger
{ {
public: public:
template<class It> template<class It>
...@@ -65,8 +65,8 @@ public: ...@@ -65,8 +65,8 @@ public:
void flush() override; void flush() override;
// Error handler // Error handler
virtual void set_error_handler(log_err_handler) override; void set_error_handler(log_err_handler) override;
virtual log_err_handler error_handler() override; log_err_handler error_handler() override;
protected: protected:
void _sink_it(details::log_msg& msg) override; void _sink_it(details::log_msg& msg) override;
......
...@@ -136,7 +136,7 @@ namespace os ...@@ -136,7 +136,7 @@ namespace os
std::string errno_str(int err_num); std::string errno_str(int err_num);
} }
} }
class spdlog_ex: public std::exception class spdlog_ex : public std::exception
{ {
public: public:
spdlog_ex(const std::string& msg):_msg(msg) spdlog_ex(const std::string& msg):_msg(msg)
...@@ -149,9 +149,9 @@ public: ...@@ -149,9 +149,9 @@ public:
{ {
return _msg.c_str(); return _msg.c_str();
} }
private: private:
std::string _msg; std::string _msg;
}; };
// //
......
...@@ -21,18 +21,18 @@ class flag_formatter; ...@@ -21,18 +21,18 @@ class flag_formatter;
class formatter class formatter
{ {
public: public:
virtual ~formatter() {} virtual ~formatter() = default;
virtual void format(details::log_msg& msg) = 0; virtual void format(details::log_msg& msg) = 0;
}; };
class pattern_formatter SPDLOG_FINAL : public formatter class pattern_formatter SPDLOG_FINAL : public formatter
{ {
public: 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); 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(const pattern_formatter&) = delete;
pattern_formatter& operator=(const pattern_formatter&) = delete; pattern_formatter& operator=(const pattern_formatter&) = delete;
void format(details::log_msg& msg) override; void format(details::log_msg& msg) override;
private: private:
const std::string _eol; const std::string _eol;
const std::string _pattern; const std::string _pattern;
...@@ -45,4 +45,3 @@ private: ...@@ -45,4 +45,3 @@ private:
} }
#include "details/pattern_formatter_impl.h" #include "details/pattern_formatter_impl.h"
...@@ -23,7 +23,7 @@ namespace sinks ...@@ -23,7 +23,7 @@ namespace sinks
* If no color terminal detected, omit the escape codes. * If no color terminal detected, omit the escape codes.
*/ */
template <class Mutex> template <class Mutex>
class ansicolor_sink: public base_sink<Mutex> class ansicolor_sink : public base_sink<Mutex>
{ {
public: public:
ansicolor_sink(FILE* file): target_file_(file) ansicolor_sink(FILE* file): target_file_(file)
...@@ -37,7 +37,8 @@ public: ...@@ -37,7 +37,8 @@ public:
colors_[level::critical] = bold + on_red; colors_[level::critical] = bold + on_red;
colors_[level::off] = reset; colors_[level::off] = reset;
} }
virtual ~ansicolor_sink()
~ansicolor_sink() override
{ {
_flush(); _flush();
} }
...@@ -79,7 +80,7 @@ public: ...@@ -79,7 +80,7 @@ public:
const std::string on_white = "\033[47m"; const std::string on_white = "\033[47m";
protected: 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. // Wrap the originally formatted message in color codes.
// If color is not supported in the terminal, log as is instead. // If color is not supported in the terminal, log as is instead.
...@@ -102,6 +103,7 @@ protected: ...@@ -102,6 +103,7 @@ protected:
{ {
fflush(target_file_); fflush(target_file_);
} }
FILE* target_file_; FILE* target_file_;
bool should_do_colors_; bool should_do_colors_;
std::unordered_map<level::level_enum, std::string, level::level_hasher> colors_; std::unordered_map<level::level_enum, std::string, level::level_hasher> colors_;
......
...@@ -22,11 +22,10 @@ namespace spdlog ...@@ -22,11 +22,10 @@ namespace spdlog
namespace sinks namespace sinks
{ {
template<class Mutex> template<class Mutex>
class base_sink:public sink class base_sink : public sink
{ {
public: public:
base_sink():_mutex() {} base_sink():_mutex() {}
virtual ~base_sink() = default;
base_sink(const base_sink&) = delete; base_sink(const base_sink&) = delete;
base_sink& operator=(const base_sink&) = delete; base_sink& operator=(const base_sink&) = delete;
...@@ -36,6 +35,7 @@ public: ...@@ -36,6 +35,7 @@ public:
std::lock_guard<Mutex> lock(_mutex); std::lock_guard<Mutex> lock(_mutex);
_sink_it(msg); _sink_it(msg);
} }
void flush() SPDLOG_FINAL override void flush() SPDLOG_FINAL override
{ {
std::lock_guard<Mutex> lock(_mutex); std::lock_guard<Mutex> lock(_mutex);
......
...@@ -22,13 +22,12 @@ namespace spdlog ...@@ -22,13 +22,12 @@ namespace spdlog
namespace sinks namespace sinks
{ {
template<class Mutex> template<class Mutex>
class dist_sink: public base_sink<Mutex> class dist_sink : public base_sink<Mutex>
{ {
public: public:
explicit dist_sink() :_sinks() {} explicit dist_sink() :_sinks() {}
dist_sink(const dist_sink&) = delete; dist_sink(const dist_sink&) = delete;
dist_sink& operator=(const dist_sink&) = delete; dist_sink& operator=(const dist_sink&) = delete;
virtual ~dist_sink() = default;
protected: protected:
std::vector<std::shared_ptr<sink>> _sinks; std::vector<std::shared_ptr<sink>> _sinks;
...@@ -51,8 +50,6 @@ protected: ...@@ -51,8 +50,6 @@ protected:
} }
public: public:
void add_sink(std::shared_ptr<sink> sink) void add_sink(std::shared_ptr<sink> sink)
{ {
std::lock_guard<Mutex> lock(base_sink<Mutex>::_mutex); std::lock_guard<Mutex> lock(base_sink<Mutex>::_mutex);
......
...@@ -26,7 +26,7 @@ namespace sinks ...@@ -26,7 +26,7 @@ namespace sinks
* Trivial file sink with single file as target * Trivial file sink with single file as target
*/ */
template<class Mutex> template<class Mutex>
class simple_file_sink SPDLOG_FINAL : public base_sink < Mutex > class simple_file_sink SPDLOG_FINAL : public base_sink<Mutex>
{ {
public: public:
explicit simple_file_sink(const filename_t &filename, bool truncate = false):_force_flush(false) explicit simple_file_sink(const filename_t &filename, bool truncate = false):_force_flush(false)
...@@ -46,10 +46,12 @@ protected: ...@@ -46,10 +46,12 @@ protected:
if(_force_flush) if(_force_flush)
_file_helper.flush(); _file_helper.flush();
} }
void _flush() override void _flush() override
{ {
_file_helper.flush(); _file_helper.flush();
} }
private: private:
details::file_helper _file_helper; details::file_helper _file_helper;
bool _force_flush; bool _force_flush;
...@@ -112,7 +114,6 @@ protected: ...@@ -112,7 +114,6 @@ protected:
_file_helper.flush(); _file_helper.flush();
} }
private: private:
// Rotate files: // Rotate files:
// log.txt -> log.1.txt // log.txt -> log.1.txt
...@@ -142,6 +143,7 @@ private: ...@@ -142,6 +143,7 @@ private:
} }
_file_helper.reopen(true); _file_helper.reopen(true);
} }
filename_t _base_filename; filename_t _base_filename;
std::size_t _max_size; std::size_t _max_size;
std::size_t _max_files; std::size_t _max_files;
......
...@@ -23,15 +23,13 @@ namespace sinks ...@@ -23,15 +23,13 @@ namespace sinks
* MSVC sink (logging using OutputDebugStringA) * MSVC sink (logging using OutputDebugStringA)
*/ */
template<class Mutex> template<class Mutex>
class msvc_sink : public base_sink < Mutex > class msvc_sink : public base_sink<Mutex>
{ {
public: public:
explicit msvc_sink() explicit msvc_sink()
{ {
} }
protected: protected:
void _sink_it(const details::log_msg& msg) override void _sink_it(const details::log_msg& msg) override
{ {
......
...@@ -16,7 +16,7 @@ namespace sinks ...@@ -16,7 +16,7 @@ namespace sinks
{ {
template <class Mutex> template <class Mutex>
class null_sink : public base_sink < Mutex > class null_sink : public base_sink<Mutex>
{ {
protected: protected:
void _sink_it(const details::log_msg&) override void _sink_it(const details::log_msg&) override
......
...@@ -16,13 +16,12 @@ namespace spdlog ...@@ -16,13 +16,12 @@ namespace spdlog
namespace sinks namespace sinks
{ {
template<class Mutex> template<class Mutex>
class ostream_sink: public base_sink<Mutex> class ostream_sink : public base_sink<Mutex>
{ {
public: public:
explicit ostream_sink(std::ostream& os, bool force_flush=false) :_ostream(os), _force_flush(force_flush) {} explicit ostream_sink(std::ostream& os, bool force_flush=false) :_ostream(os), _force_flush(force_flush) {}
ostream_sink(const ostream_sink&) = delete; ostream_sink(const ostream_sink&) = delete;
ostream_sink& operator=(const ostream_sink&) = delete; ostream_sink& operator=(const ostream_sink&) = delete;
virtual ~ostream_sink() = default;
protected: protected:
void _sink_it(const details::log_msg& msg) override void _sink_it(const details::log_msg& msg) override
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
// Distributed under the MIT License (http://opensource.org/licenses/MIT) // Distributed under the MIT License (http://opensource.org/licenses/MIT)
// //
#pragma once #pragma once
#include "../details/log_msg.h" #include "../details/log_msg.h"
...@@ -20,7 +19,7 @@ public: ...@@ -20,7 +19,7 @@ public:
_level = level::trace; _level = level::trace;
} }
virtual ~sink() {} virtual ~sink() = default;
virtual void log(const details::log_msg& msg) = 0; virtual void log(const details::log_msg& msg) = 0;
virtual void flush() = 0; virtual void flush() = 0;
...@@ -30,7 +29,6 @@ public: ...@@ -30,7 +29,6 @@ public:
private: private:
level_t _level; level_t _level;
}; };
inline bool sink::should_log(level::level_enum msg_level) const inline bool sink::should_log(level::level_enum msg_level) const
...@@ -50,4 +48,3 @@ inline level::level_enum sink::level() const ...@@ -50,4 +48,3 @@ inline level::level_enum sink::level() const
} }
} }
...@@ -50,13 +50,14 @@ class stderr_sink SPDLOG_FINAL : public base_sink<Mutex> ...@@ -50,13 +50,14 @@ class stderr_sink SPDLOG_FINAL : public base_sink<Mutex>
{ {
using MyType = stderr_sink<Mutex>; using MyType = stderr_sink<Mutex>;
public: public:
stderr_sink() explicit stderr_sink() {}
{}
static std::shared_ptr<MyType> instance() static std::shared_ptr<MyType> instance()
{ {
static std::shared_ptr<MyType> instance = std::make_shared<MyType>(); static std::shared_ptr<MyType> instance = std::make_shared<MyType>();
return instance; return instance;
} }
protected: protected:
void _sink_it(const details::log_msg& msg) override void _sink_it(const details::log_msg& msg) override
{ {
......
...@@ -44,7 +44,8 @@ public: ...@@ -44,7 +44,8 @@ public:
//set ident to be program name if empty //set ident to be program name if empty
::openlog(_ident.empty()? nullptr:_ident.c_str(), syslog_option, syslog_facility); ::openlog(_ident.empty()? nullptr:_ident.c_str(), syslog_option, syslog_facility);
} }
~syslog_sink()
~syslog_sink() override
{ {
::closelog(); ::closelog();
} }
......
...@@ -21,8 +21,8 @@ namespace sinks ...@@ -21,8 +21,8 @@ namespace sinks
/* /*
* Windows color console sink. Uses WriteConsoleA to write to the console with colors * Windows color console sink. Uses WriteConsoleA to write to the console with colors
*/ */
template<class Mutex> template <class Mutex>
class wincolor_sink: public base_sink<Mutex> class wincolor_sink : public base_sink<Mutex>
{ {
public: public:
const WORD BOLD = FOREGROUND_INTENSITY; const WORD BOLD = FOREGROUND_INTENSITY;
...@@ -42,7 +42,7 @@ public: ...@@ -42,7 +42,7 @@ public:
colors_[level::off] = 0; colors_[level::off] = 0;
} }
virtual ~wincolor_sink() ~wincolor_sink() override
{ {
this->flush(); this->flush();
} }
...@@ -58,7 +58,7 @@ public: ...@@ -58,7 +58,7 @@ public:
} }
protected: 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 color = colors_[msg.level];
auto orig_attribs = set_console_attribs(color); auto orig_attribs = set_console_attribs(color);
...@@ -66,7 +66,7 @@ protected: ...@@ -66,7 +66,7 @@ protected:
SetConsoleTextAttribute(out_handle_, orig_attribs); //reset to orig colors SetConsoleTextAttribute(out_handle_, orig_attribs); //reset to orig colors
} }
virtual void _flush() override void _flush() override
{ {
// windows console always flushed? // windows console always flushed?
} }
...@@ -92,8 +92,8 @@ private: ...@@ -92,8 +92,8 @@ private:
// //
// windows color console to stdout // windows color console to stdout
// //
template<class Mutex> template <class Mutex>
class wincolor_stdout_sink: public wincolor_sink<Mutex> class wincolor_stdout_sink : public wincolor_sink<Mutex>
{ {
public: public:
wincolor_stdout_sink() : wincolor_sink<Mutex>(GetStdHandle(STD_OUTPUT_HANDLE)) wincolor_stdout_sink() : wincolor_sink<Mutex>(GetStdHandle(STD_OUTPUT_HANDLE))
...@@ -106,8 +106,8 @@ using wincolor_stdout_sink_st = wincolor_stdout_sink<details::null_mutex>; ...@@ -106,8 +106,8 @@ using wincolor_stdout_sink_st = wincolor_stdout_sink<details::null_mutex>;
// //
// windows color console to stderr // windows color console to stderr
// //
template<class Mutex> template <class Mutex>
class wincolor_stderr_sink: public wincolor_sink<Mutex> class wincolor_stderr_sink : public wincolor_sink<Mutex>
{ {
public: public:
wincolor_stderr_sink() : wincolor_sink<Mutex>(GetStdHandle(STD_ERROR_HANDLE)) wincolor_stderr_sink() : wincolor_sink<Mutex>(GetStdHandle(STD_ERROR_HANDLE))
......
...@@ -17,7 +17,7 @@ namespace sinks ...@@ -17,7 +17,7 @@ namespace sinks
/* /*
* Windows debug sink (logging using OutputDebugStringA, synonym for msvc_sink) * Windows debug sink (logging using OutputDebugStringA, synonym for msvc_sink)
*/ */
template<class Mutex> template <class Mutex>
using windebug_sink = msvc_sink<Mutex>; using windebug_sink = msvc_sink<Mutex>;
using windebug_sink_mt = msvc_sink_mt; using windebug_sink_mt = msvc_sink_mt;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment