Skip to content

Commit

Permalink
fix: initialize logger mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
abdes committed May 17, 2023
1 parent 7c598c5 commit 680f507
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion logging/include/logging/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class ASAP_LOGGING_API Logger final {
std::shared_ptr<spdlog::logger> logger_;
/// Synchronization lock used to synchronize logging over this logger from
/// multiple threads.
std::unique_ptr<std::mutex> logger_mutex_{};
std::unique_ptr<std::mutex> logger_mutex_;

/// Logger objects are created only by the Registry class.
friend class Registry;
Expand Down
7 changes: 5 additions & 2 deletions logging/src/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "logging/logging.h"

#include <iomanip> // std::setw
#include <memory>
#include <mutex>
#include <sstream> // std::ostringstream
#include <utility>

Expand Down Expand Up @@ -43,8 +45,9 @@ std::recursive_mutex Registry::loggers_mutex_; // NOLINT
// Logger
// ---------------------------------------------------------------------------

Logger::Logger(const std::string &name, const spdlog::sink_ptr &sink) {
logger_ = std::make_shared<spdlog::logger>(name, sink);
Logger::Logger(const std::string &name, const spdlog::sink_ptr &sink)
: logger_(std::make_shared<spdlog::logger>(name, sink)),
logger_mutex_(std::make_unique<std::mutex>()) {
logger_->set_pattern(DEFAULT_LOG_FORMAT);
logger_->set_level(spdlog::level::trace);
// Ensure that critical errors, especially ASSERT/PANIC, get flushed
Expand Down

0 comments on commit 680f507

Please sign in to comment.