Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
spdlog::details::registry Class Reference

#include <registry.h>

Public Member Functions

 registry (const registry &)=delete
 
registryoperator= (const registry &)=delete
 
void register_logger (std::shared_ptr< logger > new_logger)
 
void initialize_logger (std::shared_ptr< logger > new_logger)
 
std::shared_ptr< loggerget (const std::string &logger_name)
 
std::shared_ptr< loggerdefault_logger ()
 
loggerget_default_raw ()
 
void set_default_logger (std::shared_ptr< logger > new_default_logger)
 
void set_tp (std::shared_ptr< thread_pool > tp)
 
std::shared_ptr< thread_poolget_tp ()
 
void set_formatter (std::unique_ptr< formatter > formatter)
 
void set_level (level::level_enum log_level)
 
void flush_on (level::level_enum log_level)
 
void flush_every (std::chrono::seconds interval)
 
void set_error_handler (log_err_handler handler)
 
void apply_all (const std::function< void(const std::shared_ptr< logger >)> &fun)
 
void flush_all ()
 
void drop (const std::string &logger_name)
 
void drop_all ()
 
void shutdown ()
 
std::recursive_mutex & tp_mutex ()
 
void set_automatic_registration (bool automatic_regsistration)
 

Static Public Member Functions

static registryinstance ()
 

Private Member Functions

 registry ()
 
 ~registry ()=default
 
void throw_if_exists_ (const std::string &logger_name)
 
void register_logger_ (std::shared_ptr< logger > new_logger)
 

Private Attributes

std::mutex logger_map_mutex_
 
std::mutex flusher_mutex_
 
std::recursive_mutex tp_mutex_
 
std::unordered_map< std::string, std::shared_ptr< logger > > loggers_
 
std::unique_ptr< formatterformatter_
 
level::level_enum level_ = spdlog::logger::default_level()
 
level::level_enum flush_level_ = level::off
 
log_err_handler err_handler_
 
std::shared_ptr< thread_pooltp_
 
std::unique_ptr< periodic_workerperiodic_flusher_
 
std::shared_ptr< loggerdefault_logger_
 
bool automatic_registration_ = true
 

Detailed Description

Definition at line 36 of file registry.h.

Constructor & Destructor Documentation

spdlog::details::registry::registry ( const registry )
delete
spdlog::details::registry::registry ( )
inlineprivate

Definition at line 235 of file registry.h.

236  : formatter_(new pattern_formatter())
237  {
238 
239 #ifndef SPDLOG_DISABLE_DEFAULT_LOGGER
240  // create default logger (ansicolor_stdout_sink_mt or wincolor_stdout_sink_mt in windows).
241 #ifdef _WIN32
242  auto color_sink = std::make_shared<sinks::wincolor_stdout_sink_mt>();
243 #else
244  auto color_sink = std::make_shared<sinks::ansicolor_stdout_sink_mt>();
245 #endif
246 
247  const char *default_logger_name = "";
248  default_logger_ = std::make_shared<spdlog::logger>(default_logger_name, std::move(color_sink));
249  loggers_[default_logger_name] = default_logger_;
250 
251 #endif // SPDLOG_DISABLE_DEFAULT_LOGGER
252  }
std::shared_ptr< logger > default_logger_
Definition: registry.h:280
std::unordered_map< std::string, std::shared_ptr< logger > > loggers_
Definition: registry.h:273
def move(depos, offset)
Definition: depos.py:107
std::unique_ptr< formatter > formatter_
Definition: registry.h:274
spdlog::details::registry::~registry ( )
privatedefault

Member Function Documentation

void spdlog::details::registry::apply_all ( const std::function< void(const std::shared_ptr< logger >)> &  fun)
inline

Definition at line 166 of file registry.h.

167  {
168  std::lock_guard<std::mutex> lock(logger_map_mutex_);
169  for (auto &l : loggers_)
170  {
171  fun(l.second);
172  }
173  }
std::unordered_map< std::string, std::shared_ptr< logger > > loggers_
Definition: registry.h:273
static QStrList * l
Definition: config.cpp:1044
std::mutex logger_map_mutex_
Definition: registry.h:271
std::shared_ptr<logger> spdlog::details::registry::default_logger ( )
inline

Definition at line 74 of file registry.h.

