mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-28 00:10:21 +08:00
Added registry::set_instance() and shared_instance()
This commit is contained in:
parent
fceb33fa86
commit
8af91bcda0
@ -26,10 +26,27 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
|
||||||
namespace spdlog {
|
namespace spdlog {
|
||||||
namespace details {
|
namespace details {
|
||||||
|
|
||||||
|
|
||||||
|
SPDLOG_INLINE static std::shared_ptr<registry> s_instance = std::make_shared<registry>();
|
||||||
|
|
||||||
|
SPDLOG_INLINE registry ®istry::instance() {
|
||||||
|
return *s_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
SPDLOG_INLINE std::shared_ptr<registry> registry::shared_instance() {
|
||||||
|
return s_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
SPDLOG_INLINE void registry::set_instance(std::shared_ptr<registry> instance) {
|
||||||
|
s_instance = instance;
|
||||||
|
}
|
||||||
|
|
||||||
SPDLOG_INLINE registry::registry()
|
SPDLOG_INLINE registry::registry()
|
||||||
: formatter_(new pattern_formatter()) {
|
: formatter_(new pattern_formatter()) {
|
||||||
#ifndef SPDLOG_DISABLE_DEFAULT_LOGGER
|
#ifndef SPDLOG_DISABLE_DEFAULT_LOGGER
|
||||||
@ -233,10 +250,6 @@ SPDLOG_INLINE void registry::set_levels(log_levels levels, level::level_enum *gl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SPDLOG_INLINE registry ®istry::instance() {
|
|
||||||
static registry s_instance;
|
|
||||||
return s_instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
SPDLOG_INLINE void registry::apply_logger_env_levels(std::shared_ptr<logger> new_logger) {
|
SPDLOG_INLINE void registry::apply_logger_env_levels(std::shared_ptr<logger> new_logger) {
|
||||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||||
|
@ -26,6 +26,9 @@ class thread_pool;
|
|||||||
|
|
||||||
class SPDLOG_API registry {
|
class SPDLOG_API registry {
|
||||||
public:
|
public:
|
||||||
|
registry();
|
||||||
|
~registry();
|
||||||
|
|
||||||
using log_levels = std::unordered_map<std::string, level::level_enum>;
|
using log_levels = std::unordered_map<std::string, level::level_enum>;
|
||||||
registry(const registry &) = delete;
|
registry(const registry &) = delete;
|
||||||
registry &operator=(const registry &) = delete;
|
registry &operator=(const registry &) = delete;
|
||||||
@ -95,16 +98,15 @@ public:
|
|||||||
// set levels for all existing/future loggers. global_level can be null if should not set.
|
// set levels for all existing/future loggers. global_level can be null if should not set.
|
||||||
void set_levels(log_levels levels, level::level_enum *global_level);
|
void set_levels(log_levels levels, level::level_enum *global_level);
|
||||||
|
|
||||||
|
static void set_instance(std::shared_ptr<registry> instance);
|
||||||
static registry &instance();
|
static registry &instance();
|
||||||
|
static std::shared_ptr<registry> shared_instance();
|
||||||
|
|
||||||
void apply_logger_env_levels(std::shared_ptr<logger> new_logger);
|
void apply_logger_env_levels(std::shared_ptr<logger> new_logger);
|
||||||
|
|
||||||
std::mutex& console_mutex();
|
std::mutex& console_mutex();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
registry();
|
|
||||||
~registry();
|
|
||||||
|
|
||||||
void throw_if_exists_(const std::string &logger_name);
|
void throw_if_exists_(const std::string &logger_name);
|
||||||
void register_logger_(std::shared_ptr<logger> new_logger);
|
void register_logger_(std::shared_ptr<logger> new_logger);
|
||||||
bool set_level_from_cfg_(logger *logger);
|
bool set_level_from_cfg_(logger *logger);
|
||||||
|
Loading…
Reference in New Issue
Block a user