utils.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 /*
11  * File: utils.h
12  * Author: Vladislav Tananaev
13  *
14  */
15 
16 #pragma once
17 
18 #include <ros/console.h>
19 #include <mrpt/system/datetime.h>
20 #include <mrpt/system/COutputLogger.h>
21 #include <log4cxx/logger.h>
22 
23 namespace mrpt_bridge
24 {
29 inline mrpt::system::VerbosityLevel rosLoggerLvlToMRPTLoggerLvl(
30  log4cxx::LevelPtr lvl)
31 {
32  using namespace log4cxx;
33 
34  // determine on the corresponding VerbosityLevel
35  mrpt::system::VerbosityLevel mrpt_lvl;
36 
37  if (lvl == Level::getFatal() || lvl == Level::getError())
38  {
39  mrpt_lvl = mrpt::system::LVL_ERROR;
40  }
41  else if (lvl == Level::getWarn())
42  {
43  mrpt_lvl = mrpt::system::LVL_WARN;
44  }
45  else if (lvl == Level::getInfo())
46  {
47  mrpt_lvl = mrpt::system::LVL_INFO;
48  }
49  else if (lvl == Level::getDebug() || lvl == Level::getTrace())
50  {
51  mrpt_lvl = mrpt::system::LVL_DEBUG;
52  }
53  else
54  {
55  mrpt_lvl = mrpt::system::LVL_INFO;
56  ROS_ERROR("Unknown log4cxx::Level is given.");
57  }
58 
59  return mrpt_lvl;
60 
61 } // end of rosLoggerLvlToMRPTLoggerLvl
62 
71  const std::string& msg, const mrpt::system::VerbosityLevel level,
72  [[maybe_unused]] const std::string& loggerName,
73  [[maybe_unused]] const mrpt::system::TTimeStamp timestamp)
74 {
75  // Remove trailing \n if present
76  std::string tmsg = msg;
77  if (!tmsg.empty() &&
78  tmsg.compare(tmsg.length() - 1, tmsg.length(), "\n") == 0)
79  {
80  tmsg.erase(tmsg.end() - 1);
81  }
82 
83  switch (level)
84  {
85  case mrpt::system::LVL_DEBUG:
86  ROS_DEBUG("%s", tmsg.c_str());
87  break;
88  case mrpt::system::LVL_WARN:
89  ROS_WARN("%s", tmsg.c_str());
90  break;
91  case mrpt::system::LVL_ERROR:
92  ROS_ERROR("%s", tmsg.c_str());
93  break;
94  default:
95  case mrpt::system::LVL_INFO:
96  ROS_INFO("%s", tmsg.c_str());
97  break;
98  }
99 }
100 
101 } // namespace mrpt_bridge
void mrptToROSLoggerCallback(const std::string &msg, const mrpt::system::VerbosityLevel level, [[maybe_unused]] const std::string &loggerName, [[maybe_unused]] const mrpt::system::TTimeStamp timestamp)
callback that is called by MRPT mrpt::system::COuputLogger to redirect log messages to ROS logger...
Definition: utils.h:70
#define ROS_WARN(...)
File includes methods for converting CNetworkOfPoses*DInf <=> NetworkOfPoses message types...
#define ROS_INFO(...)
mrpt::system::VerbosityLevel rosLoggerLvlToMRPTLoggerLvl(log4cxx::LevelPtr lvl)
function that converts ROS verbosity level log4cxx::Level to MRPT equivalent MRPT&#39;s VerbosityLevel ...
Definition: utils.h:29
#define ROS_ERROR(...)
#define ROS_DEBUG(...)


mrpt_bridge
Author(s): Markus Bader , Raphael Zack
autogenerated on Thu May 12 2022 02:26:47