SPDLog
How I can use spdlog spdlog::set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%n] [%^%l%$] [%t] [%thread_name] %v");
but it doesnt work?
The placeholder [%thread_name] is only supported in spdlog v1.10.0 and later.
Drogon uses the spdlog version you have installed and discoverable by CMake at build time. Drogon does not vendor or hardcode a specific spdlog version (CMakeLists.txt 85-92):
if(USE_SPDLOG)
find_package(spdlog CONFIG)
if(spdlog_FOUND)
message(STATUS "spdlog found!")
target_link_libraries(${PROJECT_NAME} PUBLIC spdlog::spdlog_header_only)
target_compile_definitions(${PROJECT_NAME} PUBLIC DROGON_SPDLOG_SUPPORT SPDLOG_FMT_EXTERNAL FMT_HEADER_ONLY)
endif(spdlog_FOUND)
endif(USE_SPDLOG)
Check your vesion (Debian/Ubuntu):
apt show libspdlog-dev
References
-
spdlog v1.10.0 Release Notes:
GitHub Release PageAdded support for thread names in the log pattern via new %thread_name pattern flag.
PR #2092 Thanks @d-frey
-
Pull Request that Added the Feature:
PR #2092: Add thread name support to pattern_formatter- Title: Add thread name support to pattern_formatter
- Merged for: Release 1.10.0
-
Changelog Snippet for v1.10.0:
Added support for thread names in the log pattern via new %thread_name pattern flag.
-
Documentation:
Thespdlogwiki - Patterns shows[%thread_name]as a valid flag, but this is only present in docs after v1.10.0.
Any updates on this?
From a quick glance, it seems there are a couple things off with this:
- spdlog is not enabled until "run" so any earlier log messages will not use spd.
- Sinks are hard coded and enabled inside app().run(), so I am unsure how to override the formats (wanted to implement a custom format just like the op)
OK I take it back, I think I can work around it by calling drogon::app().setupFileLogger(); earlier.