[Log] internal log function
authorJaeyun <jy1210.jung@samsung.com>
Fri, 8 Jul 2022 11:50:10 +0000 (20:50 +0900)
committerjaeyun-jung <39614140+jaeyun-jung@users.noreply.github.com>
Thu, 28 Jul 2022 09:35:27 +0000 (18:35 +0900)
Remove glib, add internal log function.

Signed-off-by: Jaeyun <jy1210.jung@samsung.com>
include/nnstreamer-edge.h
src/libnnstreamer-edge/nnstreamer-edge-common.h

index a11773130c9828face8eb952cd6cd90e310d00cb..bb018ffe16f1b4c24410c6c2afb9c02a74076a67 100644 (file)
@@ -24,6 +24,7 @@
 #include <stddef.h>
 #include <stdbool.h>
 #include <stdint.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
index 1d366373afd89e601127b7e65695ea05c622bba1..a07e578971acdc3dcd189a84b22bd1bbc3f77b96 100644 (file)
@@ -73,17 +73,70 @@ typedef struct {
   nns_edge_raw_data_s data;
 } nns_edge_event_s;
 
+#define TAG_NAME "nnstreamer-edge"
+
+#if defined(__TIZEN__)
+#include <dlog.h>
+
+#define nns_edge_logd(...) dlog_print (DLOG_DEBUG, TAG_NAME, __VA_ARGS__)
+#define nns_edge_logi(...) dlog_print (DLOG_INFO, TAG_NAME, __VA_ARGS__)
+#define nns_edge_logw(...) dlog_print (DLOG_WARN, TAG_NAME, __VA_ARGS__)
+#define nns_edge_loge(...) dlog_print (DLOG_ERROR, TAG_NAME, __VA_ARGS__)
+#define nns_edge_logf(...) dlog_print (DLOG_FATAL, TAG_NAME, __VA_ARGS__)
+#elif defined(__ANDROID__)
+#include <android/log.h>
+
+#define nns_edge_logd(...) __android_log_print (ANDROID_LOG_DEBUG, TAG_NAME, __VA_ARGS__)
+#define nns_edge_logi(...) __android_log_print (ANDROID_LOG_INFO, TAG_NAME, __VA_ARGS__)
+#define nns_edge_logw(...) __android_log_print (ANDROID_LOG_WARN, TAG_NAME, __VA_ARGS__)
+#define nns_edge_loge(...) __android_log_print (ANDROID_LOG_ERROR, TAG_NAME, __VA_ARGS__)
+#define nns_edge_logf(...) __android_log_print (ANDROID_LOG_FATAL, TAG_NAME, __VA_ARGS__)
+#else
 /**
- * @todo add log util for nnstreamer-edge.
- * 1. define tag (e.g., "nnstreamer-edge").
- * 2. consider macros to print function and line.
- * 3. new API to get last error.
+ * @brief Internal enumeration for log message.
  */
-#define nns_edge_logi g_info
-#define nns_edge_logw g_warning
-#define nns_edge_loge g_critical
-#define nns_edge_logd g_debug
-#define nns_edge_logf g_error
+typedef enum {
+  NE_LOG_DEBUG = 0,
+  NE_LOG_INFO,
+  NE_LOG_WARNING,
+  NE_LOG_ERROR,
+  NE_LOG_FATAL,
+  NE_LOG_NONE
+} nns_edge_log_level_e;
+
+/**
+ * @brief Internal util function to print log message.
+ */
+static inline void
+nns_edge_print_log (nns_edge_log_level_e level, const char *fmt, ...)
+{
+  const char *level_str[] = {
+    [NE_LOG_DEBUG] = "DEBUG",
+    [NE_LOG_INFO] = "INFO",
+    [NE_LOG_WARNING] = "WARNING",
+    [NE_LOG_ERROR] = "ERROR",
+    [NE_LOG_FATAL] = "FATAL",
+    [NE_LOG_NONE] = "DEBUG",
+  };
+
+  va_list args;
+
+  /** @todo expand log util and handle log level (debug, release) */
+  va_start (args, fmt);
+
+  printf ("[%s][%s] ", level_str[level], TAG_NAME);
+  vprintf (fmt, args);
+  printf ("\n");
+
+  va_end (args);
+}
+
+#define nns_edge_logi(...) nns_edge_print_log (NE_LOG_INFO, __VA_ARGS__)
+#define nns_edge_logw(...) nns_edge_print_log (NE_LOG_WARNING, __VA_ARGS__)
+#define nns_edge_loge(...) nns_edge_print_log (NE_LOG_ERROR, __VA_ARGS__)
+#define nns_edge_logd(...) nns_edge_print_log (NE_LOG_DEBUG, __VA_ARGS__)
+#define nns_edge_logf(...) nns_edge_print_log (NE_LOG_FATAL, __VA_ARGS__)
+#endif
 
 /**
  * @brief Internal util function to get available port number.