Ported pull #3023 with some changes and tests

This commit is contained in:
gabime
2024-03-16 17:12:46 +02:00
parent 167bf989d8
commit 8e10782a58
5 changed files with 223 additions and 175 deletions

View File

@@ -13,6 +13,7 @@
#include <memory>
#include <mutex>
#include <string>
#include <string_view>
#include <unordered_map>
#include "../common.h"
@@ -35,6 +36,8 @@ public:
void register_logger(std::shared_ptr<logger> new_logger);
void initialize_logger(std::shared_ptr<logger> new_logger);
std::shared_ptr<logger> get(const std::string &logger_name);
std::shared_ptr<logger> get(std::string_view logger_name);
std::shared_ptr<logger> get(const char *logger_name);
std::shared_ptr<logger> default_logger();
// Return raw ptr to the default logger.

View File

@@ -14,6 +14,7 @@
#include <memory>
#include <mutex>
#include <string>
#include <string_view>
#include "./common.h"
#include "./details/registry.h"
@@ -50,6 +51,8 @@ SPDLOG_API void initialize_logger(std::shared_ptr<logger> logger);
// exist.
// example: spdlog::get("my_logger")->info("hello {}", "world");
SPDLOG_API std::shared_ptr<logger> get(const std::string &name);
SPDLOG_API std::shared_ptr<logger> get(std::string_view name);
SPDLOG_API std::shared_ptr<logger> get(const char *name);
// Set global formatter. Each sink in each logger will get a clone of this object
SPDLOG_API void set_formatter(std::unique_ptr<spdlog::formatter> formatter);