75  {
76  std::lock_guard<std::mutex> lock(logger_map_mutex_);
77  return default_logger_;
78  }
std::shared_ptr< logger > default_logger_
Definition: registry.h:280
std::mutex logger_map_mutex_
Definition: registry.h:271
void spdlog::details::registry::drop ( const std::string logger_name)
inline

Definition at line 184 of file registry.h.

185  {
186  std::lock_guard<std::mutex> lock(logger_map_mutex_);
187  loggers_.erase(logger_name);
188  if (default_logger_ && default_logger_->name() == logger_name)
189  {
190  default_logger_.reset();
191  }
192  }
std::shared_ptr< logger > default_logger_
Definition: registry.h:280
std::unordered_map< std::string, std::shared_ptr< logger > > loggers_
Definition: registry.h:273
std::mutex logger_map_mutex_
Definition: registry.h:271
void spdlog::details::registry::drop_all ( )
inline

Definition at line 194 of file registry.h.

195  {
196  std::lock_guard<std::mutex> lock(logger_map_mutex_);
197  loggers_.clear();
198  default_logger_.reset();
199  }
std::shared_ptr< logger > default_logger_
Definition: registry.h:280
std::unordered_map< std::string, std::shared_ptr< logger > > loggers_
Definition: registry.h:273
std::mutex logger_map_mutex_
Definition: registry.h:271
void spdlog::details::registry::flush_all ( )
inline

Definition at line 175 of file registry.h.

176  {
177  std::lock_guard<std::mutex> lock(logger_map_mutex_);
178  for (auto &l : loggers_)
179  {
180  l.second->flush();
181  }
182  }
std::unordered_map< std::string, std::shared_ptr< logger > > loggers_
Definition: registry.h:273
static QStrList * l
Definition: config.cpp:1044
std::mutex logger_map_mutex_
Definition: registry.h:271
void spdlog::details::registry::flush_every ( std::chrono::seconds  interval)
inline

Definition at line 149 of file registry.h.

150  {
151  std::lock_guard<std::mutex> lock(flusher_mutex_);
152  std::function<void()> clbk = std::bind(&registry::flush_all, this);
153  periodic_flusher_ = details::make_unique<periodic_worker>(clbk, interval);
154  }
std::unique_ptr< periodic_worker > periodic_flusher_
Definition: registry.h:279
std::mutex flusher_mutex_
Definition: registry.h:271
void spdlog::details::registry::flush_on ( level::level_enum  log_level)
inline

Definition at line 139 of file registry.h.

140  {
141  std::lock_guard<std::mutex> lock(logger_map_mutex_);
142  for (auto &l : loggers_)
143  {
144  l.second->flush_on(log_level);
145  }
146  flush_level_ = log_level;
147  }
std::unordered_map< std::string, std::shared_ptr< logger > > loggers_
Definition: registry.h:273
level::level_enum flush_level_
Definition: registry.h:276
static QStrList * l
Definition: config.cpp:1044
std::mutex logger_map_mutex_
Definition: registry.h:271
std::shared_ptr<logger> spdlog::details::registry::get ( const std::string logger_name)
inline

Definition at line 67 of file registry.h.

68  {
69  std::lock_guard<std::mutex> lock(logger_map_mutex_);
70  auto found = loggers_.find(logger_name);
71  return found == loggers_.end() ? nullptr : found->second;
72  }
std::unordered_map< std::string, std::shared_ptr< logger > > loggers_
Definition: registry.h:273
std::mutex logger_map_mutex_
Definition: registry.h:271
logger* spdlog::details::registry::get_default_raw ( )
inline

Definition at line 84 of file registry.h.

85  {
86  return default_logger_.get();
87  }
std::shared_ptr< logger > default_logger_
Definition: registry.h:280
std::shared_ptr<thread_pool> spdlog::details::registry::get_tp ( )
inline

Definition at line 112 of file registry.h.

113  {
114  std::lock_guard<std::recursive_mutex> lock(tp_mutex_);
115  return tp_;
116  }
std::recursive_mutex tp_mutex_
Definition: registry.h:272
std::shared_ptr< thread_pool > tp_
Definition: registry.h:278
void spdlog::details::registry::initialize_logger ( std::shared_ptr< logger new_logger)
inline

Definition at line 48 of file registry.h.

