Skip to content

Commit 4b1c529

Browse files
committed
Cache default log and use it, fix shutdown race
1 parent 3c0f715 commit 4b1c529

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/util/Logging.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,16 @@ Logging::normalizePartition(std::string const& partition)
418418
std::recursive_mutex Logging::mLogMutex;
419419

420420
#if defined(USE_SPDLOG)
421+
LogPtr Logging::defaultLogPtr = nullptr;
422+
LogPtr Logging::getDefaultLogPtr() \
423+
{
424+
std::lock_guard<std::recursive_mutex> guard(mLogMutex);
425+
if (!defaultLogPtr)
426+
{
427+
defaultLogPtr = spdlog::default_logger();
428+
}
429+
return defaultLogPtr;
430+
}
421431
#define LOG_PARTITION(name) \
422432
LogPtr Logging::name##LogPtr = nullptr; \
423433
LogPtr Logging::get##name##LogPtr() \

src/util/Logging.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
SPDLOG_LOGGER_CRITICAL(lg, fmt, ##__VA_ARGS__))
7777

7878
#define GET_LOG(name) spdlog::get(name)
79-
#define DEFAULT_LOG spdlog::default_logger()
79+
#define DEFAULT_LOG stellar::Logging::getDefaultLogPtr()
8080
namespace stellar
8181
{
8282
typedef std::shared_ptr<spdlog::logger> LogPtr;
@@ -168,6 +168,7 @@ class Logging
168168
static std::string mLastPattern;
169169
static std::string mLastFilenamePattern;
170170
static bool mLogToConsole;
171+
static LogPtr defaultLogPtr;
171172
#define LOG_PARTITION(name) static LogPtr name##LogPtr;
172173
#include "util/LogPartitions.def"
173174
#undef LOG_PARTITION
@@ -195,6 +196,7 @@ class Logging
195196
static std::array<std::string const, 15> const kPartitionNames;
196197

197198
#if defined(USE_SPDLOG)
199+
static LogPtr getDefaultLogPtr();
198200
#define LOG_PARTITION(name) static LogPtr get##name##LogPtr();
199201
#include "util/LogPartitions.def"
200202
#undef LOG_PARTITION

0 commit comments

Comments
 (0)