summaryrefslogtreecommitdiffstats
path: root/deps/include/spdlog/mdc.h
diff options
context:
space:
mode:
authoruntodesu <kirill@untode.su>2025-03-15 16:22:09 +0500
committeruntodesu <kirill@untode.su>2025-03-15 16:22:09 +0500
commit3bf42c6ff3805a0d42bbc661794a95ff31bedc26 (patch)
tree05049955847504808d6bed2bb7b155f8b03807bb /deps/include/spdlog/mdc.h
parent02294547dcde0d4ad76e229106702261e9f10a51 (diff)
downloadvoxelius-3bf42c6ff3805a0d42bbc661794a95ff31bedc26.tar.bz2
voxelius-3bf42c6ff3805a0d42bbc661794a95ff31bedc26.zip
Add whatever I was working on for the last month
Diffstat (limited to 'deps/include/spdlog/mdc.h')
-rw-r--r--deps/include/spdlog/mdc.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/deps/include/spdlog/mdc.h b/deps/include/spdlog/mdc.h
new file mode 100644
index 0000000..8f4923d
--- /dev/null
+++ b/deps/include/spdlog/mdc.h
@@ -0,0 +1,50 @@
+// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
+// Distributed under the MIT License (http://opensource.org/licenses/MIT)
+
+#pragma once
+
+#if defined(SPDLOG_NO_TLS)
+ #error "This header requires thread local storage support, but SPDLOG_NO_TLS is defined."
+#endif
+
+#include <map>
+#include <string>
+
+#include <spdlog/common.h>
+
+// MDC is a simple map of key->string values stored in thread local storage whose content will be printed by the loggers.
+// Note: Not supported in async mode (thread local storage - so the async thread pool have different copy).
+//
+// Usage example:
+// spdlog::mdc::put("mdc_key_1", "mdc_value_1");
+// spdlog::info("Hello, {}", "World!"); // => [2024-04-26 02:08:05.040] [info] [mdc_key_1:mdc_value_1] Hello, World!
+
+namespace spdlog {
+class SPDLOG_API 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