Handle loggers with name that already exist

This commit is contained in:
2023-09-25 20:56:47 +02:00
parent 5dfc2de985
commit 869a9a36a1
2 changed files with 2 additions and 1 deletions

View File

@@ -85,6 +85,7 @@ namespace openVulkanoCpp
Logger::Ptr Logger::CreateLogger(const std::string& name, const bool reg) Logger::Ptr Logger::CreateLogger(const std::string& name, const bool reg)
{ {
if (reg) { auto logger = spdlog::get(name); if (logger) return logger; }
auto logger = std::make_shared<spdlog::logger>(name, SINKS.begin(), SINKS.end()); auto logger = std::make_shared<spdlog::logger>(name, SINKS.begin(), SINKS.end());
if (reg) spdlog::register_logger(logger); if (reg) spdlog::register_logger(logger);
#ifdef LOG_DATE #ifdef LOG_DATE

View File

@@ -39,7 +39,7 @@ namespace openVulkanoCpp
* \brief Creates a new custom logger that writes to the main log file. * \brief Creates a new custom logger that writes to the main log file.
* \param name The name of the logger * \param name The name of the logger
* \param reg If set to true the logger can be accessed again with Logger::GetLogger(name) * \param reg If set to true the logger can be accessed again with Logger::GetLogger(name)
* \return The created logger * \return The created logger, if reg = true and a logger with the given name already exists this function will return the old logger.
*/ */
static Ptr CreateLogger(const std::string& name, bool reg = true); static Ptr CreateLogger(const std::string& name, bool reg = true);