drogon icon indicating copy to clipboard operation
drogon copied to clipboard

SPDLog

Open GigaDevelopper opened this issue 7 months ago • 3 comments

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?

GigaDevelopper avatar Jun 11 '25 06:06 GigaDevelopper

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 Page

    Added 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:
    The spdlog wiki - Patterns shows [%thread_name] as a valid flag, but this is only present in docs after v1.10.0.

slesniew avatar Jun 20 '25 13:06 slesniew

Any updates on this?

From a quick glance, it seems there are a couple things off with this:

  1. spdlog is not enabled until "run" so any earlier log messages will not use spd.
  2. 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)

ToddWilfling avatar Sep 22 '25 19:09 ToddWilfling

OK I take it back, I think I can work around it by calling drogon::app().setupFileLogger(); earlier.

ToddWilfling avatar Sep 22 '25 20:09 ToddWilfling