mirror of https://github.com/gabime/spdlog.git
Add mdc support for default format
parent
cba66029e2
commit
1253a57db6
@ -1,35 +1,34 @@
|
|||||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
|
||||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace spdlog {
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
class mdc {
|
static std::string get(const std::string &key) {
|
||||||
public:
|
auto &context = get_context();
|
||||||
static void put(const std::string &key, const std::string &value) {
|
auto it = context.find(key);
|
||||||
get_context()[key] = value;
|
if (it != context.end()) {
|
||||||
}
|
return it->second;
|
||||||
|
}
|
||||||
static std::string get(const std::string &key) {
|
return "";
|
||||||
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 remove(const std::string &key) { get_context().erase(key); }
|
||||||
|
|
||||||
static void clear() { get_context().clear(); }
|
static void clear() { get_context().clear(); }
|
||||||
|
|
||||||
static std::map<std::string, std::string> &get_context() {
|
static mdc_map_t &get_context() {
|
||||||
static thread_local std::map<std::string, std::string> context;
|
static thread_local mdc_map_t context;
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace spdlog
|
} // namespace spdlog
|
Loading…
Reference in New Issue