8 #ifndef __dynamic_graph_logger_H__ 9 #define __dynamic_graph_logger_H__ 16 #if defined(logger_EXPORTS) 17 #define LOGGER_EXPORT __declspec(dllexport) 19 #define LOGGER_EXPORT __declspec(dllimport) 53 #include <boost/assign.hpp> 54 #include <boost/preprocessor/stringize.hpp> 55 #include <dynamic-graph/deprecated.hh> 63 #define LOGGER_VERBOSITY_ALL 65 #define SEND_MSG(msg, type) \ 66 sendMsg(msg, type, __FILE__ ":" BOOST_PP_STRINGIZE(__LINE__)) 68 #define SEND_DEBUG_STREAM_MSG(msg) SEND_MSG(msg, MSG_TYPE_DEBUG_STREAM) 69 #define SEND_INFO_STREAM_MSG(msg) SEND_MSG(msg, MSG_TYPE_INFO_STREAM) 70 #define SEND_WARNING_STREAM_MSG(msg) SEND_MSG(msg, MSG_TYPE_WARNING_STREAM) 71 #define SEND_ERROR_STREAM_MSG(msg) SEND_MSG(msg, MSG_TYPE_ERROR_STREAM) 73 #define _DYNAMIC_GRAPH_ENTITY_MSG(entity, type) \ 74 (entity).logger().stream(type, __FILE__ BOOST_PP_STRINGIZE(__LINE__)) 76 #define DYNAMIC_GRAPH_ENTITY_DEBUG(entity) \ 77 _DYNAMIC_GRAPH_ENTITY_MSG(entity, MSG_TYPE_DEBUG) 78 #define DYNAMIC_GRAPH_ENTITY_INFO(entity) \ 79 _DYNAMIC_GRAPH_ENTITY_MSG(entity, MSG_TYPE_INFO) 80 #define DYNAMIC_GRAPH_ENTITY_WARNING(entity) \ 81 _DYNAMIC_GRAPH_ENTITY_MSG(entity, MSG_TYPE_WARNING) 82 #define DYNAMIC_GRAPH_ENTITY_ERROR(entity) \ 83 _DYNAMIC_GRAPH_ENTITY_MSG(entity, MSG_TYPE_ERROR) 85 #define DYNAMIC_GRAPH_ENTITY_DEBUG_STREAM(entity) \ 86 _DYNAMIC_GRAPH_ENTITY_MSG(entity, MSG_TYPE_DEBUG_STREAM) 87 #define DYNAMIC_GRAPH_ENTITY_INFO_STREAM(entity) \ 88 _DYNAMIC_GRAPH_ENTITY_MSG(entity, MSG_TYPE_INFO_STREAM) 89 #define DYNAMIC_GRAPH_ENTITY_WARNING_STREAM(entity) \ 90 _DYNAMIC_GRAPH_ENTITY_MSG(entity, MSG_TYPE_WARNING_STREAM) 91 #define DYNAMIC_GRAPH_ENTITY_ERROR_STREAM(entity) \ 92 _DYNAMIC_GRAPH_ENTITY_MSG(entity, MSG_TYPE_ERROR_STREAM) 95 std::string
toString(
const T &v,
const int precision = 3,
96 const int width = -1) {
98 if (width > precision)
99 ss << std::fixed << std::setw(width) << std::setprecision(precision) << v;
101 ss << std::fixed << std::setprecision(precision) << v;
105 template <
typename T>
106 std::string
toString(
const std::vector<T> &v,
const int precision = 3,
107 const int width = -1,
const std::string separator =
", ") {
108 std::stringstream ss;
109 if (width > precision) {
110 for (
unsigned int i = 0; i < v.size() - 1; i++)
111 ss << std::fixed << std::setw(width) << std::setprecision(precision)
112 << v[i] << separator;
113 ss << std::fixed << std::setw(width) << std::setprecision(precision)
116 for (
unsigned int i = 0; i < v.size() - 1; i++)
117 ss << std::fixed << std::setprecision(precision) << v[i] << separator;
118 ss << std::fixed << std::setprecision(precision) << v[v.size() - 1];
124 template <
typename T>
125 std::string
toString(
const Eigen::MatrixBase<T> &v,
const int precision = 3,
126 const int width = -1,
const std::string separator =
", ") {
127 std::stringstream ss;
128 if (width > precision) {
129 for (
unsigned int i = 0; i < v.size() - 1; i++)
130 ss << std::fixed << std::setw(width) << std::setprecision(precision)
131 << v[i] << separator;
132 ss << std::fixed << std::setw(width) << std::setprecision(precision)
135 for (
unsigned int i = 0; i < v.size() - 1; i++)
136 ss << std::fixed << std::setprecision(precision) << v[i] << separator;
137 ss << std::setprecision(precision) << v[v.size() - 1];
189 Logger(
double timeSample = 0.001,
double streamPrintPeriod = 1.0);
201 return ::dynamicgraph::RealTimeLogger::instance().front();
222 [[deprecated(
"use stream(type, lineId) << msg")]]
void sendMsg(
223 std::string msg,
MsgType type,
const std::string &lineId =
"");
230 [[deprecated(
"use stream(type, lineId) << msg")]]
void sendMsg(
231 std::string msg,
MsgType type,
const std::string &file,
int line);
289 #endif // #ifndef __sot_torque_control_logger_H__
RTLoggerStream emptyStream()
Return an empty stream object.
double m_streamPrintPeriod
specify the period of call of the countdown method
RTLoggerStream stream(MsgType type, const std::string &lineId="")
bool checkStreamPeriod(const std::string &lineId)
Main class of the real-time logger.
double m_timeSample
verbosity of the logger
std::map< std::string, double > StreamCounterMap_t
every time this is < 0 (i.e. every _streamPrintPeriod sec) print stuff
double getStreamPrintPeriod()
Logger(double timeSample=0.001, double streamPrintPeriod=1.0)
bool setTimeSample(double t)
void setVerbosity(LoggerVerbosity lv)
bool acceptMsg(MsgType m, const std::string &lineId)
bool setStreamPrintPeriod(double s)
std::string toString(const T &v, const int precision=3, const int width=-1)
double m_printCountdown
specify the time period of the stream prints
void sendMsg(std::string msg, MsgType type, const std::string &lineId="")
StreamCounterMap_t m_stream_msg_counters
LoggerVerbosity getVerbosity()
bool isStreamMsg(MsgType m)
Class for logging messages.
static RealTimeLogger & instance()