-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Mapped Diagnostic Context (MDC) support (#2907)
* Added Mapped Diagnostic Context (MDC) support * Update include statement * Optimize string creation * Fix includes * Fix padding rules in mdc empty case * Add comment to describe the use of mdc formatter
- Loading branch information
1 parent
23587b0
commit d03eb40
Showing
4 changed files
with
202 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <spdlog/common.h> | ||
#include <map> | ||
|
||
namespace spdlog { | ||
|
||
class SPDLOG_API mdc { | ||
public: | ||
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 std::map<std::string, std::string> &get_context() { | ||
static thread_local std::map<std::string, std::string> context; | ||
return context; | ||
} | ||
}; | ||
|
||
} // namespace spdlog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters