NexusForce 1.0.0
A rigorously engineered full-stack C++ backend library.
载入中...
搜索中...
未找到
neforce::mdc类 参考

Mapped Diagnostic Context,线程局部上下文 更多...

#include <log_event.hpp>

静态 Public 成员函数

static void put (const string &key, string value)
 设置键值对
static string get (const string &key)
 获取键对应的值
static void remove (const string &key)
 移除指定的键
static void clear ()
 清除当前线程的所有 MDC 数据
static bool empty ()
 检查当前线程的 MDC 是否为空
static unordered_map< string, stringsnapshot ()
 获取当前线程 MDC 的快照

详细描述

Mapped Diagnostic Context,线程局部上下文

每个线程独立的键值对存储,用于附加请求追踪信息(如 request_id、user)。 日志事件构造时自动将 MDC 内容合并到 event.context 中。

在文件 log_event.hpp124 行定义.

成员函数说明

◆ empty()

bool neforce::mdc::empty ( )
static

检查当前线程的 MDC 是否为空

返回
为空返回 true

◆ get()

string neforce::mdc::get ( const string & key)
static

获取键对应的值

参数
key键名
返回
值,若不存在返回空字符串

◆ put()

void neforce::mdc::put ( const string & key,
string value )
static

设置键值对

参数
key键名
value

◆ remove()

void neforce::mdc::remove ( const string & key)
static

移除指定的键

参数
key键名

◆ snapshot()

unordered_map< string, string > neforce::mdc::snapshot ( )
static

获取当前线程 MDC 的快照

返回
MDC 键值对副本

该类的文档由以下文件生成: