YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Log.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef YARP_OS_LOG_H
7#define YARP_OS_LOG_H
8
9#include <yarp/os/api.h>
10
11#include <cstdint>
12#include <iosfwd>
13#include <mutex>
14#include <string_view>
15
16#if defined(__GNUC__)
17# define __YFUNCTION__ __PRETTY_FUNCTION__
18#elif defined(_MSC_VER)
19# define __YFUNCTION__ __FUNCSIG__
20#elif (__cplusplus <= 199711)
21# define __YFUNCTION__ __func__
22#else
23# define __YFUNCTION__ "(unknown function)"
24#endif // __GNUC__
25
26// check arguments of the c-style debug functions to make sure that the
27// arguments supplied have types appropriate to the format string
28// specified, and that the conversions specified in the format string
29// make sense. On gcc the warning is enabled by -Wformat.
30#if defined(__GNUC__)
31# define YARP_ATTRIBUTE_FORMAT(style, fmt, args) __attribute__((format(printf, (fmt), (args))))
32#else
33# define YARP_ATTRIBUTE_FORMAT(style, fmt, args)
34#endif
35
36
37// Forward declarations
38namespace yarp::os {
39
40class LogComponent;
41class LogStream;
42
43#ifndef DOXYGEN_SHOULD_SKIP_THIS
44namespace impl {
45class LogPrivate;
46} // namespace impl
47#endif // DOXYGEN_SHOULD_SKIP_THIS
48
50{
51public:
52 using Predicate = bool(*)();
53
54 Log(const char* file,
55 const unsigned int line,
56 const char* func,
57 const Predicate pred = nullptr,
58 const LogComponent& comp = defaultLogComponent());
59
60 // constructor with id
61 Log(const char* file,
62 const unsigned int line,
63 const char* func,
64 const std::string_view id,
65 const Predicate pred = nullptr,
66 const LogComponent& comp = defaultLogComponent());
67
68 // constructor with externaltime
69 Log(const char* file,
70 const unsigned int line,
71 const char* func,
72 const double externaltime,
73 const Predicate pred = nullptr,
74 const LogComponent& comp = defaultLogComponent());
75
76 // constructor with id and external time
77 Log(const char* file,
78 const unsigned int line,
79 const char* func,
80 const std::string_view id,
81 const double externaltime,
82 const Predicate pred = nullptr,
83 const LogComponent& comp = defaultLogComponent());
84
85 Log();
86 virtual ~Log();
87
89 {
90 LogTypeUnknown = 0,
97 LogTypeReserved = 0xFF
98 };
99
100 void trace(const char* msg, ...) const YARP_ATTRIBUTE_FORMAT(printf, 2, 3);
101 void debug(const char* msg, ...) const YARP_ATTRIBUTE_FORMAT(printf, 2, 3);
102 void info(const char* msg, ...) const YARP_ATTRIBUTE_FORMAT(printf, 2, 3);
103 void warning(const char* msg, ...) const YARP_ATTRIBUTE_FORMAT(printf, 2, 3);
104 void error(const char* msg, ...) const YARP_ATTRIBUTE_FORMAT(printf, 2, 3);
105 YARP_NORETURN void fatal(const char* msg, ...) const YARP_ATTRIBUTE_FORMAT(printf, 2, 3);
106
107 LogStream trace() const;
112 LogStream fatal() const;
113
114 using LogCallback = void (*)(yarp::os::Log::LogType type,
115 const char* msg,
116 const char* file,
117 const unsigned int line,
118 const char* func,
119 double systemtime,
120 double networktime,
121 double externaltime,
122 const char* comp_name,
123 const char* id);
124
125 static void setMinimumPrintLevel(LogType level);
126 static LogType minimumPrintLevel();
127 static LogType defaultMinimumPrintLevel();
128
129 static void setMinimumForwardLevel(LogType level);
130 static LogType minimumForwardLevel();
131 static LogType defaultMinimumForwardLevel();
132
133 static void setPrintCallback(LogCallback);
134 static LogCallback printCallback();
135 static LogCallback defaultPrintCallback();
136
137 static void setForwardCallback(LogCallback);
138 static LogCallback forwardCallback();
139 static LogCallback defaultForwardCallback();
140
141
142#ifndef DOXYGEN_SHOULD_SKIP_THIS
143 static void nolog(const char* msg, ...) {}
144 struct NoLog
145 {
146 template <typename T>
147 NoLog& operator<<(const T&)
148 {
149 return *this;
150 }
151 };
152 static NoLog nolog() { return NoLog(); }
153
154private:
155 yarp::os::impl::LogPrivate* const mPriv;
156
157 friend class yarp::os::LogStream;
158
159 // This callback is called by LogStream
160 static void do_log(yarp::os::Log::LogType type,
161 const char* msg,
162 const char* file,
163 const unsigned int line,
164 const char* func,
165 double systemtime,
166 double networktime,
167 double externaltime,
168 const LogComponent& comp_name,
169 const std::string_view id);
170
171 // This component is used for yDebug-family output, and is called by LogStream
172 static const LogComponent& defaultLogComponent();
173
174 // This component is used for internal debug output, and is called by LogStream
175 static const LogComponent& logInternalComponent();
176#endif // DOXYGEN_SHOULD_SKIP_THIS
177}; // class Log
178
179} // namespace yarp::os
180
181
182#define YARP_ONCE_CALLBACK \
183 [](){ \
184 static std::atomic_flag flag = ATOMIC_FLAG_INIT; \
185 return !flag.test_and_set(); \
186 }
187
188#define YARP_THREADONCE_CALLBACK \
189 [](){ \
190 thread_local std::atomic_flag flag = ATOMIC_FLAG_INIT; \
191 return !flag.test_and_set(); \
192 }
193
194#define YARP_THROTTLE_CALLBACK(period) \
195 [](){ \
196 static double last = -period; \
197 static std::mutex mutex; \
198 std::lock_guard<std::mutex> lock(mutex); \
199 double now = yarp::os::SystemClock::nowSystem(); \
200 if (now >= last + period) { \
201 last = now; \
202 return true; \
203 } \
204 return false; \
205 }
206
207#define YARP_THREADTHROTTLE_CALLBACK(period) \
208 [](){ \
209 thread_local double last = -period; \
210 double now = yarp::os::SystemClock::nowSystem(); \
211 if (now >= last + period) { \
212 last = now; \
213 return true; \
214 } \
215 return false; \
216 }
217
218
219
220#ifndef NDEBUG
221# define yTrace(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__).trace(__VA_ARGS__)
222# define yTraceOnce(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_ONCE_CALLBACK).trace(__VA_ARGS__)
223# define yTraceThreadOnce(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THREADONCE_CALLBACK).trace(__VA_ARGS__)
224# define yTraceThrottle(period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THROTTLE_CALLBACK(period)).trace(__VA_ARGS__)
225# define yTraceThreadThrottle(period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THREADTHROTTLE_CALLBACK(period)).trace(__VA_ARGS__)
226# define yTraceExternalTime(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime).trace(__VA_ARGS__)
227# define yTraceExternalTimeOnce(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_ONCE_CALLBACK).trace(__VA_ARGS__)
228# define yTraceExternalTimeThreadOnce(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THREADONCE_CALLBACK).trace(__VA_ARGS__)
229# define yTraceExternalTimeThrottle(externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THROTTLE_CALLBACK(period)).trace(__VA_ARGS__)
230# define yTraceExternalTimeThreadThrottle(externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THREADTHROTTLE_CALLBACK(period)).trace(__VA_ARGS__)
231# define yITrace(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id).trace(__VA_ARGS__)
232# define yITraceOnce(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_ONCE_CALLBACK).trace(__VA_ARGS__)
233# define yITraceThreadOnce(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THREADONCE_CALLBACK).trace(__VA_ARGS__)
234# define yITraceThrottle(id, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THROTTLE_CALLBACK(period)).trace(__VA_ARGS__)
235# define yITraceThreadThrottle(id, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THREADTHROTTLE_CALLBACK(period)).trace(__VA_ARGS__)
236# define yITraceExternalTime(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime).trace(__VA_ARGS__)
237# define yITraceExternalTimeOnce(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_ONCE_CALLBACK).trace(__VA_ARGS__)
238# define yITraceExternalTimeThreadOnce(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THREADONCE_CALLBACK).trace(__VA_ARGS__)
239# define yITraceExternalTimeThrottle(id, externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THROTTLE_CALLBACK(period)).trace(__VA_ARGS__)
240# define yITraceExternalTimeThreadThrottle(id, externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THREADTHROTTLE_CALLBACK(period)).trace(__VA_ARGS__)
241#else
242# define yTrace(...) yarp::os::Log::nolog(__VA_ARGS__)
243# define yTraceOnce(...) yarp::os::Log::nolog(__VA_ARGS__)
244# define yTraceThreadOnce(...) yarp::os::Log::nolog(__VA_ARGS__)
245# define yTraceThrottle(period, ...) yarp::os::Log::nolog(__VA_ARGS__)
246# define yTraceThreadThrottle(period, ...) yarp::os::Log::nolog(__VA_ARGS__)
247# define yTraceExternalTime(externaltime, ...) yarp::os::Log::nolog(__VA_ARGS__)
248# define yTraceExternalTimeOnce(externaltime, ...) yarp::os::Log::nolog(__VA_ARGS__)
249# define yTraceExternalTimeThreadOnce(externaltime, ...) yarp::os::Log::nolog(__VA_ARGS__)
250# define yTraceExternalTimeThrottle(externaltime, period, ...) yarp::os::Log::nolog(__VA_ARGS__)
251# define yTraceExternalTimeThreadThrottle(externaltime, period, ...) yarp::os::Log::nolog(__VA_ARGS__)
252# define yITrace(id, ...) yarp::os::Log::nolog(__VA_ARGS__)
253# define yITraceOnce(id, ...) yarp::os::Log::nolog(__VA_ARGS__)
254# define yITraceThreadOnce(id, ...) yarp::os::Log::nolog(__VA_ARGS__)
255# define yITraceThrottle(id, period, ...) yarp::os::Log::nolog(__VA_ARGS__)
256# define yITraceThreadThrottle(id, period, ...) yarp::os::Log::nolog(__VA_ARGS__)
257# define yITraceExternalTime(id, externaltime, ...) yarp::os::Log::nolog(__VA_ARGS__)
258# define yITraceExternalTimeOnce(id, externaltime, ...) yarp::os::Log::nolog(__VA_ARGS__)
259# define yITraceExternalTimeThreadOnce(id, externaltime, ...) yarp::os::Log::nolog(__VA_ARGS__)
260# define yITraceExternalTimeThrottle(id, externaltime, period, ...) yarp::os::Log::nolog(__VA_ARGS__)
261# define yITraceExternalTimeThreadThrottle(id, externaltime, period, ...) yarp::os::Log::nolog(__VA_ARGS__)
262#endif
263
264#ifndef YARP_NO_DEBUG_OUTPUT
265# define yDebug(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__).debug(__VA_ARGS__)
266# define yDebugOnce(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_ONCE_CALLBACK).debug(__VA_ARGS__)
267# define yDebugThreadOnce(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THREADONCE_CALLBACK).debug(__VA_ARGS__)
268# define yDebugThrottle(period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THROTTLE_CALLBACK(period)).debug(__VA_ARGS__)
269# define yDebugThreadThrottle(period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THREADTHROTTLE_CALLBACK(period)).debug(__VA_ARGS__)
270# define yDebugExternalTime(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime).debug(__VA_ARGS__)
271# define yDebugExternalTimeOnce(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_ONCE_CALLBACK).debug(__VA_ARGS__)
272# define yDebugExternalTimeThreadOnce(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THREADONCE_CALLBACK).debug(__VA_ARGS__)
273# define yDebugExternalTimeThrottle(externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THROTTLE_CALLBACK(period)).debug(__VA_ARGS__)
274# define yDebugExternalTimeThreadThrottle(externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THREADTHROTTLE_CALLBACK(period)).debug(__VA_ARGS__)
275# define yIDebug(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id).debug(__VA_ARGS__)
276# define yIDebugOnce(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_ONCE_CALLBACK).debug(__VA_ARGS__)
277# define yIDebugThreadOnce(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THREADONCE_CALLBACK).debug(__VA_ARGS__)
278# define yIDebugThrottle(id, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THROTTLE_CALLBACK(period)).debug(__VA_ARGS__)
279# define yIDebugThreadThrottle(id, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THREADTHROTTLE_CALLBACK(period)).debug(__VA_ARGS__)
280# define yIDebugExternalTime(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime).debug(__VA_ARGS__)
281# define yIDebugExternalTimeOnce(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_ONCE_CALLBACK).debug(__VA_ARGS__)
282# define yIDebugExternalTimeThreadOnce(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THREADONCE_CALLBACK).debug(__VA_ARGS__)
283# define yIDebugExternalTimeThrottle(id, externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THROTTLE_CALLBACK(period)).debug(__VA_ARGS__)
284# define yIDebugExternalTimeThreadThrottle(id, externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THREADTHROTTLE_CALLBACK(period)).debug(__VA_ARGS__)
285#else
286# define yDebug(...) yarp::os::Log::nolog(__VA_ARGS__)
287# define yDebugOnce(...) yarp::os::Log::nolog(__VA_ARGS__)
288# define yDebugThreadOnce(...) yarp::os::Log::nolog(__VA_ARGS__)
289# define yDebugThrottle(period, ...) yarp::os::Log::nolog(__VA_ARGS__)
290# define yDebugThreadThrottle(period, ...) yarp::os::Log::nolog(__VA_ARGS__)
291# define yDebugExternalTime(externaltime, ...) yarp::os::Log::nolog(__VA_ARGS__)
292# define yDebugExternalTimeOnce(externaltime, ...) yarp::os::Log::nolog(__VA_ARGS__)
293# define yDebugExternalTimeThreadOnce(externaltime, ...) yarp::os::Log::nolog(__VA_ARGS__)
294# define yDebugExternalTimeThrottle(externaltime, period, ...) yarp::os::Log::nolog(__VA_ARGS__)
295# define yDebugExternalTimeThreadThrottle(externaltime, period, ...) yarp::os::Log::nolog(__VA_ARGS__)
296# define yIDebug(id, ...) yarp::os::Log::nolog(__VA_ARGS__)
297# define yIDebugOnce(id, ...) yarp::os::Log::nolog(__VA_ARGS__)
298# define yIDebugThreadOnce(id, ...) yarp::os::Log::nolog(__VA_ARGS__)
299# define yIDebugThrottle(id, period, ...) yarp::os::Log::nolog(__VA_ARGS__)
300# define yIDebugThreadThrottle(id, period, ...) yarp::os::Log::nolog(__VA_ARGS__)
301# define yIDebugExternalTime(id, externaltime, ...) yarp::os::Log::nolog(__VA_ARGS__)
302# define yIDebugExternalTimeOnce(id, externaltime, ...) yarp::os::Log::nolog(__VA_ARGS__)
303# define yIDebugExternalTimeThreadOnce(id, externaltime, ...) yarp::os::Log::nolog(__VA_ARGS__)
304# define yIDebugExternalTimeThrottle(id, externaltime, period, ...) yarp::os::Log::nolog(__VA_ARGS__)
305# define yIDebugExternalTimeThreadThrottle(id, externaltime, period, ...) yarp::os::Log::nolog(__VA_ARGS__)
306
307#endif
308
309#define yInfo(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__).info(__VA_ARGS__)
310#define yInfoOnce(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_ONCE_CALLBACK).info(__VA_ARGS__)
311#define yInfoThreadOnce(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THREADONCE_CALLBACK).info(__VA_ARGS__)
312#define yInfoThrottle(period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THROTTLE_CALLBACK(period)).info(__VA_ARGS__)
313#define yInfoThreadThrottle(period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THREADTHROTTLE_CALLBACK(period)).info(__VA_ARGS__)
314#define yInfoExternalTime(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime).info(__VA_ARGS__)
315#define yInfoExternalTimeOnce(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_ONCE_CALLBACK).info(__VA_ARGS__)
316#define yInfoExternalTimeThreadOnce(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THREADONCE_CALLBACK).info(__VA_ARGS__)
317#define yInfoExternalTimeThrottle(externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THROTTLE_CALLBACK(period)).info(__VA_ARGS__)
318#define yInfoExternalTimeThreadThrottle(externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THREADTHROTTLE_CALLBACK(period)).info(__VA_ARGS__)
319#define yIInfo(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id).info(__VA_ARGS__)
320#define yIInfoOnce(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_ONCE_CALLBACK).info(__VA_ARGS__)
321#define yIInfoThreadOnce(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THREADONCE_CALLBACK).info(__VA_ARGS__)
322#define yIInfoThrottle(id, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THROTTLE_CALLBACK(period)).info(__VA_ARGS__)
323#define yIInfoThreadThrottle(id, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THREADTHROTTLE_CALLBACK(period)).info(__VA_ARGS__)
324#define yIInfoExternalTime(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime).info(__VA_ARGS__)
325#define yIInfoExternalTimeOnce(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_ONCE_CALLBACK).info(__VA_ARGS__)
326#define yIInfoExternalTimeThreadOnce(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THREADONCE_CALLBACK).info(__VA_ARGS__)
327#define yIInfoExternalTimeThrottle(id, externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THROTTLE_CALLBACK(period)).info(__VA_ARGS__)
328#define yIInfoExternalTimeThreadThrottle(id, externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THREADTHROTTLE_CALLBACK(period)).info(__VA_ARGS__)
329
330#define yWarning(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__).warning(__VA_ARGS__)
331#define yWarningOnce(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_ONCE_CALLBACK).warning(__VA_ARGS__)
332#define yWarningThreadOnce(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THREADONCE_CALLBACK).warning(__VA_ARGS__)
333#define yWarningThrottle(period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THROTTLE_CALLBACK(period)).warning(__VA_ARGS__)
334#define yWarningThreadThrottle(period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THREADTHROTTLE_CALLBACK(period)).warning(__VA_ARGS__)
335#define yWarningExternalTime(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime).warning(__VA_ARGS__)
336#define yWarningExternalTimeOnce(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_ONCE_CALLBACK).warning(__VA_ARGS__)
337#define yWarningExternalTimeThreadOnce(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THREADONCE_CALLBACK).warning(__VA_ARGS__)
338#define yWarningExternalTimeThrottle(externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THROTTLE_CALLBACK(period)).warning(__VA_ARGS__)
339#define yWarningExternalTimeThreadThrottle(externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THREADTHROTTLE_CALLBACK(period)).warning(__VA_ARGS__)
340#define yIWarning(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id).warning(__VA_ARGS__)
341#define yIWarningOnce(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_ONCE_CALLBACK).warning(__VA_ARGS__)
342#define yIWarningThreadOnce(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THREADONCE_CALLBACK).warning(__VA_ARGS__)
343#define yIWarningThrottle(id, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THROTTLE_CALLBACK(period)).warning(__VA_ARGS__)
344#define yIWarningThreadThrottle(id, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THREADTHROTTLE_CALLBACK(period)).warning(__VA_ARGS__)
345#define yIWarningExternalTime(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime).warning(__VA_ARGS__)
346#define yIWarningExternalTimeOnce(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_ONCE_CALLBACK).warning(__VA_ARGS__)
347#define yIWarningExternalTimeThreadOnce(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THREADONCE_CALLBACK).warning(__VA_ARGS__)
348#define yIWarningExternalTimeThrottle(id, externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THROTTLE_CALLBACK(period)).warning(__VA_ARGS__)
349#define yIWarningExternalTimeThreadThrottle(id, externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THREADTHROTTLE_CALLBACK(period)).warning(__VA_ARGS__)
350
351#define yError(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__).error(__VA_ARGS__)
352#define yErrorOnce(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_ONCE_CALLBACK).error(__VA_ARGS__)
353#define yErrorThreadOnce(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THREADONCE_CALLBACK).error(__VA_ARGS__)
354#define yErrorThrottle(period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THROTTLE_CALLBACK(period)).error(__VA_ARGS__)
355#define yErrorThreadThrottle(period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THREADTHROTTLE_CALLBACK(period)).error(__VA_ARGS__)
356#define yErrorExternalTime(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime).error(__VA_ARGS__)
357#define yErrorExternalTimeOnce(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_ONCE_CALLBACK).error(__VA_ARGS__)
358#define yErrorExternalTimeThreadOnce(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THREADONCE_CALLBACK).error(__VA_ARGS__)
359#define yErrorExternalTimeThrottle(externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THROTTLE_CALLBACK(period)).error(__VA_ARGS__)
360#define yErrorExternalTimeThreadThrottle(externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THREADTHROTTLE_CALLBACK(period)).error(__VA_ARGS__)
361#define yIError(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id).error(__VA_ARGS__)
362#define yIErrorOnce(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_ONCE_CALLBACK).error(__VA_ARGS__)
363#define yIErrorThreadOnce(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THREADONCE_CALLBACK).error(__VA_ARGS__)
364#define yIErrorThrottle(id, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THROTTLE_CALLBACK(period)).error(__VA_ARGS__)
365#define yIErrorThreadThrottle(id, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THREADTHROTTLE_CALLBACK(period)).error(__VA_ARGS__)
366#define yIErrorExternalTime(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime).error(__VA_ARGS__)
367#define yIErrorExternalTimeOnce(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_ONCE_CALLBACK).error(__VA_ARGS__)
368#define yIErrorExternalTimeThreadOnce(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THREADONCE_CALLBACK).error(__VA_ARGS__)
369#define yIErrorExternalTimeThrottle(id, externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THROTTLE_CALLBACK(period)).error(__VA_ARGS__)
370#define yIErrorExternalTimeThreadThrottle(id, externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THREADTHROTTLE_CALLBACK(period)).error(__VA_ARGS__)
371
372#define yFatal(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__).fatal(__VA_ARGS__)
373#define yFatalExternalTime(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime).fatal(__VA_ARGS__)
374#define yIFatal(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id).fatal(__VA_ARGS__)
375#define yIFatalExternalTime(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime).fatal(__VA_ARGS__)
376
377#ifndef NDEBUG
378# define yAssert(x) \
379 if (!(x)) { \
380 yFatal("Assertion failure at %s:%d (%s)", __FILE__, __LINE__, #x); \
381 }
382# define yAssertExternalTime(externaltime, x) \
383 if (!(x)) { \
384 yFatalExternalTime(externaltime, "Assertion failure at %s:%d (%s)", __FILE__, __LINE__, #x); \
385 }
386# define yIAssert(id, x) \
387 if (!(x)) { \
388 yIFatal(id, "Assertion failure at %s:%d (%s)", __FILE__, __LINE__, #x); \
389 }
390# define yIAssertExternalTime(id, externaltime, x) \
391 if (!(x)) { \
392 yIFatalExternalTime(id, externaltime, "Assertion failure at %s:%d (%s)", __FILE__, __LINE__, #x); \
393 }
394#else
395# define yAssert(x)
396# define yAssertExternalTime(externaltime, x) { YARP_UNUSED(externaltime); }
397# define yIAssert(x) { YARP_UNUSED(id); }
398# define yIAssertExternalTime(externaltime, x) { YARP_UNUSED(id); YARP_UNUSED(externaltime); }
399#endif
400
401#define YARP_FIXME_NOTIMPLEMENTED(what) yWarning("FIXME: %s not yet implemented", what);
402
403
407YARP_os_API void yarp_print_trace(FILE* out, const char* file, unsigned int line);
408
409
410#endif // YARP_OS_LOG_H
#define YARP_ATTRIBUTE_FORMAT(style, fmt, args)
Definition Log.h:33
void yarp_print_trace(FILE *out, const char *file, unsigned int line)
Low level function for printing a stack trace, if implemented (ACE or gcc/Linux).
Definition Log.cpp:1120
A mini-server for performing network communication in the background.
@ ErrorType
Definition Log.h:95
@ DebugType
Definition Log.h:92
@ TraceType
Definition Log.h:91
@ InfoType
Definition Log.h:93
@ FatalType
Definition Log.h:96
@ WarningType
Definition Log.h:94
void(*)(yarp::os::Log::LogType type, const char *msg, const char *file, const unsigned int line, const char *func, double systemtime, double networktime, double externaltime, const char *comp_name, const char *id) LogCallback
Definition Log.h:123
An interface to the operating system, including Port based communication.
The main, catch-all namespace for YARP.
Definition dirs.h:16
std::ostream & operator<<(std::ostream &os, StrStream &sstr)
Definition utility.cpp:85
#define YARP_NORETURN
Definition api.h:156
#define YARP_os_API
Definition api.h:18