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