···3232 */
33333434/*!
3535+ * @brief Logging level enum
3636+ */
3737+enum u_logging_level
3838+{
3939+ U_LOGGING_TRACE, //!< Trace messages, highly verbose.
4040+ U_LOGGING_DEBUG, //!< Debug messages, verbose.
4141+ U_LOGGING_INFO, //!< Info messages: not very verbose, not indicating a problem.
4242+ U_LOGGING_WARN, //!< Warning messages: indicating a potential problem
4343+ U_LOGGING_ERROR, //!< Error messages: indicating a problem
4444+ U_LOGGING_RAW, //!< Special level for raw printing, prints a new-line.
4545+};
4646+4747+/*!
3548 * For places where you really just want printf, prints a new-line.
3649 */
3750#define U_LOG_RAW(...) \
···3952 u_log(__FILE__, __LINE__, __func__, U_LOGGING_RAW, __VA_ARGS__); \
4053 } while (false)
41545555+/*!
5656+ * @name Base Logging Utilities
5757+ * In most cases, you will want to use another macro from this file, or a module/driver-local macro, to do your logging.
5858+ * @{
5959+ */
6060+/*!
6161+ * @brief Log a message at @p level , with file, line, and function context (always logs) - typically wrapped
6262+ * in a helper macro.
6363+ *
6464+ * @param level A @ref u_logging_level value for this message.
6565+ * @param ... Format string and optional format arguments.
6666+ */
4267#define U_LOG(level, ...) \
4368 do { \
4469 u_log(__FILE__, __LINE__, __func__, level, __VA_ARGS__); \
4570 } while (false)
46717272+/*!
7373+ * @brief Log at @p level only if the level is at least @p cond_level - typically wrapped in a helper macro.
7474+ *
7575+ * Adds file, line, and function context. Like U_LOG() but conditional.
7676+ *
7777+ * @param level A @ref u_logging_level value for this message.
7878+ * @param cond_level The minimum @ref u_logging_level that will be actually output.
7979+ * @param ... Format string and optional format arguments.
8080+ */
4781#define U_LOG_IFL(level, cond_level, ...) \
4882 do { \
4983 if (cond_level <= level) { \
5084 u_log(__FILE__, __LINE__, __func__, level, __VA_ARGS__); \
5185 } \
5286 } while (false)
5353-8787+/*!
8888+ * @brief Log at @p level for a given @ref xrt_device - typically wrapped in a helper macro.
8989+ *
9090+ * Adds file, line, and function context, and forwards device context from provided @p xdev .
9191+ *
9292+ * Like U_LOG() but calling u_log_xdev() (which takes a device) instead.
9393+ *
9494+ * @param level A @ref u_logging_level value for this message.
9595+ * @param xdev The @ref xrt_device pointer associated with this message.
9696+ * @param ... Format string and optional format arguments.
9797+ */
5498#define U_LOG_XDEV(level, xdev, ...) \
5599 do { \
56100 u_log_xdev(__FILE__, __LINE__, __func__, level, xdev, __VA_ARGS__); \
57101 } while (false)
5858-102102+/*!
103103+ * @brief Log at @p level for a given @ref xrt_device, only if the level is at least @p cond_level - typically wrapped
104104+ * in a helper macro.
105105+ *
106106+ * Adds file, line, and function context, and forwards device context from provided @p xdev .
107107+ * @param level A @ref u_logging_level value for this message.
108108+ * @param cond_level The minimum @ref u_logging_level that will be actually output.
109109+ * @param xdev The @ref xrt_device pointer associated with this message.
110110+ * @param ... Format string and optional format arguments.
111111+ */
59112#define U_LOG_XDEV_IFL(level, cond_level, xdev, ...) \
60113 do { \
61114 if (cond_level <= level) { \
···63116 } \
64117 } while (false)
651186666-// clang-format off
6767-#define U_LOG_T(...) U_LOG_IFL_T(u_log_get_global_level(), __VA_ARGS__)
6868-#define U_LOG_D(...) U_LOG_IFL_D(u_log_get_global_level(), __VA_ARGS__)
6969-#define U_LOG_I(...) U_LOG_IFL_I(u_log_get_global_level(), __VA_ARGS__)
7070-#define U_LOG_W(...) U_LOG_IFL_W(u_log_get_global_level(), __VA_ARGS__)
7171-#define U_LOG_E(...) U_LOG_IFL_E(u_log_get_global_level(), __VA_ARGS__)
721197373-#define U_LOG_IFL_T(cond_level, ...) U_LOG_IFL(U_LOGGING_TRACE, cond_level, __VA_ARGS__)
7474-#define U_LOG_IFL_D(cond_level, ...) U_LOG_IFL(U_LOGGING_DEBUG, cond_level, __VA_ARGS__)
7575-#define U_LOG_IFL_I(cond_level, ...) U_LOG_IFL(U_LOGGING_INFO, cond_level, __VA_ARGS__)
7676-#define U_LOG_IFL_W(cond_level, ...) U_LOG_IFL(U_LOGGING_WARN, cond_level, __VA_ARGS__)
7777-#define U_LOG_IFL_E(cond_level, ...) U_LOG_IFL(U_LOGGING_ERROR, cond_level, __VA_ARGS__)
7878-7979-#define U_LOG_XDEV_IFL_T(xdev, cond_level, ...) U_LOG_XDEV_IFL(U_LOGGING_TRACE, cond_level, xdev, __VA_ARGS__)
8080-#define U_LOG_XDEV_IFL_D(xdev, cond_level, ...) U_LOG_XDEV_IFL(U_LOGGING_DEBUG, cond_level, xdev, __VA_ARGS__)
8181-#define U_LOG_XDEV_IFL_I(xdev, cond_level, ...) U_LOG_XDEV_IFL(U_LOGGING_INFO, cond_level, xdev, __VA_ARGS__)
8282-#define U_LOG_XDEV_IFL_W(xdev, cond_level, ...) U_LOG_XDEV_IFL(U_LOGGING_WARN, cond_level, xdev, __VA_ARGS__)
8383-#define U_LOG_XDEV_IFL_E(xdev, cond_level, ...) U_LOG_XDEV_IFL(U_LOGGING_ERROR, cond_level, xdev, __VA_ARGS__)
8484-8585-#define U_LOG_XDEV_T(xdev, ...) U_LOG_XDEV(U_LOGGING_TRACE, xdev, __VA_ARGS__)
8686-#define U_LOG_XDEV_D(xdev, ...) U_LOG_XDEV(U_LOGGING_DEBUG, xdev, __VA_ARGS__)
8787-#define U_LOG_XDEV_I(xdev, ...) U_LOG_XDEV(U_LOGGING_INFO, xdev, __VA_ARGS__)
8888-#define U_LOG_XDEV_W(xdev, ...) U_LOG_XDEV(U_LOGGING_WARN, xdev, __VA_ARGS__)
8989-#define U_LOG_XDEV_E(xdev, ...) U_LOG_XDEV(U_LOGGING_ERROR, xdev, __VA_ARGS__)
9090-// clang-format on
9191-9292-enum u_logging_level
9393-{
9494- U_LOGGING_TRACE,
9595- U_LOGGING_DEBUG,
9696- U_LOGGING_INFO,
9797- U_LOGGING_WARN,
9898- U_LOGGING_ERROR,
9999- U_LOGGING_RAW, //!< Special level for raw printing, prints a new-line.
100100-};
101120102121/*!
103122 * Returns the global logging level, subsystems own logging level take precedence.
···106125u_log_get_global_level(void);
107126108127/*!
109109- * This function always logs, level is used for printing or passed to native
110110- * logging functions.
128128+ * @brief Main non-device-related log implementation function: do not call directly, use a macro that wraps it.
129129+ *
130130+ * This function always logs: level is used for printing or passed to native logging functions.
131131+ *
132132+ * @param file Source file name associated with a message
133133+ * @param line Source file line associated with a message
134134+ * @param func Function name associated with a message
135135+ * @param level Message level: used for formatting or forwarding to native log functions
136136+ * @param format Format string
137137+ * @param ... Format parameters
111138 */
112139void
113140u_log(const char *file, int line, const char *func, enum u_logging_level level, const char *format, ...)
114141 XRT_PRINTF_FORMAT(5, 6);
115142116143/*!
117117- * This function always logs, level is used for printing or passed to native
118118- * logging functions.
144144+ * @brief Main device-related log implementation function: do not call directly, use a macro that wraps it.
145145+ *
146146+ * This function always logs: level is used for printing or passed to native logging functions.
147147+ * @param file Source file name associated with a message
148148+ * @param line Source file line associated with a message
149149+ * @param func Function name associated with a message
150150+ * @param level Message level: used for formatting or forwarding to native log functions
151151+ * @param xdev The associated @ref xrt_device
152152+ * @param format Format string
153153+ * @param ... Format parameters
119154 */
120155void
121156u_log_xdev(const char *file,
···126161 const char *format,
127162 ...) XRT_PRINTF_FORMAT(6, 7);
128163164164+/*!
165165+ * @}
166166+ */
167167+168168+169169+/*!
170170+ * @name Logging macros conditional on global log level
171171+ *
172172+ * These each imply a log level, and will only log if the global log level is equal or lower.
173173+ * They are often used for one-off logging in a module with few other logging needs,
174174+ * where having a module-specific log level would be unnecessary.
175175+ *
176176+ * @see U_LOG_IFL, u_log_get_global_level()
177177+ * @param ... Format string and optional format arguments.
178178+ * @{
179179+ */
180180+//! Log a message at U_LOGGING_TRACE level, conditional on the global log level
181181+#define U_LOG_T(...) U_LOG_IFL_T(u_log_get_global_level(), __VA_ARGS__)
182182+183183+//! Log a message at U_LOGGING_DEBUG level, conditional on the global log level
184184+#define U_LOG_D(...) U_LOG_IFL_D(u_log_get_global_level(), __VA_ARGS__)
185185+186186+//! Log a message at U_LOGGING_INFO level, conditional on the global log level
187187+#define U_LOG_I(...) U_LOG_IFL_I(u_log_get_global_level(), __VA_ARGS__)
188188+189189+//! Log a message at U_LOGGING_WARN level, conditional on the global log level
190190+#define U_LOG_W(...) U_LOG_IFL_W(u_log_get_global_level(), __VA_ARGS__)
191191+192192+//! Log a message at U_LOGGING_ERROR level, conditional on the global log level
193193+#define U_LOG_E(...) U_LOG_IFL_E(u_log_get_global_level(), __VA_ARGS__)
194194+195195+/*!
196196+ * @}
197197+ */
198198+199199+/*!
200200+ * @name Logging macros conditional on provided log level
201201+ *
202202+ * These are often wrapped within a module, to automatically supply
203203+ * @p cond_level as appropriate for that module.
204204+ *
205205+ * @see U_LOG_IFL
206206+ * @param cond_level The minimum @ref u_logging_level that will be actually output.
207207+ * @param ... Format string and optional format arguments.
208208+ *
209209+ * @{
210210+ */
211211+//! Conditionally log a message at U_LOGGING_TRACE level.
212212+#define U_LOG_IFL_T(cond_level, ...) U_LOG_IFL(U_LOGGING_TRACE, cond_level, __VA_ARGS__)
213213+//! Conditionally log a message at U_LOGGING_DEBUG level.
214214+#define U_LOG_IFL_D(cond_level, ...) U_LOG_IFL(U_LOGGING_DEBUG, cond_level, __VA_ARGS__)
215215+//! Conditionally log a message at U_LOGGING_INFO level.
216216+#define U_LOG_IFL_I(cond_level, ...) U_LOG_IFL(U_LOGGING_INFO, cond_level, __VA_ARGS__)
217217+//! Conditionally log a message at U_LOGGING_WARN level.
218218+#define U_LOG_IFL_W(cond_level, ...) U_LOG_IFL(U_LOGGING_WARN, cond_level, __VA_ARGS__)
219219+//! Conditionally log a message at U_LOGGING_ERROR level.
220220+#define U_LOG_IFL_E(cond_level, ...) U_LOG_IFL(U_LOGGING_ERROR, cond_level, __VA_ARGS__)
221221+/*!
222222+ * @}
223223+ */
224224+225225+226226+227227+/*!
228228+ * @name Device-related logging macros conditional on provided log level
229229+ *
230230+ * These are often wrapped within a driver, to automatically supply @p xdev and
231231+ * @p cond_level from their conventional names and log level member variable.
232232+ *
233233+ * @param level A @ref u_logging_level value for this message.
234234+ * @param cond_level The minimum @ref u_logging_level that will be actually output.
235235+ * @param xdev The @ref xrt_device pointer associated with this message.
236236+ * @param ... Format string and optional format arguments.
237237+ *
238238+ * @{
239239+ */
240240+//! Conditionally log a device-related message at U_LOGGING_TRACE level.
241241+#define U_LOG_XDEV_IFL_T(xdev, cond_level, ...) U_LOG_XDEV_IFL(U_LOGGING_TRACE, cond_level, xdev, __VA_ARGS__)
242242+//! Conditionally log a device-related message at U_LOGGING_DEBUG level.
243243+#define U_LOG_XDEV_IFL_D(xdev, cond_level, ...) U_LOG_XDEV_IFL(U_LOGGING_DEBUG, cond_level, xdev, __VA_ARGS__)
244244+//! Conditionally log a device-related message at U_LOGGING_INFO level.
245245+#define U_LOG_XDEV_IFL_I(xdev, cond_level, ...) U_LOG_XDEV_IFL(U_LOGGING_INFO, cond_level, xdev, __VA_ARGS__)
246246+//! Conditionally log a device-related message at U_LOGGING_WARN level.
247247+#define U_LOG_XDEV_IFL_W(xdev, cond_level, ...) U_LOG_XDEV_IFL(U_LOGGING_WARN, cond_level, xdev, __VA_ARGS__)
248248+//! Conditionally log a device-related message at U_LOGGING_ERROR level.
249249+#define U_LOG_XDEV_IFL_E(xdev, cond_level, ...) U_LOG_XDEV_IFL(U_LOGGING_ERROR, cond_level, xdev, __VA_ARGS__)
250250+/*!
251251+ * @}
252252+ */
253253+254254+/*!
255255+ * @name Device-related logging macros that always log.
256256+ *
257257+ * These wrap U_LOG_XDEV() to supply the @p level - which is only used for formatting the output, these macros always
258258+ * log regardless of level.
259259+ *
260260+ * @param xdev The @ref xrt_device pointer associated with this message.
261261+ * @param ... Format string and optional format arguments.
262262+ * @{
263263+ */
264264+//! Log a device-related message at U_LOGGING_TRACE level (always logs).
265265+#define U_LOG_XDEV_T(xdev, ...) U_LOG_XDEV(U_LOGGING_TRACE, xdev, __VA_ARGS__)
266266+//! Log a device-related message at U_LOGGING_DEBUG level (always logs).
267267+#define U_LOG_XDEV_D(xdev, ...) U_LOG_XDEV(U_LOGGING_DEBUG, xdev, __VA_ARGS__)
268268+//! Log a device-related message at U_LOGGING_INFO level (always logs).
269269+#define U_LOG_XDEV_I(xdev, ...) U_LOG_XDEV(U_LOGGING_INFO, xdev, __VA_ARGS__)
270270+//! Log a device-related message at U_LOGGING_WARN level (always logs).
271271+#define U_LOG_XDEV_W(xdev, ...) U_LOG_XDEV(U_LOGGING_WARN, xdev, __VA_ARGS__)
272272+//! Log a device-related message at U_LOGGING_ERROR level (always logs).
273273+#define U_LOG_XDEV_E(xdev, ...) U_LOG_XDEV(U_LOGGING_ERROR, xdev, __VA_ARGS__)
274274+/*!
275275+ * @}
276276+ */
129277130278/*!
131279 * @}