Go to the documentation of this file.
18 #include <farm_pp/preprocessor/comparison/equal.hpp>
19 #include <farm_pp/preprocessor/control/if.hpp>
20 #include <farm_pp/preprocessor/variadic/size.hpp>
22 #include <fmt/format.h>
23 #include <fmt/ostream.h>
28 #ifdef FARM_COMPILE_TIME_FMT
29 #define FARM_STRING(x) FMT_STRING(x)
31 #define FARM_STRING(x) x
39 void logLine(std::string
const &line);
43 #define FARM_IMPL_LOG_PRINTLN_ZERO()
45 #define FARM_IMPL_LOG_PRINTLN_ONE(cstr) farm_ng::logLine(FARM_STRING(cstr))
47 #define FARM_IMPL_LOG_PRINTLN_ARGS(cstr, ...) \
48 farm_ng::logLine(::fmt::format(FMT_STRING(cstr), __VA_ARGS__))
50 #define FARM_IMPL_LOG_PRINTLN_VARG(cstr, ...) \
52 FARM_PP_EQUAL(FARM_PP_VARIADIC_SIZE(cstr, ##__VA_ARGS__), 1), \
53 FARM_IMPL_LOG_PRINTLN_ONE(cstr), \
54 FARM_IMPL_LOG_PRINTLN_ARGS(cstr, ##__VA_ARGS__))
56 #define FARM_IMPL_LOG_PRINTLN(...) \
58 FARM_PP_EQUAL(FARM_PP_VARIADIC_SIZE(dummy, ##__VA_ARGS__), 1), \
59 FARM_IMPL_LOG_PRINTLN_ZERO(), \
60 FARM_IMPL_LOG_PRINTLN_VARG(__VA_ARGS__))
62 #define FARM_IMPL_ABORT() \
64 farm_ng::printBacktrace(); \
73 template <
class... TArgs>
75 std::string
const &file,
77 std::string
const &
str,
80 return ::fmt::format(fmt::runtime(
str), std::forward<TArgs>(
args)...);
81 }
catch (::fmt::format_error &e) {
84 "Runtime format error thrown for {}.\nError string: {}",
str, e.what());
98 #define FARM_RUNTIME_FORMAT(str, ...) \
99 ::farm_ng::details::runtimeFormatImpl(__FILE__, __LINE__, str, __VA_ARGS__)
101 #ifdef FARM_COMPILE_TIME_FMT
102 #define FARM_IMPL_FORMAT_ARGS(cstr, ...) \
103 ::fmt::format(FMT_STRING(cstr), __VA_ARGS__)
105 #define FARM_IMPL_FORMAT_ARGS(cstr, ...) FARM_RUNTIME_FORMAT(cstr, __VA_ARGS__)
108 #define FARM_IMPL_FORMAT_VARG(cstr, ...) \
110 FARM_PP_EQUAL(FARM_PP_VARIADIC_SIZE(cstr, ##__VA_ARGS__), 1), \
112 FARM_IMPL_FORMAT_ARGS(cstr, ##__VA_ARGS__))
125 #define FARM_FORMAT(...) \
127 FARM_PP_EQUAL(FARM_PP_VARIADIC_SIZE(dummy, ##__VA_ARGS__), 1), \
129 FARM_IMPL_FORMAT_VARG(__VA_ARGS__))
Definition: backtrace.cpp:102
void logLine(std::string const &line)
Definition: format.cpp:28
str
Definition: event_service.py:547
args
Definition: event_service.py:549
void setLogLineFunction(std::function< void(std::string const &)> f)
Definition: format.cpp:24
std::function< void(std::string const &)> & getLogLineFunction()
Definition: format.h:35
std::string runtimeFormatImpl(std::string const &file, int line, std::string const &str, TArgs &&...args)
Definition: format.h:74