Search code examples
c++spdlogfmt

spdlog error: "don't know how to format the type, include fmt/ostream.h if it provides an operator<< that should be used"


I've just picked up spdlog in an effort to improve our logging. Our logging is very basic, so I'm just copying the "multi sink" example almost verbatim to log to file and console.

However, even when following the example exactly, I get:

Error C2338 don't know how to format the type, include fmt/ostream.h if it provides an operator<< that should be used Logger d:\tfs\development\bladed\main\external\spdlog\spdlog-1.x\include\spdlog\fmt\bundled\core.h 351

Coming from core.h:

// A formatter for objects of type T.
template <typename T, typename Char = char, typename Enable = void>
struct formatter {
  static_assert(no_formatter_error<T>::value,
    "don't know how to format the type, include fmt/ostream.h if it provides "
    "an operator<< that should be used");

I'm presuming this is really easy to fix, but I can't see it...

[basic Win32 usage]


Solution

  • With @PaulMcKenzie pointing me in the right direction, it seems that I was trying to log a type of string that spdlog cannot handle by default (std::wstrings).

    Visual Studio's Intellisense seemed to be confused by the templating, making it appear to be happy with my sending spdlog::warn a std::wstring.

    Solution: either just use std::string, or if you want to use wstrings you (probably) need to define a custome formatter for them.