Skip to content

Commit 27cb4c7

Browse files
committed
Added mdc example to readme
1 parent 2d4acf8 commit 27cb4c7

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,22 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
437437
logger->info("Some info message");
438438
}
439439
```
440+
---
440441
442+
#### Mapped Diagnostic Context
443+
```c++
444+
// Mapped Diagnostic Context (MDC) is a map that stores key-value pairs (string values) in thread local storage.
445+
// Each thread maintains its own MDC, which loggers use to append diagnostic information to log outputs.
446+
// Note: it is not supported in asynchronous mode due to its reliance on thread-local storage.
447+
#include "spdlog/mdc.h"
448+
void mdc_example()
449+
{
450+
spdlog::mdc::put("key1", "value1");
451+
spdlog::mdc::put("key2", "value2");
452+
// if not using the default format, use the %& formatter to print mdc data
453+
// spdlog::set_pattern("[%H:%M:%S %z] [%^%L%$] [%&] %v");
454+
}
455+
```
441456
---
442457
## Benchmarks
443458

0 commit comments

Comments
 (0)