11 #include <spdlog/fmt/fmt.h>
12 #include <spdlog/fmt/ostr.h>
13 #include <spdlog/logger.h>
16 #if FMT_VERSION >= 9 * 10000
17 # define MC_FMT_STREAMED(X) fmt::streamed(X)
18 # include <boost/filesystem.hpp>
19 # include <Eigen/Core>
20 # include <fmt/ostream.h>
21 # include <fmt/ranges.h>
22 # include <type_traits>
25 template<
typename T,
typename Char>
26 struct fmt::formatter<T,
28 std::enable_if_t<std::is_base_of_v<Eigen::DenseBase<T>, T>
29 && (fmt::range_format_kind<T, Char, void>::value == fmt::range_format::disabled)>>
30 : fmt::ostream_formatter
36 struct fmt::formatter<
boost::filesystem::path> : fmt::formatter<std::string>
38 template<
typename FormatContext>
39 auto format(
const boost::filesystem::path & p, FormatContext & ctx)
41 return fmt::formatter<std::string>::format(p.string(), ctx);
46 # define MC_FMT_STREAMED(X) X
49 #define BOOST_STACKTRACE_LINK
50 #include <boost/stacktrace.hpp>
73 template<
typename ExceptionT = std::runtime_error,
typename... Args>
76 auto message = fmt::format(std::forward<Args>(args)...);
80 throw ExceptionT(message);
83 template<
typename... Args>
89 template<
typename... Args>
95 template<
typename... Args>
101 template<
typename... Args>
107 template<
typename... Args>
113 template<
typename... Args>
136 # define LOG_ERROR(args) \
137 _Pragma("GCC warning \"This macro is deprecated, use mc_rtc::log::error instead\""); \
138 std::cerr << mc_rtc::OUT_RED << args << mc_rtc::OUT_NONE << "\n";
139 # define LOG_WARNING(args) \
140 _Pragma("GCC warning \"This macro is deprecated, use mc_rtc::log::warning instead\""); \
141 std::cerr << mc_rtc::OUT_PURPLE << args << mc_rtc::OUT_NONE << "\n";
142 # define LOG_INFO(args) \
143 _Pragma("GCC warning \"This macro is deprecated, use mc_rtc::log::info instead\""); \
144 std::cout << mc_rtc::OUT_BLUE << args << mc_rtc::OUT_NONE << "\n";
145 # define LOG_SUCCESS(args) \
146 _Pragma("GCC warning \"This macro is deprecated, use mc_rtc::log::success instead\""); \
147 std::cout << mc_rtc::OUT_GREEN << args << mc_rtc::OUT_NONE << "\n";
149 # define LOG_ERROR_AND_THROW(exception_type, args) \
151 _Pragma("GCC warning \"This macro is deprecated, use mc_rtc::log::error_and_throw<exception_type> instead\""); \
152 std::stringstream strstrm; \
154 LOG_ERROR(strstrm.str()) \
155 throw exception_type(strstrm.str()); \
160 # include <windows.h>
163 static const HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
171 # define __MC_RTC_STR2__(x) #x
172 # define __MC_RTC_STR1__(x) __MC_RTC_STR2__(x)
173 # define __MC_RTC_PRAGMA_LOC__ __FILE__ "("__MC_RTC_STR1__(__LINE__) ") "
175 # define LOG_ERROR(args) \
176 __pragma(message(__MC_RTC_PRAGMA_LOC__ ": warning: this macro is deprecated, use mc_rtc::log::error instead")); \
177 SetConsoleTextAttribute(mc_rtc::hConsole, mc_rtc::OUT_RED); \
178 std::cerr << args << std::endl; \
179 SetConsoleTextAttribute(mc_rtc::hConsole, mc_rtc::OUT_NONE);
181 # define LOG_WARNING(args) \
182 __pragma(message(__MC_RTC_PRAGMA_LOC__ ": warning: this macro is deprecated, use mc_rtc::log::warning instead")); \
183 SetConsoleTextAttribute(mc_rtc::hConsole, mc_rtc::OUT_PURPLE); \
184 std::cerr << args << std::endl; \
185 SetConsoleTextAttribute(mc_rtc::hConsole, mc_rtc::OUT_NONE);
187 # define LOG_INFO(args) \
188 __pragma(message(__MC_RTC_PRAGMA_LOC__ ": warning: this macro is deprecated, use mc_rtc::log::info instead")); \
189 SetConsoleTextAttribute(mc_rtc::hConsole, mc_rtc::OUT_BLUE); \
190 std::cout << args << std::endl; \
191 SetConsoleTextAttribute(mc_rtc::hConsole, mc_rtc::OUT_NONE);
193 # define LOG_SUCCESS(args) \
194 __pragma(message(__MC_RTC_PRAGMA_LOC__ ": warning: this macro is deprecated, use mc_rtc::log::success instead")); \
195 SetConsoleTextAttribute(mc_rtc::hConsole, mc_rtc::OUT_GREEN); \
196 std::cout << args << std::endl; \
197 SetConsoleTextAttribute(mc_rtc::hConsole, mc_rtc::OUT_NONE);
199 # define LOG_ERROR_AND_THROW(exception_type, args) \
202 message(__MC_RTC_PRAGMA_LOC__ \
203 ": warning: this macro is deprecated, use mc_rtc::log::error_and_throw<exception_type> instead")); \
204 std::stringstream strstrm; \
206 LOG_ERROR(strstrm.str()) \
207 throw exception_type(strstrm.str()); \
#define MC_FMT_STREAMED(X)
Definition: logging.h:46
MC_RTC_UTILS_DLLAPI spdlog::logger & info()
MC_RTC_UTILS_DLLAPI spdlog::logger & success()
MC_RTC_UTILS_DLLAPI void disable_notifications()
MC_RTC_UTILS_DLLAPI void notify(const std::string &message)
MC_RTC_UTILS_DLLAPI spdlog::logger & cerr()
void info(Args &&... args)
Definition: logging.h:102
void error_and_throw(Args &&... args)
Definition: logging.h:74
void success(Args &&... args)
Definition: logging.h:108
void notify(Args &&... args)
Definition: logging.h:114
void critical(Args &&... args)
Definition: logging.h:84
void warning(Args &&... args)
Definition: logging.h:96
void error(Args &&... args)
Definition: logging.h:90
constexpr auto OUT_BLUE
Definition: logging.h:129
constexpr auto OUT_GREEN
Definition: logging.h:130
constexpr auto OUT_RED
Definition: logging.h:132
constexpr auto OUT_NONE
Definition: logging.h:128
constexpr auto OUT_PURPLE
Definition: logging.h:131
#define MC_RTC_UTILS_DLLAPI
Definition: utils_api.h:50