aboutsummaryrefslogtreecommitdiffstats
path: root/host/include
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2017-07-20 17:36:31 -0700
committerMartin Braun <martin.braun@ettus.com>2017-07-21 09:24:26 -0700
commit8223a289727bbda353bd7129512daf00d46d898c (patch)
treeb4e170612b71209e922e72b8d1611d02b2c5e896 /host/include
parentfabed5f21324473a5b1345ce5d4ff8807715e7eb (diff)
downloaduhd-8223a289727bbda353bd7129512daf00d46d898c.tar.gz
uhd-8223a289727bbda353bd7129512daf00d46d898c.tar.bz2
uhd-8223a289727bbda353bd7129512daf00d46d898c.zip
C API: Added logging macros
Diffstat (limited to 'host/include')
-rw-r--r--host/include/uhd.h1
-rw-r--r--host/include/uhd/utils/CMakeLists.txt1
-rw-r--r--host/include/uhd/utils/log.h96
3 files changed, 98 insertions, 0 deletions
diff --git a/host/include/uhd.h b/host/include/uhd.h
index 8647e25e4..4844f153b 100644
--- a/host/include/uhd.h
+++ b/host/include/uhd.h
@@ -37,5 +37,6 @@
#include <uhd/usrp_clock/usrp_clock.h>
#include <uhd/utils/thread_priority.h>
+#include <uhd/utils/log.h>
#endif /* INCLUDED_UHD_H */
diff --git a/host/include/uhd/utils/CMakeLists.txt b/host/include/uhd/utils/CMakeLists.txt
index e176f2c77..2f04b31ff 100644
--- a/host/include/uhd/utils/CMakeLists.txt
+++ b/host/include/uhd/utils/CMakeLists.txt
@@ -47,6 +47,7 @@ UHD_INSTALL(FILES
IF(ENABLE_C_API)
UHD_INSTALL(FILES
thread_priority.h
+ log.h
DESTINATION ${INCLUDE_DIR}/uhd/utils
COMPONENT headers
)
diff --git a/host/include/uhd/utils/log.h b/host/include/uhd/utils/log.h
new file mode 100644
index 000000000..ce4c30ced
--- /dev/null
+++ b/host/include/uhd/utils/log.h
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2017 Ettus Research (National Instruments Corp.)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef INCLUDED_UHD_UTILS_LOG_H
+#define INCLUDED_UHD_UTILS_LOG_H
+
+#include <uhd/config.h>
+
+typedef enum {
+ UHD_LOG_LEVEL_TRACE,
+ UHD_LOG_LEVEL_DEBUG,
+ UHD_LOG_LEVEL_INFO,
+ UHD_LOG_LEVEL_WARNING,
+ UHD_LOG_LEVEL_ERROR,
+ UHD_LOG_LEVEL_FATAL
+} uhd_log_severity_level_t;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ void UHD_API _uhd_log(
+ const uhd_log_severity_level_t log_level,
+ const char *filename,
+ const int lineno,
+ const char *comp,
+ const char *format,
+ ...
+ );
+
+#ifdef __cplusplus
+};
+#endif
+
+
+#ifndef __cplusplus
+// macro-style logging (compile-time determined)
+#if UHD_LOG_MIN_LEVEL < 1
+#define UHD_LOG_TRACE(component, ...) \
+ _uhd_log(UHD_LOG_LEVEL_TRACE, __FILE__, __LINE__, component, __VA_ARGS__);
+#else
+#define UHD_LOG_TRACE(component, ...)
+#endif
+
+#if UHD_LOG_MIN_LEVEL < 2
+#define UHD_LOG_DEBUG(component, ...) \
+ _uhd_log(UHD_LOG_LEVEL_DEBUG, __FILE__, __LINE__, component, __VA_ARGS__);
+#else
+#define UHD_LOG_DEBUG(component, ...)
+#endif
+
+#if UHD_LOG_MIN_LEVEL < 3
+#define UHD_LOG_INFO(component, ...) \
+ _uhd_log(UHD_LOG_LEVEL_INFO, __FILE__, __LINE__, component, __VA_ARGS__);
+#else
+#define UHD_LOG_INFO(component, ...)
+#endif
+
+#if UHD_LOG_MIN_LEVEL < 4
+#define UHD_LOG_WARNING(component, ...) \
+ _uhd_log(UHD_LOG_LEVEL_WARNING, __FILE__, __LINE__, component, __VA_ARGS__);
+#else
+#define UHD_LOG_WARNING(component, ...)
+#endif
+
+#if UHD_LOG_MIN_LEVEL < 5
+#define UHD_LOG_ERROR(component, ...) \
+ _uhd_log(UHD_LOG_LEVEL_ERROR, __FILE__, __LINE__, component, __VA_ARGS__);
+#else
+#define UHD_LOG_ERROR(component, ...)
+#endif
+
+#if UHD_LOG_MIN_LEVEL < 6
+#define UHD_LOG_FATAL(component, ...) \
+ _uhd_log(UHD_LOG_LEVEL_FATAL, __FILE__, __LINE__, component, __VA_ARGS__);
+#else
+#define UHD_LOG_FATAL(component, ...)
+#endif
+
+#endif /* #ifndef __cplusplus */
+
+#endif /* INCLUDED_UHD_UTILS_LOG_H */