7 #if __cplusplus < 201103L 8 #error rosfmt needs C++11 support. Suggestion: add "set(CMAKE_CXX_STANDARD 11)" \ 9 to your CMakeLists.txt. 15 #include <fmt/format.h> 22 template<
typename... Args>
25 const char* file,
int line,
const char*
function,
26 const std::string& format,
const Args&... args)
28 std::string
s = fmt::format(format, args...);
36 #define ROSFMT_PRINT_AT_LOCATION_WITH_FILTER(filter, ...) \ 37 ::rosfmt::print(filter, __rosconsole_define_location__loc.logger_, __rosconsole_define_location__loc.level_, __FILE__, __LINE__, __ROSCONSOLE_FUNCTION__, __VA_ARGS__) 39 #define ROSFMT_PRINT_AT_LOCATION(...) \ 40 ROSFMT_PRINT_AT_LOCATION_WITH_FILTER(NULL, __VA_ARGS__) 51 #define ROSFMT_LOG_COND(cond, level, name, ...) \ 54 ROSCONSOLE_DEFINE_LOCATION(cond, level, name); \ 56 if (ROS_UNLIKELY(__rosconsole_define_location__enabled)) \ 58 ROSFMT_PRINT_AT_LOCATION(__VA_ARGS__); \ 68 #define ROSFMT_LOG_ONCE(level, name, ...) \ 71 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \ 72 static bool hit = false; \ 73 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && ROS_UNLIKELY(!hit)) \ 76 ROSFMT_PRINT_AT_LOCATION(__VA_ARGS__); \ 87 #define ROSFMT_LOG_THROTTLE(period, level, name, ...) \ 90 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \ 91 static double last_hit = 0.0; \ 92 ::ros::Time now = ::ros::Time::now(); \ 93 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && ROS_UNLIKELY(last_hit + period <= now.toSec())) \ 95 last_hit = now.toSec(); \ 96 ROSFMT_PRINT_AT_LOCATION(__VA_ARGS__); \ 107 #define ROSFMT_LOG_DELAYED_THROTTLE(period, level, name, ...) \ 110 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \ 111 ::ros::Time __ros_log_delayed_throttle__now__ = ::ros::Time::now(); \ 112 static double __ros_log_delayed_throttle__last_hit__ = __ros_log_delayed_throttle__now__.toSec(); \ 113 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && ROS_UNLIKELY(__ros_log_delayed_throttle__last_hit__ + period <= __ros_log_delayed_throttle__now__.toSec())) \ 115 __ros_log_delayed_throttle__last_hit__ = __ros_log_delayed_throttle__now__.toSec(); \ 116 ROSFMT_PRINT_AT_LOCATION(__VA_ARGS__); \ 127 #define ROSFMT_LOG_FILTER(filter, level, name, ...) \ 130 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \ 131 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && (filter)->isEnabled()) \ 133 ROSFMT_PRINT_AT_LOCATION_WITH_FILTER(filter, __VA_ARGS__); \ 143 #define ROSFMT_LOG(level, name, ...) ROSFMT_LOG_COND(true, level, name, __VA_ARGS__) 145 #include "macros_generated.h" 149 #endif // include guard
ROSCONSOLE_DECL void print(FilterBase *filter, void *logger, Level level, const char *file, int line, const char *function, const char *fmt,...) ROSCONSOLE_PRINTF_ATTRIBUTE(7