11 #include <spdlog/fmt/fmt.h>
12 #include <spdlog/fmt/ostr.h>
13 #include <spdlog/logger.h>
15 #define BOOST_STACKTRACE_LINK
16 #include <boost/stacktrace.hpp>
39 template<
typename ExceptionT = std::runtime_error,
typename S,
typename... Args>
43 if constexpr(
sizeof...(Args) == 0) {
message = fmt::format(
"{}", format); }
46 message = fmt::format(fmt::runtime(format), std::forward<Args>(args)...);
50 details::cerr().critical(
"=== Backtrace ===\n{}", MC_FMT_STREAMED(boost::stacktrace::stacktrace()));
54 template<
typename S,
typename... Args>
55 void critical(
const S & format, Args &&... args)
57 if constexpr(
sizeof...(Args) == 0) {
details::cerr().critical(format); }
60 details::cerr().critical(fmt::runtime(format), std::forward<Args>(args)...);
64 template<
typename S,
typename... Args>
65 void error(
const S & format, Args &&... args)
67 if constexpr(
sizeof...(Args) == 0) {
details::cerr().error(format); }
70 details::cerr().error(fmt::runtime(format), std::forward<Args>(args)...);
74 template<
typename S,
typename... Args>
75 void warning(
const S & format, Args &&... args)
77 if constexpr(
sizeof...(Args) == 0) {
details::cerr().warn(format); }
80 details::cerr().warn(fmt::runtime(format), std::forward<Args>(args)...);
84 template<
typename S,
typename... Args>
85 void info(
const S & format, Args &&... args)
87 if constexpr(
sizeof...(Args) == 0) {
details::info().info(format); }
90 details::info().info(fmt::runtime(format), std::forward<Args>(args)...);
94 template<
typename S,
typename... Args>
95 void success(
const S & format, Args &&... args)
104 template<
typename S,
typename... Args>
105 void notify(
const S & format, Args &&... args)
107 if constexpr(
sizeof...(Args) == 0) {
details::notify(fmt::format(
"{}", format)); }
110 details::notify(fmt::format(fmt::runtime(format), std::forward<Args>(args)...));
131 # define LOG_ERROR(args) \
132 _Pragma("GCC warning \"This macro is deprecated, use mc_rtc::log::error instead\""); \
133 std::cerr << mc_rtc::OUT_RED << args << mc_rtc::OUT_NONE << "\n";
134 # define LOG_WARNING(args) \
135 _Pragma("GCC warning \"This macro is deprecated, use mc_rtc::log::warning instead\""); \
136 std::cerr << mc_rtc::OUT_PURPLE << args << mc_rtc::OUT_NONE << "\n";
137 # define LOG_INFO(args) \
138 _Pragma("GCC warning \"This macro is deprecated, use mc_rtc::log::info instead\""); \
139 std::cout << mc_rtc::OUT_BLUE << args << mc_rtc::OUT_NONE << "\n";
140 # define LOG_SUCCESS(args) \
141 _Pragma("GCC warning \"This macro is deprecated, use mc_rtc::log::success instead\""); \
142 std::cout << mc_rtc::OUT_GREEN << args << mc_rtc::OUT_NONE << "\n";
144 # define LOG_ERROR_AND_THROW(exception_type, args) \
146 _Pragma("GCC warning \"This macro is deprecated, use mc_rtc::log::error_and_throw<exception_type> instead\""); \
147 std::stringstream strstrm; \
149 LOG_ERROR(strstrm.str()) \
150 throw exception_type(strstrm.str()); \
155 # include <windows.h>
158 static const HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
166 # define __MC_RTC_STR2__(x) #x
167 # define __MC_RTC_STR1__(x) __MC_RTC_STR2__(x)
168 # define __MC_RTC_PRAGMA_LOC__ __FILE__ "("__MC_RTC_STR1__(__LINE__) ") "
170 # define LOG_ERROR(args) \
171 __pragma(message(__MC_RTC_PRAGMA_LOC__ ": warning: this macro is deprecated, use mc_rtc::log::error instead")); \
172 SetConsoleTextAttribute(mc_rtc::hConsole, mc_rtc::OUT_RED); \
173 std::cerr << args << std::endl; \
174 SetConsoleTextAttribute(mc_rtc::hConsole, mc_rtc::OUT_NONE);
176 # define LOG_WARNING(args) \
177 __pragma(message(__MC_RTC_PRAGMA_LOC__ ": warning: this macro is deprecated, use mc_rtc::log::warning instead")); \
178 SetConsoleTextAttribute(mc_rtc::hConsole, mc_rtc::OUT_PURPLE); \
179 std::cerr << args << std::endl; \
180 SetConsoleTextAttribute(mc_rtc::hConsole, mc_rtc::OUT_NONE);
182 # define LOG_INFO(args) \
183 __pragma(message(__MC_RTC_PRAGMA_LOC__ ": warning: this macro is deprecated, use mc_rtc::log::info instead")); \
184 SetConsoleTextAttribute(mc_rtc::hConsole, mc_rtc::OUT_BLUE); \
185 std::cout << args << std::endl; \
186 SetConsoleTextAttribute(mc_rtc::hConsole, mc_rtc::OUT_NONE);
188 # define LOG_SUCCESS(args) \
189 __pragma(message(__MC_RTC_PRAGMA_LOC__ ": warning: this macro is deprecated, use mc_rtc::log::success instead")); \
190 SetConsoleTextAttribute(mc_rtc::hConsole, mc_rtc::OUT_GREEN); \
191 std::cout << args << std::endl; \
192 SetConsoleTextAttribute(mc_rtc::hConsole, mc_rtc::OUT_NONE);
194 # define LOG_ERROR_AND_THROW(exception_type, args) \
197 message(__MC_RTC_PRAGMA_LOC__ \
198 ": warning: this macro is deprecated, use mc_rtc::log::error_and_throw<exception_type> instead")); \
199 std::stringstream strstrm; \
201 LOG_ERROR(strstrm.str()) \
202 throw exception_type(strstrm.str()); \
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 notify(const S &format, Args &&... args)
Definition: logging.h:105
void error_and_throw(const S &format, Args &&... args)
Definition: logging.h:40
void critical(const S &format, Args &&... args)
Definition: logging.h:55
void warning(const S &format, Args &&... args)
Definition: logging.h:75
void info(const S &format, Args &&... args)
Definition: logging.h:85
void error(const S &format, Args &&... args)
Definition: logging.h:65
void success(const S &format, Args &&... args)
Definition: logging.h:95
constexpr auto OUT_BLUE
Definition: logging.h:124
constexpr auto OUT_GREEN
Definition: logging.h:125
constexpr auto OUT_RED
Definition: logging.h:127
constexpr auto OUT_NONE
Definition: logging.h:123
constexpr auto OUT_PURPLE
Definition: logging.h:126
#define MC_RTC_UTILS_DLLAPI
Definition: utils_api.h:50