00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <ros/console.h>
00038 #include <console_bridge/console.h>
00039 #include "rosconsole_bridge/bridge.h"
00040
00041 namespace rosconsole_bridge
00042 {
00043
00044 OutputHandlerROS::OutputHandlerROS(void) : OutputHandler()
00045 {
00046 }
00047
00048 void OutputHandlerROS::log(const std::string &text, console_bridge::LogLevel level, const char *filename, int line)
00049 {
00050 std::string prefix;
00051
00052
00053
00054 static const std::string NEEDLE_STRING = ": ";
00055 size_t sub_index = text.find(NEEDLE_STRING);
00056 size_t space_index = text.find(" ");
00057
00058 if (sub_index != std::string::npos &&
00059 sub_index > 0 &&
00060 space_index > sub_index &&
00061 text.length() > space_index + 1)
00062 {
00063 prefix = std::string(ROSCONSOLE_NAME_PREFIX) + "." + text.substr(0, sub_index);
00064
00065 sub_index += NEEDLE_STRING.length();
00066 }
00067 else
00068 {
00069 prefix = std::string(ROSCONSOLE_NAME_PREFIX) + ".console_bridge";
00070 sub_index = 0;
00071 }
00072
00073
00074 switch (level)
00075 {
00076 case console_bridge::CONSOLE_BRIDGE_LOG_INFO:
00077 {
00078 ROSCONSOLE_DEFINE_LOCATION(true, ::ros::console::levels::Info, prefix);
00079 if (ROS_UNLIKELY(enabled))
00080 {
00081 ::ros::console::print(NULL, loc.logger_, loc.level_, filename, line, "", "%s",
00082 text.substr(sub_index, std::string::npos).c_str());
00083 }
00084 }
00085 break;
00086 case console_bridge::CONSOLE_BRIDGE_LOG_WARN:
00087 {
00088 ROSCONSOLE_DEFINE_LOCATION(true, ::ros::console::levels::Warn, prefix);
00089 if (ROS_UNLIKELY(enabled))
00090 {
00091 ::ros::console::print(NULL, loc.logger_, loc.level_, filename, line, "", "%s",
00092 text.substr(sub_index, std::string::npos).c_str());
00093 }
00094 }
00095 break;
00096 case console_bridge::CONSOLE_BRIDGE_LOG_ERROR:
00097 {
00098 ROSCONSOLE_DEFINE_LOCATION(true, ::ros::console::levels::Error, prefix);
00099 if (ROS_UNLIKELY(enabled))
00100 {
00101 ::ros::console::print(NULL, loc.logger_, loc.level_, filename, line, "", "%s",
00102 text.substr(sub_index, std::string::npos).c_str());
00103 }
00104 }
00105 break;
00106 default:
00107
00108 {
00109 ROSCONSOLE_DEFINE_LOCATION(true, ::ros::console::levels::Debug, prefix);
00110 if (ROS_UNLIKELY(enabled))
00111 {
00112 ::ros::console::print(NULL, loc.logger_, loc.level_, filename, line, "", "%s",
00113 text.substr(sub_index, std::string::npos).c_str());
00114 }
00115 }
00116 break;
00117 }
00118 }
00119
00120 RegisterOutputHandlerProxy::RegisterOutputHandlerProxy(void)
00121 {
00122 static OutputHandlerROS oh_ros;
00123 console_bridge::useOutputHandler(&oh_ros);
00124
00125
00126 console_bridge::setLogLevel(console_bridge::CONSOLE_BRIDGE_LOG_DEBUG);
00127 }
00128
00129 }