hpp-centroidal-dynamics 5.0.0
Utility classes for testing (robust) equilibrium of a system in contact with the environment, and other centroidal dynamics methods.
Loading...
Searching...
No Matches
logger.hh
Go to the documentation of this file.
1/*
2 * Copyright 2015, LAAS-CNRS
3 * Author: Andrea Del Prete
4 */
5
6#ifndef HPP_CENTROIDAL_DYNAMICS_LOGGER_HH
7#define HPP_CENTROIDAL_DYNAMICS_LOGGER_HH
8
9/* --------------------------------------------------------------------- */
10/* --- INCLUDE --------------------------------------------------------- */
11/* --------------------------------------------------------------------- */
12
13#include <Eigen/Dense>
15#include <map>
16#include <sstream>
17
18#include "boost/assign.hpp"
19
20namespace centroidal_dynamics {
21
22// #define LOGGER_VERBOSITY_ERROR
23// #define LOGGER_VERBOSITY_WARNING_ERROR
24// #define LOGGER_VERBOSITY_INFO_WARNING_ERROR
25// #define LOGGER_VERBOSITY_ALL
26#define LOGGER_VERBOSITY_ALL
27
28#define SEND_MSG(msg, type) getLogger().sendMsg(msg, type, __FILE__, __LINE__)
29
30#ifdef LOGGER_VERBOSITY_ERROR
31#define SEND_DEBUG_MSG(msg)
32#define SEND_INFO_MSG(msg)
33#define SEND_WARNING_MSG(msg)
34#define SEND_ERROR_MSG(msg) SEND_MSG(msg, MSG_TYPE_ERROR)
35#define SEND_DEBUG_STREAM_MSG(msg)
36#define SEND_INFO_STREAM_MSG(msg)
37#define SEND_WARNING_STREAM_MSG(msg)
38#define SEND_ERROR_STREAM_MSG(msg) SEND_MSG(msg, MSG_TYPE_ERROR_STREAM)
39#endif
40
41#ifdef LOGGER_VERBOSITY_WARNING_ERROR
42#define SEND_DEBUG_MSG(msg)
43#define SEND_INFO_MSG(msg)
44#define SEND_WARNING_MSG(msg) SEND_MSG(msg, MSG_TYPE_WARNING)
45#define SEND_ERROR_MSG(msg) SEND_MSG(msg, MSG_TYPE_ERROR)
46#define SEND_DEBUG_STREAM_MSG(msg)
47#define SEND_INFO_STREAM_MSG(msg) \
48 #define SEND_WARNING_STREAM_MSG(msg) SEND_MSG(msg, MSG_TYPE_WARNING_STREAM)
49#define SEND_ERROR_STREAM_MSG(msg) SEND_MSG(msg, MSG_TYPE_ERROR_STREAM)
50#endif
51
52#ifdef LOGGER_VERBOSITY_INFO_WARNING_ERROR
53#define SEND_DEBUG_MSG(msg)
54#define SEND_INFO_MSG(msg) SEND_MSG(msg, MSG_TYPE_INFO)
55#define SEND_WARNING_MSG(msg) SEND_MSG(msg, MSG_TYPE_WARNING)
56#define SEND_ERROR_MSG(msg) SEND_MSG(msg, MSG_TYPE_ERROR)
57#define SEND_DEBUG_STREAM_MSG(msg)
58#define SEND_INFO_STREAM_MSG(msg) SEND_MSG(msg, MSG_TYPE_INFO_STREAM)
59#define SEND_WARNING_STREAM_MSG(msg) SEND_MSG(msg, MSG_TYPE_WARNING_STREAM)
60#define SEND_ERROR_STREAM_MSG(msg) SEND_MSG(msg, MSG_TYPE_ERROR_STREAM)
61#endif
62
63#ifdef LOGGER_VERBOSITY_ALL
64#define SEND_DEBUG_MSG(msg) SEND_MSG(msg, MSG_TYPE_DEBUG)
65#define SEND_INFO_MSG(msg) SEND_MSG(msg, MSG_TYPE_INFO)
66#define SEND_WARNING_MSG(msg) SEND_MSG(msg, MSG_TYPE_WARNING)
67#define SEND_ERROR_MSG(msg) SEND_MSG(msg, MSG_TYPE_ERROR)
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)
72#endif
73
76enum CENTROIDAL_DYNAMICS_DLLAPI MsgType {
84 MSG_TYPE_ERROR_STREAM = 7
85};
86
87template <typename T>
88std::string toString(const T& v) {
89 std::stringstream ss;
90 ss << v;
91 return ss.str();
92}
93
94template <typename T>
95std::string toString(const std::vector<T>& v,
96 const std::string separator = ", ") {
97 std::stringstream ss;
98 for (int i = 0; i < v.size() - 1; i++) ss << v[i] << separator;
99 ss << v[v.size() - 1];
100 return ss.str();
101}
102
103template <typename T, int n>
104std::string toString(const Eigen::MatrixBase<T>& v,
105 const std::string separator = ", ") {
106 if (v.rows() > v.cols()) return toString(v.transpose(), separator);
107 std::stringstream ss;
108 ss << v;
109 return ss.str();
110}
111
112enum CENTROIDAL_DYNAMICS_DLLAPI LoggerVerbosity {
117 VERBOSITY_NONE
118};
119
123 public:
125 Logger(double timeSample = 0.001, double streamPrintPeriod = 1.0);
126
129
132 void countdown();
133
139 void sendMsg(std::string msg, MsgType type, const char* file = "",
140 int line = 0);
141
144 bool setTimeSample(double t);
145
147 bool setStreamPrintPeriod(double s);
148
150 void setVerbosity(LoggerVerbosity lv);
151
152 protected:
153 LoggerVerbosity m_lv;
158
161 std::map<std::string, double> m_stream_msg_counters;
162
163 bool isStreamMsg(MsgType m) {
164 return m == MSG_TYPE_ERROR_STREAM || m == MSG_TYPE_DEBUG_STREAM ||
166 }
167
168 bool isDebugMsg(MsgType m) {
169 return m == MSG_TYPE_DEBUG_STREAM || m == MSG_TYPE_DEBUG;
170 }
171
172 bool isInfoMsg(MsgType m) {
173 return m == MSG_TYPE_INFO_STREAM || m == MSG_TYPE_INFO;
174 }
175
176 bool isWarningMsg(MsgType m) {
177 return m == MSG_TYPE_WARNING_STREAM || m == MSG_TYPE_WARNING;
178 }
179
180 bool isErrorMsg(MsgType m) {
181 return m == MSG_TYPE_ERROR_STREAM || m == MSG_TYPE_ERROR;
182 }
183};
184
186Logger& getLogger();
187
188} // namespace centroidal_dynamics
189
190#endif // HPP_CENTROIDAL_DYNAMICS_LOGGER_HH
Definition: logger.hh:122
double m_streamPrintPeriod
specify the period of call of the countdown method
Definition: logger.hh:155
bool isInfoMsg(MsgType m)
Definition: logger.hh:172
bool isStreamMsg(MsgType m)
Definition: logger.hh:163
double m_printCountdown
specify the time period of the stream prints
Definition: logger.hh:156
std::map< std::string, double > m_stream_msg_counters
Definition: logger.hh:161
bool isWarningMsg(MsgType m)
Definition: logger.hh:176
bool isErrorMsg(MsgType m)
Definition: logger.hh:180
double m_timeSample
verbosity of the logger
Definition: logger.hh:154
LoggerVerbosity m_lv
Definition: logger.hh:153
bool isDebugMsg(MsgType m)
Definition: logger.hh:168
void setVerbosity(LoggerVerbosity lv)
~Logger()
Definition: logger.hh:128
#define CENTROIDAL_DYNAMICS_DLLAPI
Definition: local_config.hh:52
MSG_TYPE_ERROR
Definition: logger.hh:80
MSG_TYPE_INFO_STREAM
Definition: logger.hh:82
MSG_TYPE_INFO
Definition: logger.hh:78
MSG_TYPE_DEBUG_STREAM
Definition: logger.hh:81
VERBOSITY_INFO_WARNING_ERROR
Definition: logger.hh:114
MSG_TYPE_WARNING_STREAM
Definition: logger.hh:83
VERBOSITY_WARNING_ERROR
Definition: logger.hh:115
VERBOSITY_ERROR
Definition: logger.hh:116
MSG_TYPE_DEBUG
Definition: logger.hh:77
MSG_TYPE_WARNING
Definition: logger.hh:79
VERBOSITY_ALL
Definition: logger.hh:113
Definition: centroidal_dynamics.hh:14
std::string toString(const T &v)
Definition: logger.hh:88
Logger & getLogger()
Definition: logger.cpp:22