From 0e4df671f6427f92532ff857a608a8aebaa61fa4 Mon Sep 17 00:00:00 2001 From: esigo <32193773+E-Saei@users.noreply.github.com> Date: Sat, 18 Dec 2021 10:32:49 +0100 Subject: [PATCH] loggers vector --- .../opentelemetry/sdk/logs/logger_provider.h | 4 +--- sdk/src/logs/logger_provider.cc | 16 +++++++++------- sdk/test/logs/logger_sdk_test.cc | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/logs/logger_provider.h b/sdk/include/opentelemetry/sdk/logs/logger_provider.h index a7a5d5411c..c983d0c7ce 100755 --- a/sdk/include/opentelemetry/sdk/logs/logger_provider.h +++ b/sdk/include/opentelemetry/sdk/logs/logger_provider.h @@ -7,7 +7,6 @@ # include # include # include -# include # include # include "opentelemetry/logs/logger_provider.h" @@ -84,8 +83,7 @@ class LoggerProvider final : public opentelemetry::logs::LoggerProvider, opentelemetry::sdk::common::AtomicSharedPtr processor_; // A vector of pointers to all the loggers that have been created - std::unordered_map> - loggers_; + std::vector> loggers_; // A mutex that ensures only one thread is using the map of loggers std::mutex mu_; diff --git a/sdk/src/logs/logger_provider.cc b/sdk/src/logs/logger_provider.cc index 56e63625d3..061a1b849d 100644 --- a/sdk/src/logs/logger_provider.cc +++ b/sdk/src/logs/logger_provider.cc @@ -27,10 +27,13 @@ nostd::shared_ptr LoggerProvider::GetLogger( std::lock_guard lock_guard{mu_}; // If a logger with a name "logger_name" already exists, return it - auto loggerkv = loggers_.find(logger_name.data()); - if (loggerkv != loggers_.end()) + for (auto &logger : loggers_) { - return nostd::shared_ptr(loggerkv->second); + auto& logger_lib = logger->GetInstrumentationLibrary(); + if (logger->GetName() == logger_name && logger_lib.equal(library_name, library_version, schema_url)) + { + return nostd::shared_ptr{logger}; + } } // Check if creating a new logger would exceed the max number of loggers @@ -50,10 +53,9 @@ nostd::shared_ptr LoggerProvider::GetLogger( auto lib = instrumentationlibrary::InstrumentationLibrary::Create(library_name, library_version, schema_url); - nostd::shared_ptr logger( - new Logger(logger_name, this->shared_from_this(), std::move(lib))); - loggers_[logger_name.data()] = logger; - return logger; + loggers_.push_back(std::shared_ptr( + new Logger(logger_name, this->shared_from_this(), std::move(lib)))); + return nostd::shared_ptr{loggers_.back()}; } nostd::shared_ptr LoggerProvider::GetLogger( diff --git a/sdk/test/logs/logger_sdk_test.cc b/sdk/test/logs/logger_sdk_test.cc index dc70458114..b754b30bed 100644 --- a/sdk/test/logs/logger_sdk_test.cc +++ b/sdk/test/logs/logger_sdk_test.cc @@ -78,7 +78,7 @@ TEST(LoggerSDK, LogToAProcessor) // LoggerProvider by checking that getting a logger with the same name as the previously defined // logger is the same instance auto lp = static_cast(api_lp.get()); - auto logger2 = lp->GetLogger("logger", "", schema_url); + auto logger2 = lp->GetLogger("logger", "", "lib_name", "", schema_url); ASSERT_EQ(logger, logger2); auto sdk_logger = static_cast(logger.get());