diff options
| author | memchr <118117622+memchr@users.noreply.github.com> | 2023-09-20 07:26:20 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-20 08:26:20 +0100 |
| commit | 6594b50e57935dd66930ccd35dba7a1b4131399d (patch) | |
| tree | 17d4fa7aabf0e447c7171346c5b851c999093149 /src/helpers | |
| parent | d8d0cd75c2db16a14086e1d5119ed937a60c701e (diff) | |
logging/format: use std::format_string to catch formatting string errors at compile time (#3377)
* fix(log): use constexpr format string
* deprecate getFormat
Diffstat (limited to 'src/helpers')
| -rw-r--r-- | src/helpers/MiscFunctions.cpp | 6 | ||||
| -rw-r--r-- | src/helpers/MiscFunctions.hpp | 26 |
2 files changed, 6 insertions, 26 deletions
diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index 218c2332..e54e93ac 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -706,8 +706,4 @@ std::vector<SCallstackFrameInfo> getBacktrace() { void throwError(const std::string& err) { Debug::log(CRIT, "Critical error thrown: {}", err); throw std::runtime_error(err); -} - -void sendToLog(uint8_t level, const std::string& s) { - Debug::log((LogLevel)level, s); -} +}
\ No newline at end of file diff --git a/src/helpers/MiscFunctions.hpp b/src/helpers/MiscFunctions.hpp index f53ab4e8..429f381f 100644 --- a/src/helpers/MiscFunctions.hpp +++ b/src/helpers/MiscFunctions.hpp @@ -32,26 +32,10 @@ std::string replaceInString(std::string subject, const std: std::vector<SCallstackFrameInfo> getBacktrace(); void throwError(const std::string& err); -// why, C++. -void sendToLog(uint8_t, const std::string&); template <typename... Args> -std::string getFormat(const std::string& fmt, Args&&... args) { - std::string fmtdMsg; - - try { - fmtdMsg += std::vformat(fmt, std::make_format_args(args...)); - } catch (std::exception& e) { - std::string exceptionMsg = e.what(); - sendToLog(2, std::format("caught exception in getFormat: {}", exceptionMsg)); - - const auto CALLSTACK = getBacktrace(); - - sendToLog(0, "stacktrace:"); - - for (size_t i = 0; i < CALLSTACK.size(); ++i) { - sendToLog(1, std::format("\t #{} | {}", i, CALLSTACK[i].desc)); - } - } - - return fmtdMsg; +[[deprecated("use std::format instead")]] std::string getFormat(std::format_string<Args...> fmt, Args&&... args) { + // no need for try {} catch {} because std::format_string<Args...> ensures that vformat never throw std::format_error + // because any suck format specifier will cause a compilation error + // this is actually what std::format in stdlib does + return std::vformat(fmt.get(), std::make_format_args(args...)); }
\ No newline at end of file |
