Skip to content

Commit

Permalink
Backported FMT_STRING
Browse files Browse the repository at this point in the history
  • Loading branch information
gabime committed Nov 25, 2024
1 parent c1f101a commit a2de136
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions include/spdlog/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@

#if !defined(SPDLOG_USE_STD_FORMAT) && FMT_VERSION >= 80000 // backward compatibility with fmt versions older than 8
#define SPDLOG_FMT_RUNTIME(format_string) fmt::runtime(format_string)
#define SPDLOG_FMT_STRING(format_string) FMT_STRING(format_string)
#if defined(SPDLOG_WCHAR_FILENAMES)
#include "fmt/xchar.h"
#endif
#else
#define SPDLOG_FMT_RUNTIME(format_string) format_string
#define SPDLOG_FMT_STRING(format_string) format_string
#endif

#ifndef SPDLOG_FUNCTION
Expand Down
2 changes: 1 addition & 1 deletion include/spdlog/details/fmt_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ inline void pad2(int n, memory_buf_t &dest) {
dest.push_back(static_cast<char>('0' + n % 10));
} else // unlikely, but just in case, let fmt deal with it
{
fmt_lib::format_to(std::back_inserter(dest), "{:02}", n);
fmt_lib::format_to(std::back_inserter(dest), SPDLOG_FMT_STRING("{:02}"), n);
}
}

Expand Down
2 changes: 1 addition & 1 deletion include/spdlog/fmt/bin_to_hex.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ struct formatter<spdlog::details::dump_info<T>, char> {
*inserter++ = '\n';

if (put_positions) {
spdlog::fmt_lib::format_to(inserter, "{:04X}: ", pos);
spdlog::fmt_lib::format_to(inserter, SPDLOG_FMT_STRING("{:04X}: "), pos);
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion include/spdlog/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#define SPDLOG_LOGGER_CATCH(location) \
catch (const std::exception &ex) { \
if (!location.empty()) { \
err_handler_(fmt_lib::format("{} [{}({})]", ex.what(), location.filename, location.line)); \
err_handler_(fmt_lib::format(SPDLOG_FMT_STRING("{} [{}({})]"), ex.what(), location.filename, location.line)); \
} else { \
err_handler_(ex.what()); \
} \
Expand Down
2 changes: 1 addition & 1 deletion include/spdlog/sinks/daily_file_sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct daily_filename_calculator {
static filename_t calc_filename(const filename_t &filename, const tm &now_tm) {
filename_t basename, ext;
std::tie(basename, ext) = details::file_helper::split_by_extension(filename);
return fmt_lib::format(SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}{}"), basename, now_tm.tm_year + 1900, now_tm.tm_mon + 1,
return fmt_lib::format(SPDLOG_FMT_STRING(SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}{}")), basename, now_tm.tm_year + 1900, now_tm.tm_mon + 1,
now_tm.tm_mday, ext);
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/sinks/rotating_file_sink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ filename_t rotating_file_sink<Mutex>::calc_filename(const filename_t &filename,

filename_t basename, ext;
std::tie(basename, ext) = details::file_helper::split_by_extension(filename);
return fmt_lib::format(SPDLOG_FILENAME_T("{}.{}{}"), basename, index, ext);
return fmt_lib::format(SPDLOG_FMT_STRING(SPDLOG_FILENAME_T("{}.{}{}")), basename, index, ext);
}

template <typename Mutex>
Expand Down

0 comments on commit a2de136

Please sign in to comment.