YARP
Yet Another Robot Platform
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
88 enum LogType : uint8_t
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;
108 LogStream debug() const;
109 LogStream info() const;
110 LogStream warning() const;
111 LogStream error() 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#ifndef YARP_NO_DEPRECATED // Since YARP 3.4
126 YARP_DEPRECATED_MSG("Use setPrintCallback instead")
127 static void setLogCallback(LogCallback);
128#endif // YARP_NO_DEPRECATED
129
130 static void setMinimumPrintLevel(LogType level);
131 static LogType minimumPrintLevel();
132 static LogType defaultMinimumPrintLevel();
133
134 static void setMinimumForwardLevel(LogType level);
135 static LogType minimumForwardLevel();
136 static LogType defaultMinimumForwardLevel();
137
138 static void setPrintCallback(LogCallback);
139 static LogCallback printCallback();
140 static LogCallback defaultPrintCallback();
141
142 static void setForwardCallback(LogCallback);
143 static LogCallback forwardCallback();
144 static LogCallback defaultForwardCallback();
145
146
147#ifndef DOXYGEN_SHOULD_SKIP_THIS
148 static void nolog(const char* msg, ...) {}
149 struct NoLog
150 {
151 template <typename T>
152 NoLog& operator<<(const T&)
153 {
154 return *this;
155 }
156 };
157 static NoLog nolog() { return NoLog(); }
158
159private:
160 yarp::os::impl::LogPrivate* const mPriv;
161
162 friend class yarp::os::LogStream;
163
164 // This callback is called by LogStream
165 static void do_log(yarp::os::Log::LogType type,
166 const char* msg,
167 const char* file,
168 const unsigned int line,
169 const char* func,
170 double systemtime,
171 double networktime,
172 double externaltime,
173 const LogComponent& comp_name,
174 const std::string_view id);
175
176 // This component is used for yDebug-family output, and is called by LogStream
177 static const LogComponent& defaultLogComponent();
178
179 // This component is used for internal debug output, and is called by LogStream
180 static const LogComponent& logInternalComponent();
181#endif // DOXYGEN_SHOULD_SKIP_THIS
182}; // class Log
183
184} // namespace yarp::os
185
186
187#define YARP_ONCE_CALLBACK \
188 [](){ \
189 static std::atomic_flag flag = ATOMIC_FLAG_INIT; \
190 return !flag.test_and_set(); \
191 }
192
193#define YARP_THREADONCE_CALLBACK \
194 [](){ \
195 thread_local std::atomic_flag flag = ATOMIC_FLAG_INIT; \
196 return !flag.test_and_set(); \
197 }
198
199#define YARP_THROTTLE_CALLBACK(period) \
200 [](){ \
201 static double last = -period; \
202 static std::mutex mutex; \
203 std::lock_guard<std::mutex> lock(mutex); \
204 double now = yarp::os::SystemClock::nowSystem(); \
205 if (now >= last + period) { \
206 last = now; \
207 return true; \
208 } \
209 return false; \
210 }
211
212#define YARP_THREADTHROTTLE_CALLBACK(period) \
213 [](){ \
214 thread_local double last = -period; \
215 double now = yarp::os::SystemClock::nowSystem(); \
216 if (now >= last + period) { \
217 last = now; \
218 return true; \
219 } \
220 return false; \
221 }
222
223
224
225#ifndef NDEBUG
226# define yTrace(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__).trace(__VA_ARGS__)
227# define yTraceOnce(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_ONCE_CALLBACK).trace(__VA_ARGS__)
228# define yTraceThreadOnce(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THREADONCE_CALLBACK).trace(__VA_ARGS__)
229# define yTraceThrottle(period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THROTTLE_CALLBACK(period)).trace(__VA_ARGS__)
230# define yTraceThreadThrottle(period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THREADTHROTTLE_CALLBACK(period)).trace(__VA_ARGS__)
231# define yTraceExternalTime(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime).trace(__VA_ARGS__)
232# define yTraceExternalTimeOnce(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_ONCE_CALLBACK).trace(__VA_ARGS__)
233# define yTraceExternalTimeThreadOnce(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THREADONCE_CALLBACK).trace(__VA_ARGS__)
234# define yTraceExternalTimeThrottle(externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THROTTLE_CALLBACK(period)).trace(__VA_ARGS__)
235# define yTraceExternalTimeThreadThrottle(externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THREADTHROTTLE_CALLBACK(period)).trace(__VA_ARGS__)
236# define yITrace(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id).trace(__VA_ARGS__)
237# define yITraceOnce(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_ONCE_CALLBACK).trace(__VA_ARGS__)
238# define yITraceThreadOnce(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THREADONCE_CALLBACK).trace(__VA_ARGS__)
239# define yITraceThrottle(id, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THROTTLE_CALLBACK(period)).trace(__VA_ARGS__)
240# define yITraceThreadThrottle(id, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THREADTHROTTLE_CALLBACK(period)).trace(__VA_ARGS__)
241# define yITraceExternalTime(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime).trace(__VA_ARGS__)
242# define yITraceExternalTimeOnce(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_ONCE_CALLBACK).trace(__VA_ARGS__)
243# define yITraceExternalTimeThreadOnce(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THREADONCE_CALLBACK).trace(__VA_ARGS__)
244# define yITraceExternalTimeThrottle(id, externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THROTTLE_CALLBACK(period)).trace(__VA_ARGS__)
245# define yITraceExternalTimeThreadThrottle(id, externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THREADTHROTTLE_CALLBACK(period)).trace(__VA_ARGS__)
246#else
247# define yTrace(...) yarp::os::Log::nolog(__VA_ARGS__)
248# define yTraceOnce(...) yarp::os::Log::nolog(__VA_ARGS__)
249# define yTraceThreadOnce(...) yarp::os::Log::nolog(__VA_ARGS__)
250# define yTraceThrottle(period, ...) yarp::os::Log::nolog(__VA_ARGS__)
251# define yTraceThreadThrottle(period, ...) yarp::os::Log::nolog(__VA_ARGS__)
252# define yTraceExternalTime(externaltime, ...) yarp::os::Log::nolog(__VA_ARGS__)
253# define yTraceExternalTimeOnce(externaltime, ...) yarp::os::Log::nolog(__VA_ARGS__)
254# define yTraceExternalTimeThreadOnce(externaltime, ...) yarp::os::Log::nolog(__VA_ARGS__)
255# define yTraceExternalTimeThrottle(externaltime, period, ...) yarp::os::Log::nolog(__VA_ARGS__)
256# define yTraceExternalTimeThreadThrottle(externaltime, period, ...) yarp::os::Log::nolog(__VA_ARGS__)
257# define yITrace(id, ...) yarp::os::Log::nolog(__VA_ARGS__)
258# define yITraceOnce(id, ...) yarp::os::Log::nolog(__VA_ARGS__)
259# define yITraceThreadOnce(id, ...) yarp::os::Log::nolog(__VA_ARGS__)
260# define yITraceThrottle(id, period, ...) yarp::os::Log::nolog(__VA_ARGS__)
261# define yITraceThreadThrottle(id, period, ...) yarp::os::Log::nolog(__VA_ARGS__)
262# define yITraceExternalTime(id, externaltime, ...) yarp::os::Log::nolog(__VA_ARGS__)
263# define yITraceExternalTimeOnce(id, externaltime, ...) yarp::os::Log::nolog(__VA_ARGS__)
264# define yITraceExternalTimeThreadOnce(id, externaltime, ...) yarp::os::Log::nolog(__VA_ARGS__)
265# define yITraceExternalTimeThrottle(id, externaltime, period, ...) yarp::os::Log::nolog(__VA_ARGS__)
266# define yITraceExternalTimeThreadThrottle(id, externaltime, period, ...) yarp::os::Log::nolog(__VA_ARGS__)
267#endif
268
269#ifndef YARP_NO_DEBUG_OUTPUT
270# define yDebug(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__).debug(__VA_ARGS__)
271# define yDebugOnce(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_ONCE_CALLBACK).debug(__VA_ARGS__)
272# define yDebugThreadOnce(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THREADONCE_CALLBACK).debug(__VA_ARGS__)
273# define yDebugThrottle(period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THROTTLE_CALLBACK(period)).debug(__VA_ARGS__)
274# define yDebugThreadThrottle(period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THREADTHROTTLE_CALLBACK(period)).debug(__VA_ARGS__)
275# define yDebugExternalTime(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime).debug(__VA_ARGS__)
276# define yDebugExternalTimeOnce(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_ONCE_CALLBACK).debug(__VA_ARGS__)
277# define yDebugExternalTimeThreadOnce(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THREADONCE_CALLBACK).debug(__VA_ARGS__)
278# define yDebugExternalTimeThrottle(externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THROTTLE_CALLBACK(period)).debug(__VA_ARGS__)
279# define yDebugExternalTimeThreadThrottle(externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THREADTHROTTLE_CALLBACK(period)).debug(__VA_ARGS__)
280# define yIDebug(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id).debug(__VA_ARGS__)
281# define yIDebugOnce(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_ONCE_CALLBACK).debug(__VA_ARGS__)
282# define yIDebugThreadOnce(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THREADONCE_CALLBACK).debug(__VA_ARGS__)
283# define yIDebugThrottle(id, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THROTTLE_CALLBACK(period)).debug(__VA_ARGS__)
284# define yIDebugThreadThrottle(id, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THREADTHROTTLE_CALLBACK(period)).debug(__VA_ARGS__)
285# define yIDebugExternalTime(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime).debug(__VA_ARGS__)
286# define yIDebugExternalTimeOnce(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_ONCE_CALLBACK).debug(__VA_ARGS__)
287# define yIDebugExternalTimeThreadOnce(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THREADONCE_CALLBACK).debug(__VA_ARGS__)
288# define yIDebugExternalTimeThrottle(id, externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THROTTLE_CALLBACK(period)).debug(__VA_ARGS__)
289# define yIDebugExternalTimeThreadThrottle(id, externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THREADTHROTTLE_CALLBACK(period)).debug(__VA_ARGS__)
290#else
291# define yDebug(...) yarp::os::Log::nolog(__VA_ARGS__)
292# define yDebugOnce(...) yarp::os::Log::nolog(__VA_ARGS__)
293# define yDebugThreadOnce(...) yarp::os::Log::nolog(__VA_ARGS__)
294# define yDebugThrottle(period, ...) yarp::os::Log::nolog(__VA_ARGS__)
295# define yDebugThreadThrottle(period, ...) yarp::os::Log::nolog(__VA_ARGS__)
296# define yDebugExternalTime(externaltime, ...) yarp::os::Log::nolog(__VA_ARGS__)
297# define yDebugExternalTimeOnce(externaltime, ...) yarp::os::Log::nolog(__VA_ARGS__)
298# define yDebugExternalTimeThreadOnce(externaltime, ...) yarp::os::Log::nolog(__VA_ARGS__)
299# define yDebugExternalTimeThrottle(externaltime, period, ...) yarp::os::Log::nolog(__VA_ARGS__)
300# define yDebugExternalTimeThreadThrottle(externaltime, period, ...) yarp::os::Log::nolog(__VA_ARGS__)
301# define yIDebug(id, ...) yarp::os::Log::nolog(__VA_ARGS__)
302# define yIDebugOnce(id, ...) yarp::os::Log::nolog(__VA_ARGS__)
303# define yIDebugThreadOnce(id, ...) yarp::os::Log::nolog(__VA_ARGS__)
304# define yIDebugThrottle(id, period, ...) yarp::os::Log::nolog(__VA_ARGS__)
305# define yIDebugThreadThrottle(id, period, ...) yarp::os::Log::nolog(__VA_ARGS__)
306# define yIDebugExternalTime(id, externaltime, ...) yarp::os::Log::nolog(__VA_ARGS__)
307# define yIDebugExternalTimeOnce(id, externaltime, ...) yarp::os::Log::nolog(__VA_ARGS__)
308# define yIDebugExternalTimeThreadOnce(id, externaltime, ...) yarp::os::Log::nolog(__VA_ARGS__)
309# define yIDebugExternalTimeThrottle(id, externaltime, period, ...) yarp::os::Log::nolog(__VA_ARGS__)
310# define yIDebugExternalTimeThreadThrottle(id, externaltime, period, ...) yarp::os::Log::nolog(__VA_ARGS__)
311
312#endif
313
314#define yInfo(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__).info(__VA_ARGS__)
315#define yInfoOnce(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_ONCE_CALLBACK).info(__VA_ARGS__)
316#define yInfoThreadOnce(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THREADONCE_CALLBACK).info(__VA_ARGS__)
317#define yInfoThrottle(period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THROTTLE_CALLBACK(period)).info(__VA_ARGS__)
318#define yInfoThreadThrottle(period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THREADTHROTTLE_CALLBACK(period)).info(__VA_ARGS__)
319#define yInfoExternalTime(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime).info(__VA_ARGS__)
320#define yInfoExternalTimeOnce(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_ONCE_CALLBACK).info(__VA_ARGS__)
321#define yInfoExternalTimeThreadOnce(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THREADONCE_CALLBACK).info(__VA_ARGS__)
322#define yInfoExternalTimeThrottle(externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THROTTLE_CALLBACK(period)).info(__VA_ARGS__)
323#define yInfoExternalTimeThreadThrottle(externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THREADTHROTTLE_CALLBACK(period)).info(__VA_ARGS__)
324#define yIInfo(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id).info(__VA_ARGS__)
325#define yIInfoOnce(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_ONCE_CALLBACK).info(__VA_ARGS__)
326#define yIInfoThreadOnce(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THREADONCE_CALLBACK).info(__VA_ARGS__)
327#define yIInfoThrottle(id, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THROTTLE_CALLBACK(period)).info(__VA_ARGS__)
328#define yIInfoThreadThrottle(id, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THREADTHROTTLE_CALLBACK(period)).info(__VA_ARGS__)
329#define yIInfoExternalTime(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime).info(__VA_ARGS__)
330#define yIInfoExternalTimeOnce(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_ONCE_CALLBACK).info(__VA_ARGS__)
331#define yIInfoExternalTimeThreadOnce(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THREADONCE_CALLBACK).info(__VA_ARGS__)
332#define yIInfoExternalTimeThrottle(id, externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THROTTLE_CALLBACK(period)).info(__VA_ARGS__)
333#define yIInfoExternalTimeThreadThrottle(id, externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THREADTHROTTLE_CALLBACK(period)).info(__VA_ARGS__)
334
335#define yWarning(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__).warning(__VA_ARGS__)
336#define yWarningOnce(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_ONCE_CALLBACK).warning(__VA_ARGS__)
337#define yWarningThreadOnce(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THREADONCE_CALLBACK).warning(__VA_ARGS__)
338#define yWarningThrottle(period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THROTTLE_CALLBACK(period)).warning(__VA_ARGS__)
339#define yWarningThreadThrottle(period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THREADTHROTTLE_CALLBACK(period)).warning(__VA_ARGS__)
340#define yWarningExternalTime(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime).warning(__VA_ARGS__)
341#define yWarningExternalTimeOnce(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_ONCE_CALLBACK).warning(__VA_ARGS__)
342#define yWarningExternalTimeThreadOnce(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THREADONCE_CALLBACK).warning(__VA_ARGS__)
343#define yWarningExternalTimeThrottle(externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THROTTLE_CALLBACK(period)).warning(__VA_ARGS__)
344#define yWarningExternalTimeThreadThrottle(externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THREADTHROTTLE_CALLBACK(period)).warning(__VA_ARGS__)
345#define yIWarning(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id).warning(__VA_ARGS__)
346#define yIWarningOnce(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_ONCE_CALLBACK).warning(__VA_ARGS__)
347#define yIWarningThreadOnce(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THREADONCE_CALLBACK).warning(__VA_ARGS__)
348#define yIWarningThrottle(id, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THROTTLE_CALLBACK(period)).warning(__VA_ARGS__)
349#define yIWarningThreadThrottle(id, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THREADTHROTTLE_CALLBACK(period)).warning(__VA_ARGS__)
350#define yIWarningExternalTime(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime).warning(__VA_ARGS__)
351#define yIWarningExternalTimeOnce(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_ONCE_CALLBACK).warning(__VA_ARGS__)
352#define yIWarningExternalTimeThreadOnce(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THREADONCE_CALLBACK).warning(__VA_ARGS__)
353#define yIWarningExternalTimeThrottle(id, externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THROTTLE_CALLBACK(period)).warning(__VA_ARGS__)
354#define yIWarningExternalTimeThreadThrottle(id, externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THREADTHROTTLE_CALLBACK(period)).warning(__VA_ARGS__)
355
356#define yError(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__).error(__VA_ARGS__)
357#define yErrorOnce(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_ONCE_CALLBACK).error(__VA_ARGS__)
358#define yErrorThreadOnce(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THREADONCE_CALLBACK).error(__VA_ARGS__)
359#define yErrorThrottle(period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THROTTLE_CALLBACK(period)).error(__VA_ARGS__)
360#define yErrorThreadThrottle(period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, YARP_THREADTHROTTLE_CALLBACK(period)).error(__VA_ARGS__)
361#define yErrorExternalTime(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime).error(__VA_ARGS__)
362#define yErrorExternalTimeOnce(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_ONCE_CALLBACK).error(__VA_ARGS__)
363#define yErrorExternalTimeThreadOnce(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THREADONCE_CALLBACK).error(__VA_ARGS__)
364#define yErrorExternalTimeThrottle(externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THROTTLE_CALLBACK(period)).error(__VA_ARGS__)
365#define yErrorExternalTimeThreadThrottle(externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime, YARP_THREADTHROTTLE_CALLBACK(period)).error(__VA_ARGS__)
366#define yIError(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id).error(__VA_ARGS__)
367#define yIErrorOnce(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_ONCE_CALLBACK).error(__VA_ARGS__)
368#define yIErrorThreadOnce(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THREADONCE_CALLBACK).error(__VA_ARGS__)
369#define yIErrorThrottle(id, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THROTTLE_CALLBACK(period)).error(__VA_ARGS__)
370#define yIErrorThreadThrottle(id, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, YARP_THREADTHROTTLE_CALLBACK(period)).error(__VA_ARGS__)
371#define yIErrorExternalTime(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime).error(__VA_ARGS__)
372#define yIErrorExternalTimeOnce(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_ONCE_CALLBACK).error(__VA_ARGS__)
373#define yIErrorExternalTimeThreadOnce(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THREADONCE_CALLBACK).error(__VA_ARGS__)
374#define yIErrorExternalTimeThrottle(id, externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THROTTLE_CALLBACK(period)).error(__VA_ARGS__)
375#define yIErrorExternalTimeThreadThrottle(id, externaltime, period, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime, YARP_THREADTHROTTLE_CALLBACK(period)).error(__VA_ARGS__)
376
377#define yFatal(...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__).fatal(__VA_ARGS__)
378#define yFatalExternalTime(externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, externaltime).fatal(__VA_ARGS__)
379#define yIFatal(id, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id).fatal(__VA_ARGS__)
380#define yIFatalExternalTime(id, externaltime, ...) yarp::os::Log(__FILE__, __LINE__, __YFUNCTION__, id, externaltime).fatal(__VA_ARGS__)
381
382#ifndef NDEBUG
383# define yAssert(x) \
384 if (!(x)) { \
385 yFatal("Assertion failure at %s:%d (%s)", __FILE__, __LINE__, #x); \
386 }
387# define yAssertExternalTime(externaltime, x) \
388 if (!(x)) { \
389 yFatalExternalTime(externaltime, "Assertion failure at %s:%d (%s)", __FILE__, __LINE__, #x); \
390 }
391# define yIAssert(id, x) \
392 if (!(x)) { \
393 yIFatal(id, "Assertion failure at %s:%d (%s)", __FILE__, __LINE__, #x); \
394 }
395# define yIAssertExternalTime(id, externaltime, x) \
396 if (!(x)) { \
397 yIFatalExternalTime(id, externaltime, "Assertion failure at %s:%d (%s)", __FILE__, __LINE__, #x); \
398 }
399#else
400# define yAssert(x)
401# define yAssertExternalTime(externaltime, x) { YARP_UNUSED(externaltime); }
402# define yIAssert(x) { YARP_UNUSED(id); }
403# define yIAssertExternalTime(externaltime, x) { YARP_UNUSED(id); YARP_UNUSED(externaltime); }
404#endif
405
406#define YARP_FIXME_NOTIMPLEMENTED(what) yWarning("FIXME: %s not yet implemented", what);
407
408
412YARP_os_API void yarp_print_trace(FILE* out, const char* file, unsigned int line);
413
414
415#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:1127
bool(*)() Predicate
Definition: Log.h:52
@ 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
#define YARP_DEPRECATED_MSG(MSG)
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition: compiler.h:2895
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