32 #ifndef ROSCONSOLE_ROSCONSOLE_H 33 #define ROSCONSOLE_ROSCONSOLE_H 45 #ifdef ROSCONSOLE_BACKEND_LOG4CXX 46 #include "log4cxx/level.h" 51 #ifdef ROS_BUILD_SHARED_LIBS // ros is being built around shared libraries 52 #ifdef rosconsole_EXPORTS // we are building a shared lib/dll 53 #define ROSCONSOLE_DECL ROS_HELPER_EXPORT 54 #else // we are using shared lib/dll 55 #define ROSCONSOLE_DECL ROS_HELPER_IMPORT 57 #else // ros is being built around static libraries 58 #define ROSCONSOLE_DECL 63 #define ROSCONSOLE_PRINTF_ATTRIBUTE(a, b) __attribute__ ((__format__ (__printf__, a, b))) 67 #ifndef ROSCONSOLE_PRINTF_ATTRIBUTE 68 #define ROSCONSOLE_PRINTF_ATTRIBUTE(a, b) 83 #ifdef ROSCONSOLE_BACKEND_LOG4CXX 106 virtual void log(::
ros::console::Level level,
const char* str,
const char* file,
const char*
function,
int line) = 0;
124 virtual std::string getString(
void*, ::
ros::console::Level,
const char*,
const char*,
const char*,
int) = 0;
131 void init(
const char* fmt);
132 void print(
void* logger_handle, ::
ros::console::Level level,
const char* str,
const char* file,
const char*
function,
int line);
159 const char* file,
int line,
163 const
std::stringstream& str, const
char* file,
int line, const
char* function);
196 const char*
function;
276 #if defined(_MSC_VER) 277 #define ROS_LIKELY(x) (x) 278 #define ROS_UNLIKELY(x) (x) 280 #define ROS_LIKELY(x) __builtin_expect((x),1) 281 #define ROS_UNLIKELY(x) __builtin_expect((x),0) 284 #if defined(_MSC_VER) 285 #define __ROSCONSOLE_FUNCTION__ __FUNCSIG__ 286 #elif defined(__GNUC__) 287 #define __ROSCONSOLE_FUNCTION__ __PRETTY_FUNCTION__ 289 #define __ROSCONSOLE_FUNCTION__ "" 293 #ifdef ROS_PACKAGE_NAME 294 #define ROSCONSOLE_PACKAGE_NAME ROS_PACKAGE_NAME 296 #define ROSCONSOLE_PACKAGE_NAME "unknown_package" 299 #define ROSCONSOLE_ROOT_LOGGER_NAME "ros" 300 #define ROSCONSOLE_NAME_PREFIX ROSCONSOLE_ROOT_LOGGER_NAME "." ROSCONSOLE_PACKAGE_NAME 301 #define ROSCONSOLE_DEFAULT_NAME ROSCONSOLE_NAME_PREFIX 304 #define ROSCONSOLE_SEVERITY_DEBUG 0 305 #define ROSCONSOLE_SEVERITY_INFO 1 306 #define ROSCONSOLE_SEVERITY_WARN 2 307 #define ROSCONSOLE_SEVERITY_ERROR 3 308 #define ROSCONSOLE_SEVERITY_FATAL 4 309 #define ROSCONSOLE_SEVERITY_NONE 5 316 #ifndef ROSCONSOLE_MIN_SEVERITY 317 #define ROSCONSOLE_MIN_SEVERITY ROSCONSOLE_SEVERITY_DEBUG 324 #define ROSCONSOLE_AUTOINIT \ 327 if (ROS_UNLIKELY(!::ros::console::g_initialized)) \ 329 ::ros::console::initialize(); \ 333 #define ROSCONSOLE_DEFINE_LOCATION(cond, level, name) \ 334 ROSCONSOLE_AUTOINIT; \ 335 static ::ros::console::LogLocation __rosconsole_define_location__loc = {false, false, ::ros::console::levels::Count, NULL}; \ 336 if (ROS_UNLIKELY(!__rosconsole_define_location__loc.initialized_)) \ 338 initializeLogLocation(&__rosconsole_define_location__loc, name, level); \ 340 if (ROS_UNLIKELY(__rosconsole_define_location__loc.level_ != level)) \ 342 setLogLocationLevel(&__rosconsole_define_location__loc, level); \ 343 checkLogLocationEnabled(&__rosconsole_define_location__loc); \ 345 bool __rosconsole_define_location__enabled = __rosconsole_define_location__loc.logger_enabled_ && (cond); 347 #define ROSCONSOLE_PRINT_AT_LOCATION_WITH_FILTER(filter, ...) \ 348 ::ros::console::print(filter, __rosconsole_define_location__loc.logger_, __rosconsole_define_location__loc.level_, __FILE__, __LINE__, __ROSCONSOLE_FUNCTION__, __VA_ARGS__) 350 #define ROSCONSOLE_PRINT_AT_LOCATION(...) \ 351 ROSCONSOLE_PRINT_AT_LOCATION_WITH_FILTER(NULL, __VA_ARGS__) 354 #define ROSCONSOLE_PRINT_STREAM_AT_LOCATION_WITH_FILTER(filter, args) \ 357 std::stringstream __rosconsole_print_stream_at_location_with_filter__ss__; \ 358 __rosconsole_print_stream_at_location_with_filter__ss__ << args; \ 359 ::ros::console::print(filter, __rosconsole_define_location__loc.logger_, __rosconsole_define_location__loc.level_, __rosconsole_print_stream_at_location_with_filter__ss__, __FILE__, __LINE__, __ROSCONSOLE_FUNCTION__); \ 362 #define ROSCONSOLE_PRINT_STREAM_AT_LOCATION(args) \ 363 ROSCONSOLE_PRINT_STREAM_AT_LOCATION_WITH_FILTER(NULL, args) 369 #define ROSCONSOLE_THROTTLE_CHECK(now, last, period) (ROS_UNLIKELY(last + period <= now) || ROS_UNLIKELY(now < last)) 380 #define ROS_LOG_COND(cond, level, name, ...) \ 383 ROSCONSOLE_DEFINE_LOCATION(cond, level, name); \ 385 if (ROS_UNLIKELY(__rosconsole_define_location__enabled)) \ 387 ROSCONSOLE_PRINT_AT_LOCATION(__VA_ARGS__); \ 400 #define ROS_LOG_STREAM_COND(cond, level, name, args) \ 403 ROSCONSOLE_DEFINE_LOCATION(cond, level, name); \ 404 if (ROS_UNLIKELY(__rosconsole_define_location__enabled)) \ 406 ROSCONSOLE_PRINT_STREAM_AT_LOCATION(args); \ 416 #define ROS_LOG_ONCE(level, name, ...) \ 419 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \ 420 static bool hit = false; \ 421 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && ROS_UNLIKELY(!hit)) \ 424 ROSCONSOLE_PRINT_AT_LOCATION(__VA_ARGS__); \ 435 #define ROS_LOG_STREAM_ONCE(level, name, args) \ 438 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \ 439 static bool __ros_log_stream_once__hit__ = false; \ 440 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && ROS_UNLIKELY(!__ros_log_stream_once__hit__)) \ 442 __ros_log_stream_once__hit__ = true; \ 443 ROSCONSOLE_PRINT_STREAM_AT_LOCATION(args); \ 454 #define ROS_LOG_THROTTLE(period, level, name, ...) \ 457 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \ 458 static double __ros_log_throttle_last_hit__ = 0.0; \ 459 double __ros_log_throttle_now__ = ::ros::Time::now().toSec(); \ 460 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && ROSCONSOLE_THROTTLE_CHECK(__ros_log_throttle_now__, __ros_log_throttle_last_hit__, period))\ 462 __ros_log_throttle_last_hit__ = __ros_log_throttle_now__; \ 463 ROSCONSOLE_PRINT_AT_LOCATION(__VA_ARGS__); \ 475 #define ROS_LOG_STREAM_THROTTLE(period, level, name, args) \ 478 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \ 479 static double __ros_log_stream_throttle__last_hit__ = 0.0; \ 480 double __ros_log_stream_throttle__now__ = ::ros::Time::now().toSec(); \ 481 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && \ 482 ROSCONSOLE_THROTTLE_CHECK(__ros_log_stream_throttle__now__, __ros_log_stream_throttle__last_hit__, period))\ 484 __ros_log_stream_throttle__last_hit__ = __ros_log_stream_throttle__now__; \ 485 ROSCONSOLE_PRINT_STREAM_AT_LOCATION(args); \ 496 #define ROS_LOG_DELAYED_THROTTLE(period, level, name, ...) \ 499 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \ 500 double __ros_log_delayed_throttle__now__ = ::ros::Time::now().toSec(); \ 501 static double __ros_log_delayed_throttle__last_hit__ = __ros_log_delayed_throttle__now__; \ 502 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && \ 503 ROSCONSOLE_THROTTLE_CHECK(__ros_log_delayed_throttle__now__, __ros_log_delayed_throttle__last_hit__, period))\ 505 __ros_log_delayed_throttle__last_hit__ = __ros_log_delayed_throttle__now__; \ 506 ROSCONSOLE_PRINT_AT_LOCATION(__VA_ARGS__); \ 518 #define ROS_LOG_STREAM_DELAYED_THROTTLE(period, level, name, args) \ 521 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \ 522 double __ros_log_stream_delayed_throttle__now__ = ::ros::Time::now().toSec(); \ 523 static double __ros_log_stream_delayed_throttle__last_hit__ = __ros_log_stream_delayed_throttle__now__; \ 524 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && \ 525 ROSCONSOLE_THROTTLE_CHECK(__ros_log_stream_delayed_throttle__now__, __ros_log_stream_delayed_throttle__last_hit__, period)) \ 527 __ros_log_stream_delayed_throttle__last_hit__ = __ros_log_stream_delayed_throttle__now__; \ 528 ROSCONSOLE_PRINT_STREAM_AT_LOCATION(args); \ 539 #define ROS_LOG_FILTER(filter, level, name, ...) \ 542 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \ 543 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && (filter)->isEnabled()) \ 545 ROSCONSOLE_PRINT_AT_LOCATION_WITH_FILTER(filter, __VA_ARGS__); \ 556 #define ROS_LOG_STREAM_FILTER(filter, level, name, args) \ 559 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \ 560 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && (filter)->isEnabled()) \ 562 ROSCONSOLE_PRINT_STREAM_AT_LOCATION_WITH_FILTER(filter, args); \ 572 #define ROS_LOG(level, name, ...) ROS_LOG_COND(true, level, name, __VA_ARGS__) 579 #define ROS_LOG_STREAM(level, name, args) ROS_LOG_STREAM_COND(true, level, name, args) 583 #endif // ROSCONSOLE_ROSCONSOLE_H ROSCONSOLE_DECL void registerLogLocation(LogLocation *loc)
Registers a logging location with the system.
log4cxx::LevelPtr g_level_lookup[levels::Count]
virtual bool isEnabled()
Returns whether or not the log statement should be printed. Called before the log arguments are evalu...
ROSCONSOLE_DECL void notifyLoggerLevelsChanged()
Tells the system that a logger's level has changed.
Base-class for filters. Filters allow full user-defined control over whether or not a message should ...
Parameter structure passed to FilterBase::isEnabled(...);. Includes both input and output parameters...
::ros::console::Level level_
ROSCONSOLE_DECL void initialize()
Don't call this directly. Performs any required initialization/configuration. Happens automatically w...
void * logger
[input/output] Handle identifying logger that this message will be output to. If changed, uses the new logger
ROSCONSOLE_DECL void setFixedFilterToken(const std::string &key, const std::string &val)
ROSCONSOLE_DECL bool get_loggers(std::map< std::string, levels::Level > &loggers)
const char * message
[input] The formatted message that will be output
ROSCONSOLE_DECL bool g_initialized
Only exported because the macros need it. Do not use directly.
ROSCONSOLE_DECL std::string formatToString(const char *fmt,...)
ROSCONSOLE_DECL void checkLogLocationEnabled(LogLocation *loc)
Internal.
ROSCONSOLE_DECL void deregister_appender(LogAppender *appender)
std::string out_message
[output] If set, writes this message instead of the original
boost::shared_ptr< Token > TokenPtr
Level level
[input/output] Severity level. If changed, uses the new level
ROSCONSOLE_DECL void vformatToBuffer(boost::shared_array< char > &buffer, size_t &buffer_size, const char *fmt, va_list args)
const char * file
[input] File the message came from
#define ROSCONSOLE_PRINTF_ATTRIBUTE(a, b)
ROSCONSOLE_DECL void initializeLogLocation(LogLocation *loc, const std::string &name, Level level)
Internal.
ROSCONSOLE_DECL void shutdown()
std::vector< TokenPtr > V_Token
int line
[input] Line the message came from
ROSCONSOLE_DECL std::string g_last_error_message
Only exported because the TopicManager need it. Do not use directly.
ROSCONSOLE_DECL bool set_logger_level(const std::string &name, levels::Level level)
ROSCONSOLE_DECL Formatter g_formatter
Only exported because the implementation need it. Do not use directly.
ROSCONSOLE_DECL void setLogLocationLevel(LogLocation *loc, Level level)
Internal.
ROSCONSOLE_DECL void register_appender(LogAppender *appender)
void print(ros::console::Level level, const std::string &s)
virtual bool isEnabled(FilterParams &)
Returns whether or not the log statement should be printed. Called once the message has been formatte...
ROSCONSOLE_DECL void formatToBuffer(boost::shared_array< char > &buffer, size_t &buffer_size, const char *fmt,...)