fix/issue-3101: fix the issue where mdc ignores SPDLOG_NO_TLS (#3184)

Co-authored-by: dyf <yufeng.duan@senscape.com.cn>
This commit is contained in:
allen_qfl
2024-09-13 03:27:25 +08:00
committed by GitHub
parent 2169a6f6ae
commit 362214a349
5 changed files with 34 additions and 3 deletions

View File

@@ -382,7 +382,9 @@ void replace_default_logger_example() {
// 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"
#ifndef SPDLOG_NO_TLS
#include "spdlog/mdc.h"
void mdc_example()
{
spdlog::mdc::put("key1", "value1");
@@ -391,3 +393,8 @@ void mdc_example()
spdlog::set_pattern("[%H:%M:%S %z] [%^%L%$] [%&] %v");
spdlog::info("Some log message with context");
}
#else
void mdc_example() {
// if TLS feature is disabled
}
#endif