Go to the documentation of this file.
32 #if defined(__APPLE__) && defined(__GNUC__) && defined(__llvm__) && !defined(__clang__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 2)
33 #error This code is known to provoke a compiler crash with llvm-gcc 4.2. You will have better luck with clang++. See code.ros.org/trac/ros/ticket/3626
41 #include <boost/thread.hpp>
42 #include <boost/shared_array.hpp>
43 #include <boost/regex.hpp>
44 #include <boost/make_shared.hpp>
45 #include <boost/date_time/posix_time/posix_time.hpp>
64 #ifdef ROSCONSOLE_BACKEND_LOG4CXX
67 log4cxx::Level::getDebug(),
68 log4cxx::Level::getInfo(),
69 log4cxx::Level::getWarn(),
70 log4cxx::Level::getError(),
71 log4cxx::Level::getFatal(),
77 #define COLOR_NORMAL ""
79 #define COLOR_GREEN ""
80 #define COLOR_YELLOW ""
82 #define COLOR_NORMAL "\033[0m"
83 #define COLOR_RED "\033[31m"
84 #define COLOR_GREEN "\033[32m"
85 #define COLOR_YELLOW "\033[33m"
93 typedef std::map<std::string, std::string>
M_string;
126 return (
"${" +
str_ +
"}").c_str();
129 return it->second.c_str();
139 return "PLACEHOLDER";
190 std::stringstream ss;
198 boost::posix_time::time_facet *facet =
new boost::posix_time::time_facet();
199 facet->format(
format_.c_str());
200 ss.imbue(std::locale(std::locale::classic(), facet));
229 std::stringstream ss;
237 boost::posix_time::time_facet* facet =
new boost::posix_time::time_facet();
238 facet->format(
format_.c_str());
239 ss.imbue(std::locale(std::locale::classic(), facet));
253 std::stringstream ss;
254 ss << boost::this_thread::get_id();
292 std::stringstream ss;
300 if (type ==
"severity")
302 return TokenPtr(boost::make_shared<SeverityToken>());
304 else if (type ==
"message")
306 return TokenPtr(boost::make_shared<MessageToken>());
308 else if (type ==
"time" || strncmp(type.c_str(), std::string(
"time:").c_str(), std::string(
"time:").size()) == 0)
312 std::size_t found = type.find(
':');
313 if (found != std::string::npos)
315 format = type.substr(found + 1, type.size());
318 return TokenPtr(boost::make_shared<TimeToken>(format));
320 else if (type ==
"walltime" || strncmp(type.c_str(), std::string(
"walltime:").c_str(), std::string(
"walltime:").size()) == 0)
324 std::size_t found = type.find(
':');
325 if (found != std::string::npos)
327 format = type.substr(found + 1, type.size());
330 return TokenPtr(boost::make_shared<WallTimeToken>(format));
332 else if (type ==
"thread")
334 return TokenPtr(boost::make_shared<ThreadToken>());
336 else if (type ==
"logger")
338 return TokenPtr(boost::make_shared<LoggerToken>());
340 else if (type ==
"file")
342 return TokenPtr(boost::make_shared<FileToken>());
344 else if (type ==
"line")
346 return TokenPtr(boost::make_shared<LineToken>());
348 else if (type ==
"function")
350 return TokenPtr(boost::make_shared<FunctionToken>());
353 return TokenPtr(boost::make_shared<FixedMapToken>(type));
360 boost::regex e(
"\\$\\{([^\\}]+)\\}");
361 boost::match_results<std::string::const_iterator> results;
362 std::string::const_iterator start, end;
365 bool matched_once =
false;
366 std::string last_suffix;
367 while (boost::regex_search(start, end, results, e))
370 for (
size_t i = 0; i < results.size(); ++i)
372 std::cout << i <<
"|" << results.prefix() <<
"|" << results[i] <<
"|" << results.suffix() << std::endl;
376 std::string token = results[1];
377 last_suffix = results.suffix();
378 tokens_.push_back(
TokenPtr(boost::make_shared<FixedToken>(results.prefix())));
381 start = results[0].second;
387 tokens_.push_back(
TokenPtr(boost::make_shared<FixedToken>(last_suffix)));
424 std::stringstream ss;
429 ss <<
getTokenStrings(logger_handle, level, str, file,
function, line);
435 fprintf(
f,
"%s\n", ss.str().c_str());
439 int flush_result = fflush(
f);
443 fprintf(stderr,
"Error: failed to perform fflush on stdout, fflush return code is %d\n", flush_result);
450 const char *
function,
int line)
const
452 std::stringstream ss;
454 for (V_Token::const_iterator it =
tokens_.begin(); it !=
tokens_.end(); ++it)
456 ss << (*it)->getString(logger_handle, level, str, file,
function, line);
477 char* format_string = NULL;
479 _dupenv_s(&format_string, NULL,
"ROSCONSOLE_FORMAT");
481 format_string = getenv(
"ROSCONSOLE_FORMAT");
492 std::string line_buffered;
495 if (line_buffered ==
"1")
499 else if (line_buffered !=
"0")
501 fprintf(stderr,
"Warning: unexpected value %s specified for ROSCONSOLE_STDOUT_LINE_BUFFERED. Default value 0 "
502 "will be used. Valid values are 1 or 0.\n", line_buffered.c_str());
506 std::string no_color;
520 va_copy(arg_copy, args);
521 size_t total = vsnprintf(buffer.get(), buffer_size, fmt, args);
522 if (total >= buffer_size)
524 buffer_size = total + 1;
525 buffer.reset(
new char[buffer_size]);
526 vsnprintf(buffer.get(), buffer_size, fmt, arg_copy);
553 return std::string(buffer.get(), size);
556 #define INITIAL_BUFFER_SIZE 4096
562 const char* file,
int line,
const char*
function,
const char* fmt, ...)
569 fprintf(stderr,
"Warning: recursive print statement has occurred. Throwing out recursive print.\n");
592 params.
level = level;
593 params.
logger = logger_handle;
596 level = params.
level;
621 catch (std::exception& e)
623 fprintf(stderr,
"Caught exception while logging: [%s]\n", e.what());
631 const std::stringstream& ss,
const char* file,
int line,
const char*
function)
638 fprintf(stderr,
"Warning: recursive print statement has occurred. Throwing out recursive print.\n");
647 std::string str = ss.str();
655 params.
level = level;
656 params.
logger = logger_handle;
659 level = params.
level;
677 catch (std::exception& e)
679 fprintf(stderr,
"Caught exception while logging: [%s]\n", e.what());
738 for ( ; it != end; ++it )
::ros::console::Level level_
std::map< std::string, std::string > M_string
ROSCONSOLE_CONSOLE_IMPL_DECL bool get_loggers(std::map< std::string, levels::Level > &loggers)
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)
const char * function
[input] Function the message came from
void print(ros::console::Level level, const std::string &s)
Level level
[input/output] Severity level. If changed, uses the new level
bool g_force_stdout_line_buffered
int line
[input] Line the message came from
void checkLogLocationEnabledNoLock(LogLocation *loc)
static boost::shared_array< char > g_print_buffer(new char[INITIAL_BUFFER_SIZE])
ROSCONSOLE_CONSOLE_IMPL_DECL std::string getName(void *handle)
virtual std::string getString(void *, ::ros::console::Level, const char *, const char *, const char *function, int)
boost::mutex g_init_mutex
TimeToken(const std::string &format)
ROSCONSOLE_CONSOLE_IMPL_DECL void * getHandle(const std::string &name)
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)
ROSCONSOLE_BACKEND_DECL void(* function_notifyLoggerLevelsChanged)()
const std::string format_
virtual std::string getString(void *, ::ros::console::Level, const char *str, const char *, const char *, int)
static size_t g_print_buffer_size
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.
virtual std::string getString(void *, ::ros::console::Level, const char *, const char *, const char *, int line)
#define ROSCONSOLE_AUTOINIT
Initializes the rosconsole library. Usually unnecessary to call 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,...
bool g_stdout_flush_failure_reported
ROSCONSOLE_DECL void shutdown()
ROSCONSOLE_DECL Formatter g_formatter
Only exported because the implementation need it. Do not use directly.
virtual std::string getString(void *, ::ros::console::Level level, const char *str, const char *file, const char *function, int line)
boost::mutex g_locations_mutex
ROSCONSOLE_DECL void formatToBuffer(boost::shared_array< char > &buffer, size_t &buffer_size, const char *fmt,...)
static boost::mutex g_print_mutex
ROSCONSOLE_DECL void registerLogLocation(LogLocation *loc)
Registers a logging location with the system.
WallTimeToken(const std::string &format)
boost::posix_time::ptime toBoost() const
M_string g_extra_fixed_tokens
ROSCONSOLE_DECL void setFixedFilterToken(const std::string &key, const std::string &val)
virtual std::string getString(void *, ::ros::console::Level, const char *, const char *, const char *, int)
virtual std::string getString(void *, ::ros::console::Level, const char *, const char *, const char *, int)
TokenPtr createTokenFromType(const std::string &type)
virtual std::string getString(void *, ::ros::console::Level, const char *, const char *, const char *, int)
ROSCONSOLE_CONSOLE_IMPL_DECL void shutdown()
const char * g_format_string
virtual std::string getString(void *logger_handle, ::ros::console::Level level, const char *str, const char *file, const char *function, int line)
std::string out_message
[output] If set, writes this message instead of the original
ROSCONSOLE_DECL void checkLogLocationEnabled(LogLocation *loc)
Internal.
V_LogLocation g_log_locations
ROSCONSOLE_DECL void notifyLoggerLevelsChanged()
Tells the system that a logger's level has changed.
bool get_environment_variable(std::string &str, const char *environment_variable)
ROSCONSOLE_CONSOLE_IMPL_DECL bool isEnabledFor(void *handle, ::ros::console::Level level)
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...
FixedMapToken(const std::string &str)
ROSCONSOLE_CONSOLE_IMPL_DECL void deregister_appender(LogAppender *appender)
const std::string format_
virtual std::string getString(void *, ::ros::console::Level, const char *, const char *, const char *, int)
virtual std::string getString(void *, ::ros::console::Level, const char *, const char *, const char *, int)
ROSCONSOLE_DECL std::string formatToString(const char *fmt,...)
void _print(void *logger_handle, ::ros::console::Level level, const char *str, const char *file, const char *function, int line)
#define INITIAL_BUFFER_SIZE
FixedToken(const std::string &str)
std::vector< LogLocation * > V_LogLocation
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 std::string getString(void *, ::ros::console::Level, const char *, const char *file, const char *, int)
ROSCONSOLE_DECL bool get_loggers(std::map< std::string, levels::Level > &loggers)
ROSCONSOLE_CONSOLE_IMPL_DECL bool set_logger_level(const std::string &name, levels::Level level)
ROSCONSOLE_DECL bool g_initialized
Only exported because the macros need it. Do not use directly.
ROSCONSOLE_CONSOLE_IMPL_DECL void register_appender(LogAppender *appender)
boost::shared_ptr< Token > TokenPtr
virtual std::string getString(void *, ::ros::console::Level, const char *, const char *, const char *, int)
ROSCONSOLE_BACKEND_DECL void(* function_print)(void *, ::ros::console::Level, const char *, const char *, const char *, int)
virtual bool isEnabled()
Returns whether or not the log statement should be printed. Called before the log arguments are evalu...
static boost::thread::id g_printing_thread_id
rosconsole
Author(s): Josh Faust
autogenerated on Wed Mar 2 2022 00:53:52