Go to the documentation of this file.
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;
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);
135 const char *file,
const char *
function,
int line)
const;
162 const char* file,
int line,
166 const
std::stringstream& str, const
char* file,
int line, const
char* function);
199 const char*
function;
279 #if defined(_MSC_VER)
280 #define ROS_LIKELY(x) (x)
281 #define ROS_UNLIKELY(x) (x)
283 #define ROS_LIKELY(x) __builtin_expect((x),1)
284 #define ROS_UNLIKELY(x) __builtin_expect((x),0)
287 #if defined(_MSC_VER)
288 #define __ROSCONSOLE_FUNCTION__ __FUNCSIG__
289 #elif defined(__GNUC__)
290 #define __ROSCONSOLE_FUNCTION__ __PRETTY_FUNCTION__
292 #define __ROSCONSOLE_FUNCTION__ ""
296 #ifdef ROS_PACKAGE_NAME
297 #define ROSCONSOLE_PACKAGE_NAME ROS_PACKAGE_NAME
299 #define ROSCONSOLE_PACKAGE_NAME "unknown_package"
302 #define ROSCONSOLE_ROOT_LOGGER_NAME "ros"
303 #define ROSCONSOLE_NAME_PREFIX ROSCONSOLE_ROOT_LOGGER_NAME "." ROSCONSOLE_PACKAGE_NAME
304 #define ROSCONSOLE_DEFAULT_NAME ROSCONSOLE_NAME_PREFIX
307 #define ROSCONSOLE_SEVERITY_DEBUG 0
308 #define ROSCONSOLE_SEVERITY_INFO 1
309 #define ROSCONSOLE_SEVERITY_WARN 2
310 #define ROSCONSOLE_SEVERITY_ERROR 3
311 #define ROSCONSOLE_SEVERITY_FATAL 4
312 #define ROSCONSOLE_SEVERITY_NONE 5
319 #ifndef ROSCONSOLE_MIN_SEVERITY
320 #define ROSCONSOLE_MIN_SEVERITY ROSCONSOLE_SEVERITY_DEBUG
327 #define ROSCONSOLE_AUTOINIT \
330 if (ROS_UNLIKELY(!::ros::console::g_initialized)) \
332 ::ros::console::initialize(); \
336 #define ROSCONSOLE_DEFINE_LOCATION(cond, level, name) \
337 ROSCONSOLE_AUTOINIT; \
338 static ::ros::console::LogLocation __rosconsole_define_location__loc = {false, false, ::ros::console::levels::Count, NULL}; \
339 if (ROS_UNLIKELY(!__rosconsole_define_location__loc.initialized_)) \
341 initializeLogLocation(&__rosconsole_define_location__loc, name, level); \
343 if (ROS_UNLIKELY(__rosconsole_define_location__loc.level_ != level)) \
345 setLogLocationLevel(&__rosconsole_define_location__loc, level); \
346 checkLogLocationEnabled(&__rosconsole_define_location__loc); \
348 bool __rosconsole_define_location__enabled = __rosconsole_define_location__loc.logger_enabled_ && (cond);
350 #define ROSCONSOLE_PRINT_AT_LOCATION_WITH_FILTER(filter, ...) \
351 ::ros::console::print(filter, __rosconsole_define_location__loc.logger_, __rosconsole_define_location__loc.level_, __FILE__, __LINE__, __ROSCONSOLE_FUNCTION__, __VA_ARGS__)
353 #define ROSCONSOLE_PRINT_AT_LOCATION(...) \
354 ROSCONSOLE_PRINT_AT_LOCATION_WITH_FILTER(NULL, __VA_ARGS__)
357 #define ROSCONSOLE_PRINT_STREAM_AT_LOCATION_WITH_FILTER(filter, args) \
360 std::stringstream __rosconsole_print_stream_at_location_with_filter__ss__; \
361 __rosconsole_print_stream_at_location_with_filter__ss__ << args; \
362 ::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__); \
365 #define ROSCONSOLE_PRINT_STREAM_AT_LOCATION(args) \
366 ROSCONSOLE_PRINT_STREAM_AT_LOCATION_WITH_FILTER(NULL, args)
372 #define ROSCONSOLE_THROTTLE_CHECK(now, last, period) (ROS_UNLIKELY(last + period <= now) || ROS_UNLIKELY(now < last))
383 #define ROS_LOG_COND(cond, level, name, ...) \
386 ROSCONSOLE_DEFINE_LOCATION(cond, level, name); \
388 if (ROS_UNLIKELY(__rosconsole_define_location__enabled)) \
390 ROSCONSOLE_PRINT_AT_LOCATION(__VA_ARGS__); \
403 #define ROS_LOG_STREAM_COND(cond, level, name, args) \
406 ROSCONSOLE_DEFINE_LOCATION(cond, level, name); \
407 if (ROS_UNLIKELY(__rosconsole_define_location__enabled)) \
409 ROSCONSOLE_PRINT_STREAM_AT_LOCATION(args); \
419 #define ROS_LOG_ONCE(level, name, ...) \
422 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \
423 static bool hit = false; \
424 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && ROS_UNLIKELY(!hit)) \
427 ROSCONSOLE_PRINT_AT_LOCATION(__VA_ARGS__); \
438 #define ROS_LOG_STREAM_ONCE(level, name, args) \
441 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \
442 static bool __ros_log_stream_once__hit__ = false; \
443 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && ROS_UNLIKELY(!__ros_log_stream_once__hit__)) \
445 __ros_log_stream_once__hit__ = true; \
446 ROSCONSOLE_PRINT_STREAM_AT_LOCATION(args); \
457 #define ROS_LOG_THROTTLE(period, level, name, ...) \
460 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \
461 static double __ros_log_throttle_last_hit__ = 0.0; \
462 double __ros_log_throttle_now__ = ::ros::Time::now().toSec(); \
463 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && ROSCONSOLE_THROTTLE_CHECK(__ros_log_throttle_now__, __ros_log_throttle_last_hit__, period))\
465 __ros_log_throttle_last_hit__ = __ros_log_throttle_now__; \
466 ROSCONSOLE_PRINT_AT_LOCATION(__VA_ARGS__); \
478 #define ROS_LOG_STREAM_THROTTLE(period, level, name, args) \
481 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \
482 static double __ros_log_stream_throttle__last_hit__ = 0.0; \
483 double __ros_log_stream_throttle__now__ = ::ros::Time::now().toSec(); \
484 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && \
485 ROSCONSOLE_THROTTLE_CHECK(__ros_log_stream_throttle__now__, __ros_log_stream_throttle__last_hit__, period))\
487 __ros_log_stream_throttle__last_hit__ = __ros_log_stream_throttle__now__; \
488 ROSCONSOLE_PRINT_STREAM_AT_LOCATION(args); \
499 #define ROS_LOG_DELAYED_THROTTLE(period, level, name, ...) \
502 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \
503 double __ros_log_delayed_throttle__now__ = ::ros::Time::now().toSec(); \
504 static double __ros_log_delayed_throttle__last_hit__ = __ros_log_delayed_throttle__now__; \
505 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && \
506 ROSCONSOLE_THROTTLE_CHECK(__ros_log_delayed_throttle__now__, __ros_log_delayed_throttle__last_hit__, period))\
508 __ros_log_delayed_throttle__last_hit__ = __ros_log_delayed_throttle__now__; \
509 ROSCONSOLE_PRINT_AT_LOCATION(__VA_ARGS__); \
521 #define ROS_LOG_STREAM_DELAYED_THROTTLE(period, level, name, args) \
524 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \
525 double __ros_log_stream_delayed_throttle__now__ = ::ros::Time::now().toSec(); \
526 static double __ros_log_stream_delayed_throttle__last_hit__ = __ros_log_stream_delayed_throttle__now__; \
527 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && \
528 ROSCONSOLE_THROTTLE_CHECK(__ros_log_stream_delayed_throttle__now__, __ros_log_stream_delayed_throttle__last_hit__, period)) \
530 __ros_log_stream_delayed_throttle__last_hit__ = __ros_log_stream_delayed_throttle__now__; \
531 ROSCONSOLE_PRINT_STREAM_AT_LOCATION(args); \
542 #define ROS_LOG_FILTER(filter, level, name, ...) \
545 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \
546 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && (filter)->isEnabled()) \
548 ROSCONSOLE_PRINT_AT_LOCATION_WITH_FILTER(filter, __VA_ARGS__); \
559 #define ROS_LOG_STREAM_FILTER(filter, level, name, args) \
562 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \
563 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && (filter)->isEnabled()) \
565 ROSCONSOLE_PRINT_STREAM_AT_LOCATION_WITH_FILTER(filter, args); \
575 #define ROS_LOG(level, name, ...) ROS_LOG_COND(true, level, name, __VA_ARGS__)
582 #define ROS_LOG_STREAM(level, name, args) ROS_LOG_STREAM_COND(true, level, name, args)
586 #endif // ROSCONSOLE_ROSCONSOLE_H
::ros::console::Level level_
const char * file
[input] File the message came from
ROSCONSOLE_DECL void deregister_appender(LogAppender *appender)
ROSCONSOLE_DECL void vformatToBuffer(boost::shared_array< char > &buffer, size_t &buffer_size, const char *fmt, va_list args)
Level level
[input/output] Severity level. If changed, uses the new level
int line
[input] Line the message came from
struct ROSCONSOLE_DECL LogLocation
std::vector< TokenPtr > V_Token
ROSCONSOLE_DECL void initializeLogLocation(LogLocation *loc, const std::string &name, Level level)
Internal.
ROSCONSOLE_DECL bool set_logger_level(const std::string &name, levels::Level level)
Base-class for filters. Filters allow full user-defined control over whether or not a message should ...
ROSCONSOLE_DECL std::string g_last_error_message
Only exported because the TopicManager need it. Do not use directly.
ROSCONSOLE_DECL void setLogLocationLevel(LogLocation *loc, Level level)
Internal.
ROSCONSOLE_DECL void register_appender(LogAppender *appender)
void * logger
[input/output] Handle identifying logger that this message will be output to. If changed,...
ROSCONSOLE_DECL void shutdown()
ROSCONSOLE_DECL Formatter g_formatter
Only exported because the implementation need it. Do not use directly.
ROSCONSOLE_DECL void formatToBuffer(boost::shared_array< char > &buffer, size_t &buffer_size, const char *fmt,...)
ROSCONSOLE_DECL void registerLogLocation(LogLocation *loc)
Registers a logging location with the system.
ROSCONSOLE_DECL void setFixedFilterToken(const std::string &key, const std::string &val)
#define ROSCONSOLE_PRINTF_ATTRIBUTE(a, b)
std::string out_message
[output] If set, writes this message instead of the original
ROSCONSOLE_DECL void checkLogLocationEnabled(LogLocation *loc)
Internal.
virtual std::string getString(void *, ::ros::console::Level, const char *, const char *, const char *, int)=0
ROSCONSOLE_DECL void notifyLoggerLevelsChanged()
Tells the system that a logger's level has changed.
log4cxx::LevelPtr g_level_lookup[levels::Count]
const char * message
[input] The formatted message that will be output
ROSCONSOLE_DECL void initialize()
Don't call this directly. Performs any required initialization/configuration. Happens automatically w...
ROSCONSOLE_DECL std::string formatToString(const char *fmt,...)
virtual bool isEnabled(FilterParams &)
Returns whether or not the log statement should be printed. Called once the message has been formatte...
Parameter structure passed to FilterBase::isEnabled(...);. Includes both input and output parameters.
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
Don't call this directly. Use the ROS_LOG() macro instead.
virtual void log(::ros::console::Level level, const char *str, const char *file, const char *function, int line)=0
ROSCONSOLE_DECL bool get_loggers(std::map< std::string, levels::Level > &loggers)
ROSCONSOLE_DECL bool g_initialized
Only exported because the macros need it. Do not use directly.
boost::shared_ptr< Token > TokenPtr
virtual bool isEnabled()
Returns whether or not the log statement should be printed. Called before the log arguments are evalu...
rosconsole
Author(s): Josh Faust
autogenerated on Wed Mar 2 2022 00:53:52