Skip to content

Commit

Permalink
Add a callback function to stream MRPT logs to ROS.
Browse files Browse the repository at this point in the history
  • Loading branch information
Logrus committed Aug 22, 2016
1 parent db877e0 commit 3c4a247
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions mrpt_bridge/include/mrpt_bridge/mrpt_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
#include "point_cloud2.h"
#include "beacon.h"
#include "landmark.h"
#include "utils.h"
#endif
61 changes: 61 additions & 0 deletions mrpt_bridge/include/mrpt_bridge/utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* File: utils.h
* Author: Vladislav Tananaev
*
*/

#ifndef MRPT_BRIDGE_UTILS_H
#define MRPT_BRIDGE_UTILS_H
#include <ros/console.h>
#include <mrpt/system/datetime.h>
#include <mrpt/utils/COutputLogger.h>
#include <log4cxx/logger.h>

namespace mrpt_bridge {

/**
* @brief function that converts ROS verbosity level log4cxx::Level to MRPT equivalent mrpt::utils::VerbosityLevel
*/
inline mrpt::utils::VerbosityLevel rosLoggerLvlToMRPTLoggerLvl(log4cxx::LevelPtr lvl){
if (lvl == log4cxx::Level::getFatal())
{
return mrpt::utils::LVL_ERROR;
}
else if (lvl == log4cxx::Level::getError())
{
return mrpt::utils::LVL_ERROR;
}
else if (lvl == log4cxx::Level::getWarn())
{
return mrpt::utils::LVL_WARN;
}
else if (lvl == log4cxx::Level::getInfo())
{
return mrpt::utils::LVL_INFO;
}
else if (lvl == log4cxx::Level::getDebug())
{
return mrpt::utils::LVL_DEBUG;
}
}

/**
* @brief callback that is called by MRPT mrpt::utils::COuputLogger to refirect log messages to ROS logger.
* This function has to be inline, otherwise option log4j.logger.ros.package_name will be taken from mrpt_bridge
* instead of the package from which macro is actually called.
*/
inline void mrptToROSLoggerCallback(const std::string &msg, const mrpt::utils::VerbosityLevel level, const std::string &loggerName, const mrpt::system::TTimeStamp timestamp, void *userParam){
if (level == mrpt::utils::LVL_DEBUG){
ROS_DEBUG("%s", msg.c_str());
} else if (level == mrpt::utils::LVL_INFO) {
ROS_INFO("%s", msg.c_str());
} else if (level == mrpt::utils::LVL_WARN) {
ROS_WARN("%s", msg.c_str());
} else if (level == mrpt::utils::LVL_ERROR) {
ROS_ERROR("%s", msg.c_str());
}
}

} //namespace mrpt_bridge

#endif //MRPT_BRIDGE_UTILS_H

0 comments on commit 3c4a247

Please sign in to comment.