49  {
50  std::lock_guard<std::mutex> lock(logger_map_mutex_);
51  new_logger->set_formatter(formatter_->clone());
52 
53  if (err_handler_)
54  {
55  new_logger->set_error_handler(err_handler_);
56  }
57 
58  new_logger->set_level(level_);
59  new_logger->flush_on(flush_level_);
60 
62  {
63  register_logger_(std::move(new_logger));
64  }
65  }
level::level_enum flush_level_
Definition: registry.h:276
level::level_enum level_
Definition: registry.h:275
log_err_handler err_handler_
Definition: registry.h:277
std::mutex logger_map_mutex_
Definition: registry.h:271
def move(depos, offset)
Definition: depos.py:107
std::unique_ptr< formatter > formatter_
Definition: registry.h:274
void register_logger_(std::shared_ptr< logger > new_logger)
Definition: registry.h:264
static registry& spdlog::details::registry::instance ( )
inlinestatic

Definition at line 228 of file registry.h.

229  {
230  static registry s_instance;
231  return s_instance;
232  }
registry& spdlog::details::registry::operator= ( const registry )
delete
void spdlog::details::registry::register_logger ( std::shared_ptr< logger new_logger)
inline

Definition at line 42 of file registry.h.

43  {
44  std::lock_guard<std::mutex> lock(logger_map_mutex_);
45  register_logger_(std::move(new_logger));
46  }
std::mutex logger_map_mutex_
Definition: registry.h:271
def move(depos, offset)
Definition: depos.py:107
void register_logger_(std::shared_ptr< logger > new_logger)
Definition: registry.h:264
void spdlog::details::registry::register_logger_ ( std::shared_ptr< logger new_logger)
inlineprivate

Definition at line 264 of file registry.h.

265  {
266  auto logger_name = new_logger->name();
267  throw_if_exists_(logger_name);
268  loggers_[logger_name] = std::move(new_logger);
269  }
std::unordered_map< std::string, std::shared_ptr< logger > > loggers_
Definition: registry.h:273
void throw_if_exists_(const std::string &logger_name)
Definition: registry.h:256
def move(depos, offset)
Definition: depos.py:107
void spdlog::details::registry::set_automatic_registration ( bool  automatic_regsistration)
inline

Definition at line 222 of file registry.h.

223  {
224  std::lock_guard<std::mutex> lock(logger_map_mutex_);
225  automatic_registration_ = automatic_regsistration;
226  }
std::mutex logger_map_mutex_
Definition: registry.h:271
void spdlog::details::registry::set_default_logger ( std::shared_ptr< logger new_default_logger)
inline

Definition at line 91 of file registry.h.

92  {
93  std::lock_guard<std::mutex> lock(logger_map_mutex_);
94  // remove previous default logger from the map
95  if (default_logger_ != nullptr)
96  {
97  loggers_.erase(default_logger_->name());
98  }
99  if (new_default_logger != nullptr)
100  {
101  loggers_[new_default_logger->name()] = new_default_logger;
102  }
103  default_logger_ = std::move(new_default_logger);
104  }
std::shared_ptr< logger > default_logger_
Definition: registry.h:280
std::unordered_map< std::string, std::shared_ptr< logger > > loggers_
Definition: registry.h:273
std::mutex logger_map_mutex_
Definition: registry.h:271
def move(depos, offset)
Definition: depos.py:107
void spdlog::details::registry::set_error_handler ( log_err_handler  handler)
inline

Definition at line 156 of file registry.h.

157  {
158  std::lock_guard<std::mutex> lock(logger_map_mutex_);
159  for (auto &l : loggers_)
160  {
161  l.second->set_error_handler(handler);
162  }
164  }
std::unordered_map< std::string, std::shared_ptr< logger > > loggers_
Definition: registry.h:273
log_err_handler err_handler_
Definition: registry.h:277
static QStrList * l
Definition: config.cpp:1044
std::mutex logger_map_mutex_
Definition: registry.h:271
static msg_handler handler
Definition: qglobal.cpp:234
void spdlog::details::registry::set_formatter ( std::unique_ptr< formatter formatter)
inline

Definition at line 119 of file registry.h.

