Skip to content

Commit

Permalink
Added mdc.h
Browse files Browse the repository at this point in the history
  • Loading branch information
gabime committed Mar 29, 2024
1 parent 02c3ca5 commit 8d6a121
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions include/spdlog/mdc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include <map>

namespace spdlog {
class mdc {
public:
using mdc_map_t = std::map<std::string, std::string>;

static void put(const std::string &key, const std::string &value) {
get_context()[key] = value;
}

static std::string get(const std::string &key) {
auto &context = get_context();
auto it = context.find(key);
if (it != context.end()) {
return it->second;
}
return "";
}

static void remove(const std::string &key) { get_context().erase(key); }

static void clear() { get_context().clear(); }

static mdc_map_t &get_context() {
static thread_local mdc_map_t context;
return context;
}
};

} // namespace spdlog

0 comments on commit 8d6a121

Please sign in to comment.