I'm trying to add a filename prefix to each log string in spdlog. The Spdlog formatting string looks as this:
Test log {}
Logs are written as this:
spdlog::error("Test log {}", value)
I'm trying to wrap this call and concatenate additional {} before formatting string, so I can pass the prefix of the file there.
static constexpr char * prefixHolder("{} ");
template<typename... Args>
void critical(const char fmt[], Args&&... args) const
{
constexpr auto fullFmt = prefixHolder + fmt; //I can't find any solution for this
spdlog::critical(fullFmt, m_prefix, std::forward<Args>(args)...);
}
Log log("MyClassOrLogger");
log.critical("My format {}", value);
Is it possible to solve this at compile time? I've tried some approaches, but I haven't found any way to make input fmt argument constexpr for the compiler.
C++ 17
Any suggestions or solutions?
Thanks