use underscore at end of private members names

This commit is contained in:
gabime 2018-05-26 19:21:20 +03:00
parent 72506b3bab
commit cfbc8e52ba

View File

@ -34,107 +34,107 @@ public:
void register_logger(std::shared_ptr<logger> new_logger) void register_logger(std::shared_ptr<logger> new_logger)
{ {
std::lock_guard<Mutex> lock(_mutex); std::lock_guard<Mutex> lock(mutex_);
auto logger_name = new_logger->name(); auto logger_name = new_logger->name();
throw_if_exists(logger_name); throw_if_exists(logger_name);
_loggers[logger_name] = new_logger; loggers_[logger_name] = new_logger;
} }
void register_and_init(std::shared_ptr<logger> new_logger) void register_and_init(std::shared_ptr<logger> new_logger)
{ {
std::lock_guard<Mutex> lock(_mutex); std::lock_guard<Mutex> lock(mutex_);
auto logger_name = new_logger->name(); auto logger_name = new_logger->name();
throw_if_exists(logger_name); throw_if_exists(logger_name);
if (_formatter) if (formatter_)
{ {
new_logger->set_formatter(_formatter); new_logger->set_formatter(formatter_);
} }
if (_err_handler) if (err_handler_)
{ {
new_logger->set_error_handler(_err_handler); new_logger->set_error_handler(err_handler_);
} }
new_logger->set_level(_level); new_logger->set_level(level_);
new_logger->flush_on(_flush_level); new_logger->flush_on(flush_level_);
// Add to registry // Add to registry
_loggers[logger_name] = new_logger; loggers_[logger_name] = new_logger;
} }
std::shared_ptr<logger> get(const std::string &logger_name) std::shared_ptr<logger> get(const std::string &logger_name)
{ {
std::lock_guard<Mutex> lock(_mutex); std::lock_guard<Mutex> lock(mutex_);
auto found = _loggers.find(logger_name); auto found = loggers_.find(logger_name);
return found == _loggers.end() ? nullptr : found->second; return found == loggers_.end() ? nullptr : found->second;
} }
void set_thread_pool(std::shared_ptr<thread_pool> tp) void set_thread_pool(std::shared_ptr<thread_pool> tp)
{ {
std::lock_guard<Mutex> lock(_mutex); std::lock_guard<Mutex> lock(mutex_);
_tp = std::move(tp); tp_ = std::move(tp);
} }
std::shared_ptr<thread_pool> get_thread_pool() std::shared_ptr<thread_pool> get_thread_pool()
{ {
std::lock_guard<Mutex> lock(_mutex); std::lock_guard<Mutex> lock(mutex_);
return _tp; return tp_;
} }
void set_formatter(formatter_ptr f) void set_formatter(formatter_ptr f)
{ {
std::lock_guard<Mutex> lock(_mutex); std::lock_guard<Mutex> lock(mutex_);
_formatter = f; formatter_ = f;
for (auto &l : _loggers) for (auto &l : loggers_)
{ {
l.second->set_formatter(_formatter); l.second->set_formatter(formatter_);
} }
} }
void set_pattern(const std::string &pattern) void set_pattern(const std::string &pattern)
{ {
std::lock_guard<Mutex> lock(_mutex); std::lock_guard<Mutex> lock(mutex_);
_formatter = std::make_shared<pattern_formatter>(pattern); formatter_ = std::make_shared<pattern_formatter>(pattern);
for (auto &l : _loggers) for (auto &l : loggers_)
{ {
l.second->set_formatter(_formatter); l.second->set_formatter(formatter_);
} }
} }
void set_level(level::level_enum log_level) void set_level(level::level_enum log_level)
{ {
std::lock_guard<Mutex> lock(_mutex); std::lock_guard<Mutex> lock(mutex_);
for (auto &l : _loggers) for (auto &l : loggers_)
{ {
l.second->set_level(log_level); l.second->set_level(log_level);
} }
_level = log_level; level_ = log_level;
} }
void flush_on(level::level_enum log_level) void flush_on(level::level_enum log_level)
{ {
std::lock_guard<Mutex> lock(_mutex); std::lock_guard<Mutex> lock(mutex_);
for (auto &l : _loggers) for (auto &l : loggers_)
{ {
l.second->flush_on(log_level); l.second->flush_on(log_level);
} }
_flush_level = log_level; flush_level_ = log_level;
} }
void set_error_handler(log_err_handler handler) void set_error_handler(log_err_handler handler)
{ {
for (auto &l : _loggers) for (auto &l : loggers_)
{ {
l.second->set_error_handler(handler); l.second->set_error_handler(handler);
} }
_err_handler = handler; err_handler_ = handler;
} }
void apply_all(std::function<void(std::shared_ptr<logger>)> fun) void apply_all(std::function<void(std::shared_ptr<logger>)> fun)
{ {
std::lock_guard<Mutex> lock(_mutex); std::lock_guard<Mutex> lock(mutex_);
for (auto &l : _loggers) for (auto &l : loggers_)
{ {
fun(l.second); fun(l.second);
} }
@ -142,26 +142,26 @@ public:
void drop(const std::string &logger_name) void drop(const std::string &logger_name)
{ {
std::lock_guard<Mutex> lock(_mutex); std::lock_guard<Mutex> lock(mutex_);
_loggers.erase(logger_name); loggers_.erase(logger_name);
} }
void drop_all() void drop_all()
{ {
{ {
std::lock_guard<Mutex> lock(_mutex); std::lock_guard<Mutex> lock(mutex_);
_loggers.clear(); loggers_.clear();
} }
{ {
std::lock_guard<Mutex> lock(_tp_mutex); std::lock_guard<Mutex> lock(tp_mutex_);
_tp.reset(); tp_.reset();
} }
} }
Mutex &tp_mutex() Mutex &tp_mutex()
{ {
return _tp_mutex; return tp_mutex_;
} }
static registry_t<Mutex> &instance() static registry_t<Mutex> &instance()
@ -175,20 +175,20 @@ private:
void throw_if_exists(const std::string &logger_name) void throw_if_exists(const std::string &logger_name)
{ {
if (_loggers.find(logger_name) != _loggers.end()) if (loggers_.find(logger_name) != loggers_.end())
{ {
throw spdlog_ex("logger with name '" + logger_name + "' already exists"); throw spdlog_ex("logger with name '" + logger_name + "' already exists");
} }
} }
Mutex _mutex; Mutex mutex_;
Mutex _tp_mutex; Mutex tp_mutex_;
std::unordered_map<std::string, std::shared_ptr<logger>> _loggers; std::unordered_map<std::string, std::shared_ptr<logger>> loggers_;
formatter_ptr _formatter; formatter_ptr formatter_;
level::level_enum _level = level::info; level::level_enum level_ = level::info;
level::level_enum _flush_level = level::off; level::level_enum flush_level_ = level::off;
log_err_handler _err_handler; log_err_handler err_handler_;
std::shared_ptr<thread_pool> _tp; std::shared_ptr<thread_pool> tp_;
}; };
#ifdef SPDLOG_NO_REGISTRY_MUTEX #ifdef SPDLOG_NO_REGISTRY_MUTEX