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;
122 virtual std::string getString(
void*, ::
ros::console::Level,
const char*,
const char*,
const char*,
int) = 0;
129 void init(
const char* fmt);
130 void print(
void* logger_handle, ::
ros::console::Level level,
const char* str,
const char* file,
const char*
function,
int line);
157 const char* file,
int line,
161 const
std::stringstream& str, const
char* file,
int line, const
char* function);
194 const char*
function;
275 #define ROS_LIKELY(x) (x) 276 #define ROS_UNLIKELY(x) (x) 278 #define ROS_LIKELY(x) __builtin_expect((x),1) 279 #define ROS_UNLIKELY(x) __builtin_expect((x),0) 283 #define __ROSCONSOLE_FUNCTION__ __FUNCSIG__ 284 #elif defined(__GNUC__) 285 #define __ROSCONSOLE_FUNCTION__ __PRETTY_FUNCTION__ 287 #define __ROSCONSOLE_FUNCTION__ "" 291 #ifdef ROS_PACKAGE_NAME 292 #define ROSCONSOLE_PACKAGE_NAME ROS_PACKAGE_NAME 294 #define ROSCONSOLE_PACKAGE_NAME "unknown_package" 297 #define ROSCONSOLE_ROOT_LOGGER_NAME "ros" 298 #define ROSCONSOLE_NAME_PREFIX ROSCONSOLE_ROOT_LOGGER_NAME "." ROSCONSOLE_PACKAGE_NAME 299 #define ROSCONSOLE_DEFAULT_NAME ROSCONSOLE_NAME_PREFIX 302 #define ROSCONSOLE_SEVERITY_DEBUG 0 303 #define ROSCONSOLE_SEVERITY_INFO 1 304 #define ROSCONSOLE_SEVERITY_WARN 2 305 #define ROSCONSOLE_SEVERITY_ERROR 3 306 #define ROSCONSOLE_SEVERITY_FATAL 4 307 #define ROSCONSOLE_SEVERITY_NONE 5 314 #ifndef ROSCONSOLE_MIN_SEVERITY 315 #define ROSCONSOLE_MIN_SEVERITY ROSCONSOLE_SEVERITY_DEBUG 322 #define ROSCONSOLE_AUTOINIT \ 325 if (ROS_UNLIKELY(!::ros::console::g_initialized)) \ 327 ::ros::console::initialize(); \ 331 #define ROSCONSOLE_DEFINE_LOCATION(cond, level, name) \ 332 ROSCONSOLE_AUTOINIT; \ 333 static ::ros::console::LogLocation __rosconsole_define_location__loc = {false, false, ::ros::console::levels::Count, 0}; \ 334 if (ROS_UNLIKELY(!__rosconsole_define_location__loc.initialized_)) \ 336 initializeLogLocation(&__rosconsole_define_location__loc, name, level); \ 338 if (ROS_UNLIKELY(__rosconsole_define_location__loc.level_ != level)) \ 340 setLogLocationLevel(&__rosconsole_define_location__loc, level); \ 341 checkLogLocationEnabled(&__rosconsole_define_location__loc); \ 343 bool __rosconsole_define_location__enabled = __rosconsole_define_location__loc.logger_enabled_ && (cond); 345 #define ROSCONSOLE_PRINT_AT_LOCATION_WITH_FILTER(filter, ...) \ 346 ::ros::console::print(filter, __rosconsole_define_location__loc.logger_, __rosconsole_define_location__loc.level_, __FILE__, __LINE__, __ROSCONSOLE_FUNCTION__, __VA_ARGS__) 348 #define ROSCONSOLE_PRINT_AT_LOCATION(...) \ 349 ROSCONSOLE_PRINT_AT_LOCATION_WITH_FILTER(0, __VA_ARGS__) 352 #define ROSCONSOLE_PRINT_STREAM_AT_LOCATION_WITH_FILTER(filter, args) \ 355 std::stringstream __rosconsole_print_stream_at_location_with_filter__ss__; \ 356 __rosconsole_print_stream_at_location_with_filter__ss__ << args; \ 357 ::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__); \ 360 #define ROSCONSOLE_PRINT_STREAM_AT_LOCATION(args) \ 361 ROSCONSOLE_PRINT_STREAM_AT_LOCATION_WITH_FILTER(0, args) 372 #define ROS_LOG_COND(cond, level, name, ...) \ 375 ROSCONSOLE_DEFINE_LOCATION(cond, level, name); \ 377 if (ROS_UNLIKELY(__rosconsole_define_location__enabled)) \ 379 ROSCONSOLE_PRINT_AT_LOCATION(__VA_ARGS__); \ 392 #define ROS_LOG_STREAM_COND(cond, level, name, args) \ 395 ROSCONSOLE_DEFINE_LOCATION(cond, level, name); \ 396 if (ROS_UNLIKELY(__rosconsole_define_location__enabled)) \ 398 ROSCONSOLE_PRINT_STREAM_AT_LOCATION(args); \ 408 #define ROS_LOG_ONCE(level, name, ...) \ 411 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \ 412 static bool hit = false; \ 413 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && ROS_UNLIKELY(!hit)) \ 416 ROSCONSOLE_PRINT_AT_LOCATION(__VA_ARGS__); \ 427 #define ROS_LOG_STREAM_ONCE(level, name, args) \ 430 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \ 431 static bool __ros_log_stream_once__hit__ = false; \ 432 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && ROS_UNLIKELY(!__ros_log_stream_once__hit__)) \ 434 __ros_log_stream_once__hit__ = true; \ 435 ROSCONSOLE_PRINT_STREAM_AT_LOCATION(args); \ 446 #define ROS_LOG_THROTTLE(period, level, name, ...) \ 449 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \ 450 static double last_hit = 0.0; \ 451 ::ros::Time now = ::ros::Time::now(); \ 452 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && ROS_UNLIKELY(last_hit + period <= now.toSec())) \ 454 last_hit = now.toSec(); \ 455 ROSCONSOLE_PRINT_AT_LOCATION(__VA_ARGS__); \ 467 #define ROS_LOG_STREAM_THROTTLE(period, level, name, args) \ 470 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \ 471 static double __ros_log_stream_throttle__last_hit__ = 0.0; \ 472 ::ros::Time __ros_log_stream_throttle__now__ = ::ros::Time::now(); \ 473 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && ROS_UNLIKELY(__ros_log_stream_throttle__last_hit__ + period <= __ros_log_stream_throttle__now__.toSec())) \ 475 __ros_log_stream_throttle__last_hit__ = __ros_log_stream_throttle__now__.toSec(); \ 476 ROSCONSOLE_PRINT_STREAM_AT_LOCATION(args); \ 487 #define ROS_LOG_DELAYED_THROTTLE(period, level, name, ...) \ 490 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \ 491 ::ros::Time __ros_log_delayed_throttle__now__ = ::ros::Time::now(); \ 492 static double __ros_log_delayed_throttle__last_hit__ = __ros_log_delayed_throttle__now__.toSec(); \ 493 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && ROS_UNLIKELY(__ros_log_delayed_throttle__last_hit__ + period <= __ros_log_delayed_throttle__now__.toSec())) \ 495 __ros_log_delayed_throttle__last_hit__ = __ros_log_delayed_throttle__now__.toSec(); \ 496 ROSCONSOLE_PRINT_AT_LOCATION(__VA_ARGS__); \ 508 #define ROS_LOG_STREAM_DELAYED_THROTTLE(period, level, name, args) \ 511 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \ 512 ::ros::Time __ros_log_stream_delayed_throttle__now__ = ::ros::Time::now(); \ 513 static double __ros_log_stream_delayed_throttle__last_hit__ = __ros_log_stream_delayed_throttle__now__.toSec(); \ 514 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && ROS_UNLIKELY(__ros_log_stream_delayed_throttle__last_hit__ + period <= __ros_log_stream_delayed_throttle__now__.toSec())) \ 516 __ros_log_stream_delayed_throttle__last_hit__ = __ros_log_stream_delayed_throttle__now__.toSec(); \ 517 ROSCONSOLE_PRINT_STREAM_AT_LOCATION(args); \ 528 #define ROS_LOG_FILTER(filter, level, name, ...) \ 531 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \ 532 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && (filter)->isEnabled()) \ 534 ROSCONSOLE_PRINT_AT_LOCATION_WITH_FILTER(filter, __VA_ARGS__); \ 545 #define ROS_LOG_STREAM_FILTER(filter, level, name, args) \ 548 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \ 549 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && (filter)->isEnabled()) \ 551 ROSCONSOLE_PRINT_STREAM_AT_LOCATION_WITH_FILTER(filter, args); \ 561 #define ROS_LOG(level, name, ...) ROS_LOG_COND(true, level, name, __VA_ARGS__) 568 #define ROS_LOG_STREAM(level, name, args) ROS_LOG_STREAM_COND(true, level, name, args) 572 #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.
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,...)