diff --git a/source/common/common/logger.h b/source/common/common/logger.h index a50616cc62aee..8fb1548f6628a 100644 --- a/source/common/common/logger.h +++ b/source/common/common/logger.h @@ -97,6 +97,11 @@ class LockingStderrOrFileSink : public spdlog::sinks::sink { void log(const spdlog::details::log_msg& msg) override; void flush() override; + /** + * @return bool whether a lock has been established. + */ + bool hasLock() const { return lock_ != nullptr; } + private: Thread::BasicLockable* lock_{}; Filesystem::FileSharedPtr log_file_; @@ -132,6 +137,11 @@ class Registry { */ static const std::vector& loggers() { return allLoggers(); } + /** + * @Return bool whether the registry has been initialized. + */ + static bool initialized() { return getSink()->hasLock(); } + private: /* * @return std::vector& return the installed loggers. diff --git a/source/common/common/thread.cc b/source/common/common/thread.cc index 153322c44aa03..bb8b3a49126db 100644 --- a/source/common/common/thread.cc +++ b/source/common/common/thread.cc @@ -9,12 +9,14 @@ #include #include "common/common/assert.h" +#include "common/common/logger.h" #include "common/common/macros.h" namespace Envoy { namespace Thread { Thread::Thread(std::function thread_routine) : thread_routine_(thread_routine) { + RELEASE_ASSERT(Logger::Registry::initialized()); int rc = pthread_create(&thread_id_, nullptr, [](void* arg) -> void* { static_cast(arg)->thread_routine_();