From 27cb4c76708608465c413f6d0e6b8d99a4d84302 Mon Sep 17 00:00:00 2001 From: gabime Date: Tue, 30 Apr 2024 13:14:29 +0300 Subject: [PATCH] Added mdc example to readme --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index a61dc0369..3aeceb753 100644 --- a/README.md +++ b/README.md @@ -437,7 +437,22 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) logger->info("Some info message"); } ``` +--- +#### Mapped Diagnostic Context +```c++ +// Mapped Diagnostic Context (MDC) is a map that stores key-value pairs (string values) in thread local storage. +// Each thread maintains its own MDC, which loggers use to append diagnostic information to log outputs. +// Note: it is not supported in asynchronous mode due to its reliance on thread-local storage. +#include "spdlog/mdc.h" +void mdc_example() +{ + spdlog::mdc::put("key1", "value1"); + spdlog::mdc::put("key2", "value2"); + // if not using the default format, use the %& formatter to print mdc data + // spdlog::set_pattern("[%H:%M:%S %z] [%^%L%$] [%&] %v"); +} +``` --- ## Benchmarks