Commit a21594be authored by gabime's avatar gabime

move underscores to the end of private members

parent 7d975de1
...@@ -3,25 +3,18 @@ CXX_FLAGS = -Wall -Wshadow -Wextra -pedantic -std=c++11 -pthread -I../include ...@@ -3,25 +3,18 @@ CXX_FLAGS = -Wall -Wshadow -Wextra -pedantic -std=c++11 -pthread -I../include
CXX_RELEASE_FLAGS = -O3 -march=native CXX_RELEASE_FLAGS = -O3 -march=native
CXX_DEBUG_FLAGS= -g CXX_DEBUG_FLAGS= -g
all: example
all: example bench debug: example-debug
debug: example-debug bench-debug
example: example.cpp example: example.cpp
$(CXX) example.cpp -o example $(CXX_FLAGS) $(CXX_RELEASE_FLAGS) $(CXXFLAGS) $(CXX) example.cpp -o example $(CXX_FLAGS) $(CXX_RELEASE_FLAGS) $(CXXFLAGS)
bench: bench.cpp
$(CXX) bench.cpp -o bench $(CXX_FLAGS) $(CXX_RELEASE_FLAGS) $(CXXFLAGS)
example-debug: example.cpp example-debug: example.cpp
$(CXX) example.cpp -o example-debug $(CXX_FLAGS) $(CXX_DEBUG_FLAGS) $(CXXFLAGS) $(CXX) example.cpp -o example-debug $(CXX_FLAGS) $(CXX_DEBUG_FLAGS) $(CXXFLAGS)
bench-debug: bench.cpp
$(CXX) bench.cpp -o bench-debug $(CXX_FLAGS) $(CXX_DEBUG_FLAGS) $(CXXFLAGS)
clean: clean:
rm -f *.o logs/*.txt example example-debug bench bench-debug rm -f *.o logs/*.txt example example-debug
rebuild: clean all rebuild: clean all
......
...@@ -43,15 +43,15 @@ public: ...@@ -43,15 +43,15 @@ public:
async_overflow_policy overflow_policy = async_overflow_policy::block_retry); async_overflow_policy overflow_policy = async_overflow_policy::block_retry);
protected: protected:
void _sink_it(details::log_msg &msg) override; void sink_it_(details::log_msg &msg) override;
void _flush() override; void flush_() override;
void _backend_log(details::log_msg &incoming_log_msg); void backend_log_(details::log_msg &incoming_log_msg);
void _backend_flush(); void backend_flush_();
private: private:
std::weak_ptr<details::thread_pool> _thread_pool; std::weak_ptr<details::thread_pool> thread_pool_;
async_overflow_policy _overflow_policy; async_overflow_policy overflow_policy_;
}; };
} // namespace spdlog } // namespace spdlog
......
...@@ -193,10 +193,10 @@ using filename_t = std::string; ...@@ -193,10 +193,10 @@ using filename_t = std::string;
#define SPDLOG_CATCH_AND_HANDLE \ #define SPDLOG_CATCH_AND_HANDLE \
catch (const std::exception &ex) \ catch (const std::exception &ex) \
{ \ { \
_err_handler(ex.what()); \ err_handler_(ex.what()); \
} \ } \
catch (...) \ catch (...) \
{ \ { \
_err_handler("Unknown exeption in logger"); \ err_handler_("Unknown exeption in logger"); \
} }
} // namespace spdlog } // namespace spdlog
...@@ -18,8 +18,8 @@ template<class It> ...@@ -18,8 +18,8 @@ template<class It>
inline spdlog::async_logger::async_logger(const std::string &logger_name, const It &begin, const It &end, inline spdlog::async_logger::async_logger(const std::string &logger_name, const It &begin, const It &end,
std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy) std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy)
: logger(logger_name, begin, end) : logger(logger_name, begin, end)
, _thread_pool(tp) , thread_pool_(tp)
, _overflow_policy(overflow_policy) , overflow_policy_(overflow_policy)
{ {
} }
...@@ -36,14 +36,14 @@ inline spdlog::async_logger::async_logger( ...@@ -36,14 +36,14 @@ inline spdlog::async_logger::async_logger(
} }
// send the log message to the thread pool // send the log message to the thread pool
inline void spdlog::async_logger::_sink_it(details::log_msg &msg) inline void spdlog::async_logger::sink_it_(details::log_msg &msg)
{ {
#if defined(SPDLOG_ENABLE_MESSAGE_COUNTER) #if defined(SPDLOG_ENABLE_MESSAGE_COUNTER)
_incr_msg_counter(msg); _incr_msg_counter(msg);
#endif #endif
if (auto pool_ptr = _thread_pool.lock()) if (auto pool_ptr = thread_pool_.lock())
{ {
pool_ptr->post_log(shared_from_this(), std::move(msg), _overflow_policy); pool_ptr->post_log(shared_from_this(), std::move(msg), overflow_policy_);
} }
else else
{ {
...@@ -52,11 +52,11 @@ inline void spdlog::async_logger::_sink_it(details::log_msg &msg) ...@@ -52,11 +52,11 @@ inline void spdlog::async_logger::_sink_it(details::log_msg &msg)
} }
// send flush request to the thread pool // send flush request to the thread pool
inline void spdlog::async_logger::_flush() inline void spdlog::async_logger::flush_()
{ {
if (auto pool_ptr = _thread_pool.lock()) if (auto pool_ptr = thread_pool_.lock())
{ {
pool_ptr->post_flush(shared_from_this(), _overflow_policy); pool_ptr->post_flush(shared_from_this(), overflow_policy_);
} }
else else
{ {
...@@ -67,12 +67,12 @@ inline void spdlog::async_logger::_flush() ...@@ -67,12 +67,12 @@ inline void spdlog::async_logger::_flush()
// //
// backend functions - called from the thread pool to do the actual job // backend functions - called from the thread pool to do the actual job
// //
inline void spdlog::async_logger::_backend_log(details::log_msg &incoming_log_msg) inline void spdlog::async_logger::backend_log_(details::log_msg &incoming_log_msg)
{ {
try try
{ {
_formatter->format(incoming_log_msg); formatter_->format(incoming_log_msg);
for (auto &s : _sinks) for (auto &s : sinks_)
{ {
if (s->should_log(incoming_log_msg.level)) if (s->should_log(incoming_log_msg.level))
{ {
...@@ -82,17 +82,17 @@ inline void spdlog::async_logger::_backend_log(details::log_msg &incoming_log_ms ...@@ -82,17 +82,17 @@ inline void spdlog::async_logger::_backend_log(details::log_msg &incoming_log_ms
} }
SPDLOG_CATCH_AND_HANDLE SPDLOG_CATCH_AND_HANDLE
if (_should_flush(incoming_log_msg)) if (should_flush_(incoming_log_msg))
{ {
_backend_flush(); backend_flush_();
} }
} }
inline void spdlog::async_logger::_backend_flush() inline void spdlog::async_logger::backend_flush_()
{ {
try try
{ {
for (auto &sink : _sinks) for (auto &sink : sinks_)
{ {
sink->flush(); sink->flush();
} }
......
...@@ -12,15 +12,15 @@ ...@@ -12,15 +12,15 @@
// all other ctors will call this one // all other ctors will call this one
template<class It> template<class It>
inline spdlog::logger::logger(std::string logger_name, const It &begin, const It &end) inline spdlog::logger::logger(std::string logger_name, const It &begin, const It &end)
: _name(std::move(logger_name)) : name_(std::move(logger_name))
, _sinks(begin, end) , sinks_(begin, end)
, _formatter(std::make_shared<pattern_formatter>("%+")) , formatter_(std::make_shared<pattern_formatter>("%+"))
, _level(level::info) , level_(level::info)
, _flush_level(level::off) , flush_level_(level::off)
, _last_err_time(0) , last_err_time_(0)
, _msg_counter(1) // message counter will start from 1. 0-message id will be reserved for controll messages , msg_counter_(1) // message counter will start from 1. 0-message id will be reserved for controll messages
{ {
_err_handler = [this](const std::string &msg) { this->_default_err_handler(msg); }; err_handler_ = [this](const std::string &msg) { this->default_err_handler_(msg); };
} }
// ctor with sinks as init list // ctor with sinks as init list
...@@ -39,12 +39,12 @@ inline spdlog::logger::~logger() = default; ...@@ -39,12 +39,12 @@ inline spdlog::logger::~logger() = default;
inline void spdlog::logger::set_formatter(spdlog::formatter_ptr msg_formatter) inline void spdlog::logger::set_formatter(spdlog::formatter_ptr msg_formatter)
{ {
_formatter = std::move(msg_formatter); formatter_ = std::move(msg_formatter);
} }
inline void spdlog::logger::set_pattern(const std::string &pattern, pattern_time_type pattern_time) inline void spdlog::logger::set_pattern(const std::string &pattern, pattern_time_type pattern_time)
{ {
_formatter = std::make_shared<pattern_formatter>(pattern, pattern_time); formatter_ = std::make_shared<pattern_formatter>(pattern, pattern_time);
} }
template<typename... Args> template<typename... Args>
...@@ -57,14 +57,14 @@ inline void spdlog::logger::log(level::level_enum lvl, const char *fmt, const Ar ...@@ -57,14 +57,14 @@ inline void spdlog::logger::log(level::level_enum lvl, const char *fmt, const Ar
try try
{ {
details::log_msg log_msg(&_name, lvl); details::log_msg log_msg(&name_, lvl);
#if defined(SPDLOG_FMT_PRINTF) #if defined(SPDLOG_FMT_PRINTF)
fmt::printf(log_msg.raw, fmt, args...); fmt::printf(log_msg.raw, fmt, args...);
#else #else
log_msg.raw.write(fmt, args...); log_msg.raw.write(fmt, args...);
#endif #endif
_sink_it(log_msg); sink_it_(log_msg);
} }
SPDLOG_CATCH_AND_HANDLE SPDLOG_CATCH_AND_HANDLE
} }
...@@ -78,9 +78,9 @@ inline void spdlog::logger::log(level::level_enum lvl, const char *msg) ...@@ -78,9 +78,9 @@ inline void spdlog::logger::log(level::level_enum lvl, const char *msg)
} }
try try
{ {
details::log_msg log_msg(&_name, lvl); details::log_msg log_msg(&name_, lvl);
log_msg.raw << msg; log_msg.raw << msg;
_sink_it(log_msg); sink_it_(log_msg);
} }
SPDLOG_CATCH_AND_HANDLE SPDLOG_CATCH_AND_HANDLE
} }
...@@ -94,9 +94,9 @@ inline void spdlog::logger::log(level::level_enum lvl, const T &msg) ...@@ -94,9 +94,9 @@ inline void spdlog::logger::log(level::level_enum lvl, const T &msg)
} }
try try
{ {
details::log_msg log_msg(&_name, lvl); details::log_msg log_msg(&name_, lvl);
log_msg.raw << msg; log_msg.raw << msg;
_sink_it(log_msg); sink_it_(log_msg);
} }
SPDLOG_CATCH_AND_HANDLE SPDLOG_CATCH_AND_HANDLE
} }
...@@ -237,64 +237,64 @@ inline void spdlog::logger::critical(const wchar_t *fmt, const Args &... args) ...@@ -237,64 +237,64 @@ inline void spdlog::logger::critical(const wchar_t *fmt, const Args &... args)
// //
inline const std::string &spdlog::logger::name() const inline const std::string &spdlog::logger::name() const
{ {
return _name; return name_;
} }
inline void spdlog::logger::set_level(spdlog::level::level_enum log_level) inline void spdlog::logger::set_level(spdlog::level::level_enum log_level)
{ {
_level.store(log_level); level_.store(log_level);
} }
inline void spdlog::logger::set_error_handler(spdlog::log_err_handler err_handler) inline void spdlog::logger::set_error_handler(spdlog::log_err_handler err_handler)
{ {
_err_handler = std::move(err_handler); err_handler_ = std::move(err_handler);
} }
inline spdlog::log_err_handler spdlog::logger::error_handler() inline spdlog::log_err_handler spdlog::logger::error_handler()
{ {
return _err_handler; return err_handler_;
} }
inline void spdlog::logger::flush() inline void spdlog::logger::flush()
{ {
try try
{ {
_flush(); flush_();
} }
SPDLOG_CATCH_AND_HANDLE SPDLOG_CATCH_AND_HANDLE
} }
inline void spdlog::logger::flush_on(level::level_enum log_level) inline void spdlog::logger::flush_on(level::level_enum log_level)
{ {
_flush_level.store(log_level); flush_level_.store(log_level);
} }
inline bool spdlog::logger::_should_flush(const details::log_msg &msg) inline bool spdlog::logger::should_flush_(const details::log_msg &msg)
{ {
auto flush_level = _flush_level.load(std::memory_order_relaxed); auto flush_level = flush_level_.load(std::memory_order_relaxed);
return (msg.level >= flush_level) && (msg.level != level::off); return (msg.level >= flush_level) && (msg.level != level::off);
} }
inline spdlog::level::level_enum spdlog::logger::level() const inline spdlog::level::level_enum spdlog::logger::level() const
{ {
return static_cast<spdlog::level::level_enum>(_level.load(std::memory_order_relaxed)); return static_cast<spdlog::level::level_enum>(level_.load(std::memory_order_relaxed));
} }
inline bool spdlog::logger::should_log(spdlog::level::level_enum msg_level) const inline bool spdlog::logger::should_log(spdlog::level::level_enum msg_level) const
{ {
return msg_level >= _level.load(std::memory_order_relaxed); return msg_level >= level_.load(std::memory_order_relaxed);
} }
// //
// protected virtual called at end of each user log call (if enabled) by the line_logger // protected virtual called at end of each user log call (if enabled) by the line_logger
// //
inline void spdlog::logger::_sink_it(details::log_msg &msg) inline void spdlog::logger::sink_it_(details::log_msg &msg)
{ {
#if defined(SPDLOG_ENABLE_MESSAGE_COUNTER) #if defined(SPDLOG_ENABLE_MESSAGE_COUNTER)
_incr_msg_counter(msg); incr_msg_counter_(msg);
#endif #endif
_formatter->format(msg); formatter_->format(msg);
for (auto &sink : _sinks) for (auto &sink : sinks_)
{ {
if (sink->should_log(msg.level)) if (sink->should_log(msg.level))
{ {
...@@ -302,40 +302,40 @@ inline void spdlog::logger::_sink_it(details::log_msg &msg) ...@@ -302,40 +302,40 @@ inline void spdlog::logger::_sink_it(details::log_msg &msg)
} }
} }
if (_should_flush(msg)) if (should_flush_(msg))
{ {
flush(); flush();
} }
} }
inline void spdlog::logger::_flush() inline void spdlog::logger::flush_()
{ {
for (auto &sink : _sinks) for (auto &sink : sinks_)
{ {
sink->flush(); sink->flush();
} }
} }
inline void spdlog::logger::_default_err_handler(const std::string &msg) inline void spdlog::logger::default_err_handler_(const std::string &msg)
{ {
auto now = time(nullptr); auto now = time(nullptr);
if (now - _last_err_time < 60) if (now - last_err_time_ < 60)
{ {
return; return;
} }
_last_err_time = now; last_err_time_ = now;
auto tm_time = details::os::localtime(now); auto tm_time = details::os::localtime(now);
char date_buf[100]; char date_buf[100];
std::strftime(date_buf, sizeof(date_buf), "%Y-%m-%d %H:%M:%S", &tm_time); std::strftime(date_buf, sizeof(date_buf), "%Y-%m-%d %H:%M:%S", &tm_time);
fmt::print(stderr, "[*** LOG ERROR ***] [{}] [{}] {}\n", date_buf, name(), msg); fmt::print(stderr, "[*** LOG ERROR ***] [{}] [{}] {}\n", date_buf, name(), msg);
} }
inline void spdlog::logger::_incr_msg_counter(details::log_msg &msg) inline void spdlog::logger::incr_msg_counter_(details::log_msg &msg)
{ {
msg.msg_id = _msg_counter.fetch_add(1, std::memory_order_relaxed); msg.msg_id = msg_counter_.fetch_add(1, std::memory_order_relaxed);
} }
inline const std::vector<spdlog::sink_ptr> &spdlog::logger::sinks() const inline const std::vector<spdlog::sink_ptr> &spdlog::logger::sinks() const
{ {
return _sinks; return sinks_;
} }
...@@ -335,19 +335,19 @@ public: ...@@ -335,19 +335,19 @@ public:
} }
private: private:
log_clock::time_point _last_update{std::chrono::seconds(0)}; log_clock::time_point last_update_{std::chrono::seconds(0)};
int _offset_minutes{0}; int offset_minutes_{0};
std::mutex _mutex; std::mutex mutex_;
int get_cached_offset(const log_msg &msg, const std::tm &tm_time) int get_cached_offset(const log_msg &msg, const std::tm &tm_time)
{ {
std::lock_guard<std::mutex> l(_mutex); std::lock_guard<std::mutex> l(mutex_);
if (msg.time - _last_update >= cache_refresh) if (msg.time - last_update_ >= cache_refresh)
{ {
_offset_minutes = os::utc_minutes_offset(tm_time); offset_minutes_ = os::utc_minutes_offset(tm_time);
_last_update = msg.time; last_update_ = msg.time;
} }
return _offset_minutes; return offset_minutes_;
} }
}; };
...@@ -390,16 +390,16 @@ class ch_formatter SPDLOG_FINAL : public flag_formatter ...@@ -390,16 +390,16 @@ class ch_formatter SPDLOG_FINAL : public flag_formatter
{ {
public: public:
explicit ch_formatter(char ch) explicit ch_formatter(char ch)
: _ch(ch) : ch_(ch)
{ {
} }
void format(details::log_msg &msg, const std::tm &) override void format(details::log_msg &msg, const std::tm &) override
{ {
msg.formatted << _ch; msg.formatted << ch_;
} }
private: private:
char _ch; char ch_;
}; };
// aggregate user chars to display as is // aggregate user chars to display as is
...@@ -410,15 +410,15 @@ public: ...@@ -410,15 +410,15 @@ public:
void add_ch(char ch) void add_ch(char ch)
{ {
_str += ch; str_ += ch;
} }
void format(details::log_msg &msg, const std::tm &) override void format(details::log_msg &msg, const std::tm &) override
{ {
msg.formatted << _str; msg.formatted << str_;
} }
private: private:
std::string _str; std::string str_;
}; };
// mark the color range. expect it to be in the form of "%^colored text%$" // mark the color range. expect it to be in the form of "%^colored text%$"
...@@ -493,8 +493,8 @@ class full_formatter SPDLOG_FINAL : public flag_formatter ...@@ -493,8 +493,8 @@ class full_formatter SPDLOG_FINAL : public flag_formatter
// pattern_formatter inline impl // pattern_formatter inline impl
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
inline spdlog::pattern_formatter::pattern_formatter(const std::string &pattern, pattern_time_type pattern_time, std::string eol) inline spdlog::pattern_formatter::pattern_formatter(const std::string &pattern, pattern_time_type pattern_time, std::string eol)
: _eol(std::move(eol)) : eol_(std::move(eol))
, _pattern_time(pattern_time) , pattern_time_(pattern_time)
{ {
compile_pattern(pattern); compile_pattern(pattern);
} }
...@@ -509,7 +509,7 @@ inline void spdlog::pattern_formatter::compile_pattern(const std::string &patter ...@@ -509,7 +509,7 @@ inline void spdlog::pattern_formatter::compile_pattern(const std::string &patter
{ {
if (user_chars) // append user chars found so far if (user_chars) // append user chars found so far
{ {
_formatters.push_back(std::move(user_chars)); formatters_.push_back(std::move(user_chars));
} }
// if( // if(
if (++it != end) if (++it != end)
...@@ -532,7 +532,7 @@ inline void spdlog::pattern_formatter::compile_pattern(const std::string &patter ...@@ -532,7 +532,7 @@ inline void spdlog::pattern_formatter::compile_pattern(const std::string &patter
} }
if (user_chars) // append raw chars found so far if (user_chars) // append raw chars found so far
{ {
_formatters.push_back(std::move(user_chars)); formatters_.push_back(std::move(user_chars));
} }
} }
inline void spdlog::pattern_formatter::handle_flag(char flag) inline void spdlog::pattern_formatter::handle_flag(char flag)
...@@ -541,149 +541,149 @@ inline void spdlog::pattern_formatter::handle_flag(char flag) ...@@ -541,149 +541,149 @@ inline void spdlog::pattern_formatter::handle_flag(char flag)
{ {
// logger name // logger name
case 'n': case 'n':
_formatters.emplace_back(new details::name_formatter()); formatters_.emplace_back(new details::name_formatter());
break; break;
case 'l': case 'l':
_formatters.emplace_back(new details::level_formatter()); formatters_.emplace_back(new details::level_formatter());
break; break;
case 'L': case 'L':
_formatters.emplace_back(new details::short_level_formatter()); formatters_.emplace_back(new details::short_level_formatter());
break; break;
case ('t'): case ('t'):
_formatters.emplace_back(new details::t_formatter()); formatters_.emplace_back(new details::t_formatter());
break; break;
case ('v'): case ('v'):
_formatters.emplace_back(new details::v_formatter()); formatters_.emplace_back(new details::v_formatter());
break; break;
case ('a'): case ('a'):
_formatters.emplace_back(new details::a_formatter()); formatters_.emplace_back(new details::a_formatter());
break; break;
case ('A'): case ('A'):
_formatters.emplace_back(new details::A_formatter()); formatters_.emplace_back(new details::A_formatter());
break; break;
case ('b'): case ('b'):
case ('h'): case ('h'):
_formatters.emplace_back(new details::b_formatter()); formatters_.emplace_back(new details::b_formatter());
break; break;
case ('B'): case ('B'):
_formatters.emplace_back(new details::B_formatter()); formatters_.emplace_back(new details::B_formatter());
break; break;
case ('c'): case ('c'):
_formatters.emplace_back(new details::c_formatter()); formatters_.emplace_back(new details::c_formatter());
break; break;
case ('C'): case ('C'):
_formatters.emplace_back(new details::C_formatter()); formatters_.emplace_back(new details::C_formatter());
break; break;
case ('Y'): case ('Y'):
_formatters.emplace_back(new details::Y_formatter()); formatters_.emplace_back(new details::Y_formatter());
break; break;
case ('D'): case ('D'):
case ('x'): case ('x'):
_formatters.emplace_back(new details::D_formatter()); formatters_.emplace_back(new details::D_formatter());
break; break;
case ('m'): case ('m'):
_formatters.emplace_back(new details::m_formatter()); formatters_.emplace_back(new details::m_formatter());
break; break;
case ('d'): case ('d'):
_formatters.emplace_back(new details::d_formatter()); formatters_.emplace_back(new details::d_formatter());
break; break;
case ('H'): case ('H'):
_formatters.emplace_back(new details::H_formatter()); formatters_.emplace_back(new details::H_formatter());
break; break;
case ('I'): case ('I'):
_formatters.emplace_back(new details::I_formatter()); formatters_.emplace_back(new details::I_formatter());
break; break;
case ('M'): case ('M'):
_formatters.emplace_back(new details::M_formatter()); formatters_.emplace_back(new details::M_formatter());
break; break;
case ('S'): case ('S'):
_formatters.emplace_back(new details::S_formatter()); formatters_.emplace_back(new details::S_formatter());
break; break;
case ('e'): case ('e'):
_formatters.emplace_back(new details::e_formatter()); formatters_.emplace_back(new details::e_formatter());
break; break;
case ('f'): case ('f'):
_formatters.emplace_back(new details::f_formatter()); formatters_.emplace_back(new details::f_formatter());
break; break;
case ('F'): case ('F'):
_formatters.emplace_back(new details::F_formatter()); formatters_.emplace_back(new details::F_formatter());
break; break;
case ('E'): case ('E'):
_formatters.emplace_back(new details::E_formatter()); formatters_.emplace_back(new details::E_formatter());
break; break;
case ('p'): case ('p'):
_formatters.emplace_back(new details::p_formatter()); formatters_.emplace_back(new details::p_formatter());
break; break;
case ('r'): case ('r'):
_formatters.emplace_back(new details::r_formatter()); formatters_.emplace_back(new details::r_formatter());
break; break;
case ('R'): case ('R'):
_formatters.emplace_back(new details::R_formatter()); formatters_.emplace_back(new details::R_formatter());
break; break;
case ('T'): case ('T'):
case ('X'): case ('X'):
_formatters.emplace_back(new details::T_formatter()); formatters_.emplace_back(new details::T_formatter());
break; break;
case ('z'): case ('z'):
_formatters.emplace_back(new details::z_formatter()); formatters_.emplace_back(new details::z_formatter());
break; break;
case ('+'): case ('+'):
_formatters.emplace_back(new details::full_formatter()); formatters_.emplace_back(new details::full_formatter());
break; break;
case ('P'): case ('P'):
_formatters.emplace_back(new details::pid_formatter()); formatters_.emplace_back(new details::pid_formatter());
break; break;
case ('i'): case ('i'):
_formatters.emplace_back(new details::i_formatter()); formatters_.emplace_back(new details::i_formatter());
break; break;
case ('^'): case ('^'):
_formatters.emplace_back(new details::color_start_formatter()); formatters_.emplace_back(new details::color_start_formatter());
break; break;
case ('$'): case ('$'):
_formatters.emplace_back(new details::color_stop_formatter()); formatters_.emplace_back(new details::color_stop_formatter());
break; break;
default: // Unknown flag appears as is default: // Unknown flag appears as is
_formatters.emplace_back(new details::ch_formatter('%')); formatters_.emplace_back(new details::ch_formatter('%'));
_formatters.emplace_back(new details::ch_formatter(flag)); formatters_.emplace_back(new details::ch_formatter(flag));
break; break;
} }
} }
inline std::tm spdlog::pattern_formatter::get_time(details::log_msg &msg) inline std::tm spdlog::pattern_formatter::get_time(details::log_msg &msg)
{ {
if (_pattern_time == pattern_time_type::local) if (pattern_time_ == pattern_time_type::local)
{ {
return details::os::localtime(log_clock::to_time_t(msg.time)); return details::os::localtime(log_clock::to_time_t(msg.time));
} }
...@@ -698,10 +698,10 @@ inline void spdlog::pattern_formatter::format(details::log_msg &msg) ...@@ -698,10 +698,10 @@ inline void spdlog::pattern_formatter::format(details::log_msg &msg)
#else #else
std::tm tm_time; std::tm tm_time;
#endif #endif
for (auto &f : _formatters) for (auto &f : formatters_)
{ {
f->format(msg, tm_time); f->format(msg, tm_time);
} }
// write eol // write eol
msg.formatted << _eol; msg.formatted << eol_;
} }
...@@ -170,7 +170,7 @@ private: ...@@ -170,7 +170,7 @@ private:
{ {
case async_msg_type::flush: case async_msg_type::flush:
{ {
incoming_async_msg.worker_ptr->_backend_flush(); incoming_async_msg.worker_ptr->backend_flush_();
return true; return true;
} }
...@@ -183,7 +183,7 @@ private: ...@@ -183,7 +183,7 @@ private:
{ {
log_msg msg; log_msg msg;
incoming_async_msg.to_log_msg(std::move(msg)); incoming_async_msg.to_log_msg(std::move(msg));
incoming_async_msg.worker_ptr->_backend_log(msg); incoming_async_msg.worker_ptr->backend_log_(msg);
return true; return true;
} }
} }
......
...@@ -33,10 +33,9 @@ public: ...@@ -33,10 +33,9 @@ public:
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 pattern_time_type pattern_time_;
const pattern_time_type _pattern_time; std::vector<std::unique_ptr<details::flag_formatter>> formatters_;
std::vector<std::unique_ptr<details::flag_formatter>> _formatters;
std::tm get_time(details::log_msg &msg); std::tm get_time(details::log_msg &msg);
void handle_flag(char flag); void handle_flag(char flag);
void compile_pattern(const std::string &pattern); void compile_pattern(const std::string &pattern);
......
...@@ -124,25 +124,25 @@ public: ...@@ -124,25 +124,25 @@ public:
log_err_handler error_handler(); log_err_handler error_handler();
protected: protected:
virtual void _sink_it(details::log_msg &msg); virtual void sink_it_(details::log_msg &msg);
virtual void _flush(); virtual void flush_();
bool _should_flush(const details::log_msg &msg); bool should_flush_(const details::log_msg &msg);
// default error handler: print the error to stderr with the max rate of 1 message/minute // default error handler: print the error to stderr with the max rate of 1 message/minute
void _default_err_handler(const std::string &msg); void default_err_handler_(const std::string &msg);
// increment the message count (only if defined(SPDLOG_ENABLE_MESSAGE_COUNTER)) // increment the message count (only if defined(SPDLOG_ENABLE_MESSAGE_COUNTER))
void _incr_msg_counter(details::log_msg &msg); void incr_msg_counter_(details::log_msg &msg);
const std::string _name; const std::string name_;
std::vector<sink_ptr> _sinks; std::vector<sink_ptr> sinks_;
formatter_ptr _formatter; formatter_ptr formatter_;
spdlog::level_t _level; spdlog::level_t level_;
spdlog::level_t _flush_level; spdlog::level_t flush_level_;
log_err_handler _err_handler; log_err_handler err_handler_;
std::atomic<time_t> _last_err_time; std::atomic<time_t> last_err_time_;
std::atomic<size_t> _msg_counter; std::atomic<size_t> msg_counter_;
}; };
} // namespace spdlog } // namespace spdlog
......
...@@ -31,23 +31,23 @@ class android_sink : public sink ...@@ -31,23 +31,23 @@ class android_sink : public sink
{ {
public: public:
explicit android_sink(const std::string &tag = "spdlog", bool use_raw_msg = false) explicit android_sink(const std::string &tag = "spdlog", bool use_raw_msg = false)
: _tag(tag) : tag_(tag)
, _use_raw_msg(use_raw_msg) , use_raw_msg_(use_raw_msg)
{ {
} }
void log(const details::log_msg &msg) override void log(const details::log_msg &msg) override
{ {
const android_LogPriority priority = convert_to_android(msg.level); const android_LogPriority priority = convert_to_android(msg.level);
const char *msg_output = (_use_raw_msg ? msg.raw.c_str() : msg.formatted.c_str()); const char *msg_output = (use_raw_msg_ ? msg.raw.c_str() : msg.formatted.c_str());
// See system/core/liblog/logger_write.c for explanation of return value // See system/core/liblog/logger_write.c for explanation of return value
int ret = __android_log_write(priority, _tag.c_str(), msg_output); int ret = __android_log_write(priority, tag_.c_str(), msg_output);
int retry_count = 0; int retry_count = 0;
while ((ret == -11 /*EAGAIN*/) && (retry_count < SPDLOG_ANDROID_RETRIES)) while ((ret == -11 /*EAGAIN*/) && (retry_count < SPDLOG_ANDROID_RETRIES))
{ {
details::os::sleep_for_millis(5); details::os::sleep_for_millis(5);
ret = __android_log_write(priority, _tag.c_str(), msg_output); ret = __android_log_write(priority, tag_.c_str(), msg_output);
retry_count++; retry_count++;
} }
...@@ -81,8 +81,8 @@ private: ...@@ -81,8 +81,8 @@ private:
} }
} }
std::string _tag; std::string tag_;
bool _use_raw_msg; bool use_raw_msg_;
}; };
} // namespace sinks } // namespace sinks
......
...@@ -29,7 +29,7 @@ public: ...@@ -29,7 +29,7 @@ public:
using mutex_t = typename ConsoleMutexTrait::mutex_t; using mutex_t = typename ConsoleMutexTrait::mutex_t;
ansicolor_sink() ansicolor_sink()
: target_file_(StreamTrait::stream()) : target_file_(StreamTrait::stream())
, _mutex(ConsoleMutexTrait::console_mutex()) , mutex_(ConsoleMutexTrait::console_mutex())
{ {
should_do_colors_ = details::os::in_terminal(target_file_) && details::os::is_color_terminal(); should_do_colors_ = details::os::in_terminal(target_file_) && details::os::is_color_terminal();
...@@ -49,7 +49,7 @@ public: ...@@ -49,7 +49,7 @@ public:
void set_color(level::level_enum color_level, const std::string &color) void set_color(level::level_enum color_level, const std::string &color)
{ {
std::lock_guard<mutex_t> lock(_mutex); std::lock_guard<mutex_t> lock(mutex_);
colors_[color_level] = color; colors_[color_level] = color;
} }
...@@ -87,43 +87,43 @@ public: ...@@ -87,43 +87,43 @@ public:
{ {
// 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.
std::lock_guard<mutex_t> lock(_mutex); std::lock_guard<mutex_t> lock(mutex_);
if (should_do_colors_ && msg.color_range_end > msg.color_range_start) if (should_do_colors_ && msg.color_range_end > msg.color_range_start)
{ {
// before color range // before color range
_print_range(msg, 0, msg.color_range_start); print_range_(msg, 0, msg.color_range_start);
// in color range // in color range
_print_ccode(colors_[msg.level]); print_ccode_(colors_[msg.level]);
_print_range(msg, msg.color_range_start, msg.color_range_end); print_range_(msg, msg.color_range_start, msg.color_range_end);
_print_ccode(reset); print_ccode_(reset);
// after color range // after color range
_print_range(msg, msg.color_range_end, msg.formatted.size()); print_range_(msg, msg.color_range_end, msg.formatted.size());
} }
else // no color else // no color
{ {
_print_range(msg, 0, msg.formatted.size()); print_range_(msg, 0, msg.formatted.size());
} }
fflush(target_file_); fflush(target_file_);
} }
void flush() SPDLOG_FINAL override void flush() SPDLOG_FINAL override
{ {
std::lock_guard<mutex_t> lock(_mutex); std::lock_guard<mutex_t> lock(mutex_);
fflush(target_file_); fflush(target_file_);
} }
private: private:
void _print_ccode(const std::string &color_code) void print_ccode_(const std::string &color_code)
{ {
fwrite(color_code.data(), sizeof(char), color_code.size(), target_file_); fwrite(color_code.data(), sizeof(char), color_code.size(), target_file_);
} }
void _print_range(const details::log_msg &msg, size_t start, size_t end) void print_range_(const details::log_msg &msg, size_t start, size_t end)
{ {
fwrite(msg.formatted.data() + start, sizeof(char), end - start, target_file_); fwrite(msg.formatted.data() + start, sizeof(char), end - start, target_file_);
} }
FILE *target_file_; FILE *target_file_;
mutex_t &_mutex; mutex_t &mutex_;
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_;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#pragma once #pragma once
// //
// base sink templated over a mutex (either dummy or real) // base sink templated over a mutex (either dummy or real)
// concrete implementation should only override the _sink_it method. // concrete implementation should only override the sink_it_ method.
// all locking is taken care of here so no locking needed by the implementers.. // all locking is taken care of here so no locking needed by the implementers..
// //
...@@ -28,20 +28,21 @@ public: ...@@ -28,20 +28,21 @@ public:
void log(const details::log_msg &msg) SPDLOG_FINAL override void log(const details::log_msg &msg) SPDLOG_FINAL override
{ {
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_);
_flush(); flush_();
} }
protected: protected:
virtual void _sink_it(const details::log_msg &msg) = 0; virtual void sink_it_(const details::log_msg &msg) = 0;
virtual void _flush() = 0; virtual void flush_() = 0;
Mutex _mutex; Mutex mutex_;
}; };
} // namespace sinks } // namespace sinks
} // namespace spdlog } // namespace spdlog
...@@ -63,42 +63,42 @@ class daily_file_sink SPDLOG_FINAL : public base_sink<Mutex> ...@@ -63,42 +63,42 @@ class daily_file_sink SPDLOG_FINAL : public base_sink<Mutex>
public: public:
// create daily file sink which rotates on given time // create daily file sink which rotates on given time
daily_file_sink(filename_t base_filename, int rotation_hour, int rotation_minute) daily_file_sink(filename_t base_filename, int rotation_hour, int rotation_minute)
: _base_filename(std::move(base_filename)) : base_filename_(std::move(base_filename))
, _rotation_h(rotation_hour) , rotation_h_(rotation_hour)
, _rotation_m(rotation_minute) , rotation_m_(rotation_minute)
{ {
if (rotation_hour < 0 || rotation_hour > 23 || rotation_minute < 0 || rotation_minute > 59) if (rotation_hour < 0 || rotation_hour > 23 || rotation_minute < 0 || rotation_minute > 59)
{ {
throw spdlog_ex("daily_file_sink: Invalid rotation time in ctor"); throw spdlog_ex("daily_file_sink: Invalid rotation time in ctor");
} }
_rotation_tp = _next_rotation_tp(); rotation_tp_ = next_rotation_tp_();
_file_helper.open(FileNameCalc::calc_filename(_base_filename)); file_helper_.open(FileNameCalc::calc_filename(base_filename_));
} }
protected: protected:
void _sink_it(const details::log_msg &msg) override void sink_it_(const details::log_msg &msg) override
{ {
if (std::chrono::system_clock::now() >= _rotation_tp) if (std::chrono::system_clock::now() >= rotation_tp_)
{ {
_file_helper.open(FileNameCalc::calc_filename(_base_filename)); file_helper_.open(FileNameCalc::calc_filename(base_filename_));
_rotation_tp = _next_rotation_tp(); rotation_tp_ = next_rotation_tp_();
} }
_file_helper.write(msg); file_helper_.write(msg);
} }
void _flush() override void flush_() override
{ {
_file_helper.flush(); file_helper_.flush();
} }
private: private:
std::chrono::system_clock::time_point _next_rotation_tp() std::chrono::system_clock::time_point next_rotation_tp_()
{ {
auto now = std::chrono::system_clock::now(); auto now = std::chrono::system_clock::now();
time_t tnow = std::chrono::system_clock::to_time_t(now); time_t tnow = std::chrono::system_clock::to_time_t(now);
tm date = spdlog::details::os::localtime(tnow); tm date = spdlog::details::os::localtime(tnow);
date.tm_hour = _rotation_h; date.tm_hour = rotation_h_;
date.tm_min = _rotation_m; date.tm_min = rotation_m_;
date.tm_sec = 0; date.tm_sec = 0;
auto rotation_time = std::chrono::system_clock::from_time_t(std::mktime(&date)); auto rotation_time = std::chrono::system_clock::from_time_t(std::mktime(&date));
if (rotation_time > now) if (rotation_time > now)
...@@ -108,11 +108,11 @@ private: ...@@ -108,11 +108,11 @@ private:
return {rotation_time + std::chrono::hours(24)}; return {rotation_time + std::chrono::hours(24)};
} }
filename_t _base_filename; filename_t base_filename_;
int _rotation_h; int rotation_h_;
int _rotation_m; int rotation_m_;
std::chrono::system_clock::time_point _rotation_tp; std::chrono::system_clock::time_point rotation_tp_;
details::file_helper _file_helper; details::file_helper file_helper_;
}; };
using daily_file_sink_mt = daily_file_sink<std::mutex>; using daily_file_sink_mt = daily_file_sink<std::mutex>;
......
...@@ -23,18 +23,18 @@ class dist_sink : public base_sink<Mutex> ...@@ -23,18 +23,18 @@ class dist_sink : public base_sink<Mutex>
{ {
public: public:
explicit dist_sink() explicit dist_sink()
: _sinks() : 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;
protected: protected:
std::vector<std::shared_ptr<sink>> _sinks; std::vector<std::shared_ptr<sink>> sinks_;
void _sink_it(const details::log_msg &msg) override void sink_it_(const details::log_msg &msg) override
{ {
for (auto &sink : _sinks) for (auto &sink : sinks_)
{ {
if (sink->should_log(msg.level)) if (sink->should_log(msg.level))
{ {
...@@ -43,23 +43,23 @@ protected: ...@@ -43,23 +43,23 @@ protected:
} }
} }
void _flush() override void flush_() override
{ {
for (auto &sink : _sinks) for (auto &sink : sinks_)
sink->flush(); sink->flush();
} }
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_);
_sinks.push_back(sink); sinks_.push_back(sink);
} }
void remove_sink(std::shared_ptr<sink> sink) void remove_sink(std::shared_ptr<sink> sink)
{ {
std::lock_guard<Mutex> lock(base_sink<Mutex>::_mutex); std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
_sinks.erase(std::remove(_sinks.begin(), _sinks.end(), sink), _sinks.end()); sinks_.erase(std::remove(sinks_.begin(), sinks_.end(), sink), sinks_.end());
} }
}; };
......
...@@ -27,12 +27,12 @@ public: ...@@ -27,12 +27,12 @@ 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
{ {
OutputDebugStringA(msg.formatted.c_str()); OutputDebugStringA(msg.formatted.c_str());
} }
void _flush() override {} void flush_() override {}
}; };
using msvc_sink_mt = msvc_sink<std::mutex>; using msvc_sink_mt = msvc_sink<std::mutex>;
......
...@@ -17,9 +17,9 @@ template<class Mutex> ...@@ -17,9 +17,9 @@ 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 {}
void _flush() override {} void flush_() override {}
}; };
using null_sink_mt = null_sink<details::null_mutex>; using null_sink_mt = null_sink<details::null_mutex>;
......
...@@ -18,28 +18,28 @@ class ostream_sink : public base_sink<Mutex> ...@@ -18,28 +18,28 @@ class ostream_sink : public base_sink<Mutex>
{ {
public: public:
explicit ostream_sink(std::ostream &os, bool force_flush = false) explicit ostream_sink(std::ostream &os, bool force_flush = false)
: _ostream(os) : ostream_(os)
, _force_flush(force_flush) , 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;
protected: protected:
void _sink_it(const details::log_msg &msg) override void sink_it_(const details::log_msg &msg) override
{ {
_ostream.write(msg.formatted.data(), msg.formatted.size()); ostream_.write(msg.formatted.data(), msg.formatted.size());
if (_force_flush) if (force_flush_)
_ostream.flush(); ostream_.flush();
} }
void _flush() override void flush_() override
{ {
_ostream.flush(); ostream_.flush();
} }
std::ostream &_ostream; std::ostream &ostream_;
bool _force_flush; bool force_flush_;
}; };
using ostream_sink_mt = ostream_sink<std::mutex>; using ostream_sink_mt = ostream_sink<std::mutex>;
......
...@@ -28,12 +28,12 @@ class rotating_file_sink SPDLOG_FINAL : public base_sink<Mutex> ...@@ -28,12 +28,12 @@ class rotating_file_sink SPDLOG_FINAL : public base_sink<Mutex>
{ {
public: public:
rotating_file_sink(filename_t base_filename, std::size_t max_size, std::size_t max_files) rotating_file_sink(filename_t base_filename, std::size_t max_size, std::size_t max_files)
: _base_filename(std::move(base_filename)) : base_filename_(std::move(base_filename))
, _max_size(max_size) , max_size_(max_size)
, _max_files(max_files) , max_files_(max_files)
{ {
_file_helper.open(calc_filename(_base_filename, 0)); file_helper_.open(calc_filename(base_filename_, 0));
_current_size = _file_helper.size(); // expensive. called only once current_size_ = file_helper_.size(); // expensive. called only once
} }
// calc filename according to index and file extension if exists. // calc filename according to index and file extension if exists.
...@@ -55,20 +55,20 @@ public: ...@@ -55,20 +55,20 @@ public:
} }
protected: protected:
void _sink_it(const details::log_msg &msg) override void sink_it_(const details::log_msg &msg) override
{ {
_current_size += msg.formatted.size(); current_size_ += msg.formatted.size();
if (_current_size > _max_size) if (current_size_ > max_size_)
{ {
_rotate(); rotate_();
_current_size = msg.formatted.size(); current_size_ = msg.formatted.size();
} }
_file_helper.write(msg); file_helper_.write(msg);
} }
void _flush() override void flush_() override
{ {
_file_helper.flush(); file_helper_.flush();
} }
private: private:
...@@ -77,14 +77,14 @@ private: ...@@ -77,14 +77,14 @@ private:
// log.1.txt -> log.2.txt // log.1.txt -> log.2.txt
// log.2.txt -> log.3.txt // log.2.txt -> log.3.txt
// log.3.txt -> delete // log.3.txt -> delete
void _rotate() void rotate_()
{ {
using details::os::filename_to_str; using details::os::filename_to_str;
_file_helper.close(); file_helper_.close();
for (auto i = _max_files; i > 0; --i) for (auto i = max_files_; i > 0; --i)
{ {
filename_t src = calc_filename(_base_filename, i - 1); filename_t src = calc_filename(base_filename_, i - 1);
filename_t target = calc_filename(_base_filename, i); filename_t target = calc_filename(base_filename_, i);
if (details::file_helper::file_exists(target)) if (details::file_helper::file_exists(target))
{ {
...@@ -98,14 +98,14 @@ private: ...@@ -98,14 +98,14 @@ private:
throw spdlog_ex("rotating_file_sink: failed renaming " + filename_to_str(src) + " to " + filename_to_str(target), errno); throw spdlog_ex("rotating_file_sink: failed renaming " + filename_to_str(src) + " to " + filename_to_str(target), errno);
} }
} }
_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_;
std::size_t _current_size; std::size_t current_size_;
details::file_helper _file_helper; details::file_helper file_helper_;
}; };
using rotating_file_sink_mt = rotating_file_sink<std::mutex>; using rotating_file_sink_mt = rotating_file_sink<std::mutex>;
......
...@@ -22,34 +22,34 @@ class simple_file_sink SPDLOG_FINAL : public base_sink<Mutex> ...@@ -22,34 +22,34 @@ class simple_file_sink SPDLOG_FINAL : public base_sink<Mutex>
{ {
public: public:
explicit simple_file_sink(const filename_t &filename, bool truncate = false) explicit simple_file_sink(const filename_t &filename, bool truncate = false)
: _force_flush(false) : force_flush_(false)
{ {
_file_helper.open(filename, truncate); file_helper_.open(filename, truncate);
} }
void set_force_flush(bool force_flush) void set_force_flush(bool force_flush)
{ {
_force_flush = force_flush; force_flush_ = force_flush;
} }
protected: protected:
void _sink_it(const details::log_msg &msg) override void sink_it_(const details::log_msg &msg) override
{ {
_file_helper.write(msg); file_helper_.write(msg);
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_;
}; };
using simple_file_sink_mt = simple_file_sink<std::mutex>; using simple_file_sink_mt = simple_file_sink<std::mutex>;
......
...@@ -22,22 +22,22 @@ public: ...@@ -22,22 +22,22 @@ public:
level::level_enum level() const; level::level_enum level() const;
private: private:
level_t _level{level::trace}; level_t level_{level::trace};
}; };
inline bool sink::should_log(level::level_enum msg_level) const inline bool sink::should_log(level::level_enum msg_level) const
{ {
return msg_level >= _level.load(std::memory_order_relaxed); return msg_level >= level_.load(std::memory_order_relaxed);
} }
inline void sink::set_level(level::level_enum log_level) inline void sink::set_level(level::level_enum log_level)
{ {
_level.store(log_level); level_.store(log_level);
} }
inline level::level_enum sink::level() const inline level::level_enum sink::level() const
{ {
return static_cast<spdlog::level::level_enum>(_level.load(std::memory_order_relaxed)); return static_cast<spdlog::level::level_enum>(level_.load(std::memory_order_relaxed));
} }
} // namespace sinks } // namespace sinks
......
...@@ -23,8 +23,8 @@ class stdout_sink : public sink ...@@ -23,8 +23,8 @@ class stdout_sink : public sink
public: public:
using mutex_t = typename ConsoleMutexTrait::mutex_t; using mutex_t = typename ConsoleMutexTrait::mutex_t;
stdout_sink() stdout_sink()
: _mutex(ConsoleMutexTrait::console_mutex()) : mutex_(ConsoleMutexTrait::console_mutex())
, _file(StdoutTrait::stream()) , file_(StdoutTrait::stream())
{ {
} }
~stdout_sink() = default; ~stdout_sink() = default;
...@@ -34,20 +34,20 @@ public: ...@@ -34,20 +34,20 @@ public:
void log(const details::log_msg &msg) override void log(const details::log_msg &msg) override
{ {
std::lock_guard<mutex_t> lock(_mutex); std::lock_guard<mutex_t> lock(mutex_);
fwrite(msg.formatted.data(), sizeof(char), msg.formatted.size(), _file); fwrite(msg.formatted.data(), sizeof(char), msg.formatted.size(), file_);
fflush(StdoutTrait::stream()); fflush(StdoutTrait::stream());
} }
void flush() override void flush() override
{ {
std::lock_guard<mutex_t> lock(_mutex); std::lock_guard<mutex_t> lock(mutex_);
fflush(StdoutTrait::stream()); fflush(StdoutTrait::stream());
} }
private: private:
mutex_t &_mutex; mutex_t &mutex_;
FILE *_file; FILE *file_;
}; };
using stdout_sink_mt = stdout_sink<details::console_stdout_trait, details::console_mutex_trait>; using stdout_sink_mt = stdout_sink<details::console_stdout_trait, details::console_mutex_trait>;
......
...@@ -26,18 +26,18 @@ class syslog_sink : public sink ...@@ -26,18 +26,18 @@ class syslog_sink : public sink
public: public:
// //
syslog_sink(const std::string &ident = "", int syslog_option = 0, int syslog_facility = LOG_USER) syslog_sink(const std::string &ident = "", int syslog_option = 0, int syslog_facility = LOG_USER)
: _ident(ident) : ident_(ident)
{ {
_priorities[static_cast<size_t>(level::trace)] = LOG_DEBUG; priorities_[static_cast<size_t>(level::trace)] = LOG_DEBUG;
_priorities[static_cast<size_t>(level::debug)] = LOG_DEBUG; priorities_[static_cast<size_t>(level::debug)] = LOG_DEBUG;
_priorities[static_cast<size_t>(level::info)] = LOG_INFO; priorities_[static_cast<size_t>(level::info)] = LOG_INFO;
_priorities[static_cast<size_t>(level::warn)] = LOG_WARNING; priorities_[static_cast<size_t>(level::warn)] = LOG_WARNING;
_priorities[static_cast<size_t>(level::err)] = LOG_ERR; priorities_[static_cast<size_t>(level::err)] = LOG_ERR;
_priorities[static_cast<size_t>(level::critical)] = LOG_CRIT; priorities_[static_cast<size_t>(level::critical)] = LOG_CRIT;
_priorities[static_cast<size_t>(level::off)] = LOG_INFO; priorities_[static_cast<size_t>(level::off)] = LOG_INFO;
// 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() override ~syslog_sink() override
...@@ -56,16 +56,16 @@ public: ...@@ -56,16 +56,16 @@ public:
void flush() override {} void flush() override {}
private: private:
std::array<int, 7> _priorities; std::array<int, 7> priorities_;
// must store the ident because the man says openlog might use the pointer as is and not a string copy // must store the ident because the man says openlog might use the pointer as is and not a string copy
const std::string _ident; const std::string ident_;
// //
// Simply maps spdlog's log level to syslog priority level. // Simply maps spdlog's log level to syslog priority level.
// //
int syslog_prio_from_level(const details::log_msg &msg) const int syslog_prio_from_level(const details::log_msg &msg) const
{ {
return _priorities[static_cast<size_t>(msg.level)]; return priorities_[static_cast<size_t>(msg.level)];
} }
}; };
} // namespace sinks } // namespace sinks
......
...@@ -34,7 +34,7 @@ public: ...@@ -34,7 +34,7 @@ public:
wincolor_sink() wincolor_sink()
: out_handle_(HandleTrait::handle()) : out_handle_(HandleTrait::handle())
, _mutex(ConsoleMutexTrait::console_mutex()) , mutex_(ConsoleMutexTrait::console_mutex())
{ {
colors_[level::trace] = WHITE; colors_[level::trace] = WHITE;
colors_[level::debug] = CYAN; colors_[level::debug] = CYAN;
...@@ -56,29 +56,29 @@ public: ...@@ -56,29 +56,29 @@ public:
// change the color for the given level // change the color for the given level
void set_color(level::level_enum level, WORD color) void set_color(level::level_enum level, WORD color)
{ {
std::lock_guard<mutex_t> lock(_mutex); std::lock_guard<mutex_t> lock(mutex_);
colors_[level] = color; colors_[level] = color;
} }
void log(const details::log_msg &msg) SPDLOG_FINAL override void log(const details::log_msg &msg) SPDLOG_FINAL override
{ {
std::lock_guard<mutex_t> lock(_mutex); std::lock_guard<mutex_t> lock(mutex_);
if (msg.color_range_end > msg.color_range_start) if (msg.color_range_end > msg.color_range_start)
{ {
// before color range // before color range
_print_range(msg, 0, msg.color_range_start); print_range_(msg, 0, msg.color_range_start);
// in color range // in color range
auto orig_attribs = set_console_attribs(colors_[msg.level]); auto orig_attribs = set_console_attribs(colors_[msg.level]);
_print_range(msg, msg.color_range_start, msg.color_range_end); print_range_(msg, msg.color_range_start, msg.color_range_end);
::SetConsoleTextAttribute(out_handle_, orig_attribs); // reset to orig colors ::SetConsoleTextAttribute(out_handle_, orig_attribs); // reset to orig colors
// after color range // after color range
_print_range(msg, msg.color_range_end, msg.formatted.size()); print_range_(msg, msg.color_range_end, msg.formatted.size());
} }
else // print without colors if color range is invalid else // print without colors if color range is invalid
{ {
_print_range(msg, 0, msg.formatted.size()); print_range_(msg, 0, msg.formatted.size());
} }
} }
...@@ -103,14 +103,14 @@ private: ...@@ -103,14 +103,14 @@ private:
} }
// print a range of formatted message to console // print a range of formatted message to console
void _print_range(const details::log_msg &msg, size_t start, size_t end) void print_range_(const details::log_msg &msg, size_t start, size_t end)
{ {
auto size = static_cast<DWORD>(end - start); auto size = static_cast<DWORD>(end - start);
::WriteConsoleA(out_handle_, msg.formatted.data() + start, size, nullptr, nullptr); ::WriteConsoleA(out_handle_, msg.formatted.data() + start, size, nullptr, nullptr);
} }
HANDLE out_handle_; HANDLE out_handle_;
mutex_t &_mutex; mutex_t &mutex_;
std::unordered_map<level::level_enum, WORD, level::level_hasher> colors_; std::unordered_map<level::level_enum, WORD, level::level_hasher> colors_;
}; };
......
...@@ -35,13 +35,13 @@ public: ...@@ -35,13 +35,13 @@ public:
} }
protected: protected:
void _sink_it(const details::log_msg &) override void sink_it_(const details::log_msg &) override
{ {
msg_counter_++; msg_counter_++;
std::this_thread::sleep_for(delay_); std::this_thread::sleep_for(delay_);
} }
void _flush() override void flush_() override
{ {
flush_counter_++; flush_counter_++;
} }
......
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