120  {
121  std::lock_guard<std::mutex> lock(logger_map_mutex_);
122  formatter_ = std::move(formatter);
123  for (auto &l : loggers_)
124  {
125  l.second->set_formatter(formatter_->clone());
126  }
127  }
std::unordered_map< std::string, std::shared_ptr< logger > > loggers_
Definition: registry.h:273
static QStrList * l
Definition: config.cpp:1044
std::mutex logger_map_mutex_
Definition: registry.h:271
def move(depos, offset)
Definition: depos.py:107
std::unique_ptr< formatter > formatter_
Definition: registry.h:274
void spdlog::details::registry::set_level ( level::level_enum  log_level)
inline

Definition at line 129 of file registry.h.

130  {
131  std::lock_guard<std::mutex> lock(logger_map_mutex_);
132  for (auto &l : loggers_)
133  {
134  l.second->set_level(log_level);
135  }
136  level_ = log_level;
137  }
std::unordered_map< std::string, std::shared_ptr< logger > > loggers_
Definition: registry.h:273
level::level_enum level_
Definition: registry.h:275
static QStrList * l
Definition: config.cpp:1044
std::mutex logger_map_mutex_
Definition: registry.h:271
void spdlog::details::registry::set_tp ( std::shared_ptr< thread_pool tp)
inline

Definition at line 106 of file registry.h.

107  {
108  std::lock_guard<std::recursive_mutex> lock(tp_mutex_);
109  tp_ = std::move(tp);
110  }
std::recursive_mutex tp_mutex_
Definition: registry.h:272
std::shared_ptr< thread_pool > tp_
Definition: registry.h:278
def move(depos, offset)
Definition: depos.py:107
void spdlog::details::registry::shutdown ( )
inline

Definition at line 202 of file registry.h.

203  {
204  {
205  std::lock_guard<std::mutex> lock(flusher_mutex_);
206  periodic_flusher_.reset();
207  }
208 
209  drop_all();
210 
211  {
212  std::lock_guard<std::recursive_mutex> lock(tp_mutex_);
213  tp_.reset();
214  }
215  }
std::recursive_mutex tp_mutex_
Definition: registry.h:272
std::shared_ptr< thread_pool > tp_
Definition: registry.h:278
std::unique_ptr< periodic_worker > periodic_flusher_
Definition: registry.h:279
std::mutex flusher_mutex_
Definition: registry.h:271
void spdlog::details::registry::throw_if_exists_ ( const std::string logger_name)
inlineprivate

Definition at line 256 of file registry.h.

257  {
258  if (loggers_.find(logger_name) != loggers_.end())
259  {
260  throw spdlog_ex("logger with name '" + logger_name + "' already exists");
261  }
262  }
std::unordered_map< std::string, std::shared_ptr< logger > > loggers_
Definition: registry.h:273
std::recursive_mutex& spdlog::details::registry::tp_mutex ( )
inline

Definition at line 217 of file registry.h.

218  {
219  return tp_mutex_;
220  }
std::recursive_mutex tp_mutex_
Definition: registry.h:272

Member Data Documentation

bool spdlog::details::registry::automatic_registration_ = true
private

Definition at line 281 of file registry.h.

std::shared_ptr<logger> spdlog::details::registry::default_logger_
private

Definition at line 280 of file registry.h.

log_err_handler spdlog::details::registry::err_handler_
private

Definition at line 277 of file registry.h.

level::level_enum spdlog::details::registry::flush_level_ = level::off
private

Definition at line 276 of file registry.h.

std::mutex spdlog::details::registry::flusher_mutex_
private

Definition at line 271 of file registry.h.

std::unique_ptr<formatter> spdlog::details::registry::formatter_
private

Definition at line 274 of file registry.h.

level::level_enum spdlog::details::registry::level_ = spdlog::logger::default_level()
private

Definition at line 275 of file registry.h.

std::mutex spdlog::details::registry::logger_map_mutex_
private

Definition at line 271 of file registry.h.

std::unordered_map<std::string, std::shared_ptr<logger> > spdlog::details::registry::loggers_
private

Definition at line 273 of file registry.h.

std::unique_ptr<periodic_worker> spdlog::details::registry::periodic_flusher_
private

Definition at line 279 of file registry.h.

std::shared_ptr<thread_pool> spdlog::details::registry::tp_
private

Definition at line 278 of file registry.h.

std::recursive_mutex spdlog::details::registry::tp_mutex_
private

Definition at line 272 of file registry.h.


The documentation for this class was generated from the following file: