Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
Loading...
Searching...
No Matches
log_context_scope.cpp
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
7
8namespace kcenon::logger {
9
11 : previous_context_(log_context_storage::get()),
12 had_previous_(log_context_storage::has_context()),
13 logger_(&log) {
14 for (const auto& [key, value] : fields) {
15 // Track which keys we're adding
16 if (previous_context_.find(key) == previous_context_.end()) {
17 added_keys_.push_back(key);
18 }
19 log_context_storage::set(key, value);
20
21 // Also set on logger for non-thread-local context
22 std::visit([&log, &key](const auto& v) {
23 log.context().set(key, v);
24 }, value);
25 }
26}
27
28void log_context_scope::remove_logger_context(const std::string& key) {
29 if (logger_ != nullptr) {
30 logger_->context().remove(key);
31 }
32}
33
34} // namespace kcenon::logger
log_context_scope(const log_fields &fields)
Construct scope with initial fields.
void remove_logger_context(const std::string &key)
std::vector< std::string > added_keys_
Thread-local storage for structured logging context fields.
static void set(const std::string &key, const std::string &value)
Set a string context field for the current thread.
unified_log_context & context()
Definition logger.cpp:769
unified_log_context & set(std::string_view key, context_value value, context_category category=context_category::custom)
Set a context value.
void remove(std::string_view key)
Remove a specific key from the context.
RAII-based context scope management for structured logging kcenon.
High-performance, thread-safe logging system with asynchronous capabilities.
std::unordered_map< std::string, log_value > log_fields
Type alias for structured fields map.
Definition log_entry.h:75