[Common] define macro to print logs
authorJaeyun <jy1210.jung@samsung.com>
Thu, 12 Mar 2020 08:45:17 +0000 (17:45 +0900)
committerwooksong <wook16.song@samsung.com>
Fri, 13 Mar 2020 03:36:06 +0000 (12:36 +0900)
Add internal header to define common log formats.

Signed-off-by: Jaeyun <jy1210.jung@samsung.com>
api/android/api/src/main/jni/nnstreamer-native.h
api/capi/include/nnstreamer-capi-private.h
gst/nnstreamer/meson.build
gst/nnstreamer/nnstreamer_log.h [new file with mode: 0644]
gst/nnstreamer/tensor_common.h
gst/nnstreamer/tensor_filter/tensor_filter_common.c
jni/Android-app.mk
jni/Android-nnstreamer.mk
tests/nnstreamer_filter_reload/tensor_filter_reload_test.c

index 3758455..4495b8b 100644 (file)
 #define __NNSTREAMER_ANDROID_NATIVE_H__
 
 #include <jni.h>
-#include <android/log.h>
 
 #include <gst/gst.h>
 
 #include "nnstreamer.h"
 #include "nnstreamer-single.h"
 #include "nnstreamer-capi-private.h"
+#include "nnstreamer_log.h"
 #include "nnstreamer_plugin_api.h"
 #include "nnstreamer_plugin_api_filter.h"
 
-#define TAG "NNStreamer-native"
-
-#define nns_logi(...) \
-    __android_log_print (ANDROID_LOG_INFO, TAG, __VA_ARGS__)
-
-#define nns_logw(...) \
-    __android_log_print (ANDROID_LOG_WARN, TAG, __VA_ARGS__)
-
-#define nns_loge(...) \
-    __android_log_print (ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
-
-#define nns_logd(...) \
-    __android_log_print (ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
-
 #if GLIB_SIZEOF_VOID_P == 8
 #define CAST_TO_LONG(p) (jlong)(p)
 #define CAST_TO_TYPE(l,type) (type)(l)
index 7804fda..4aa9550 100644 (file)
@@ -30,6 +30,7 @@
 #include "nnstreamer.h"
 #include "nnstreamer-single.h"
 #include "tensor_typedef.h"
+#include "nnstreamer_log.h"
 
 /* Tizen ML feature */
 #if defined (__TIZEN__)
 #define release_tizen_resource(...)
 #endif
 
-#define TAG_NAME "nnstreamer-capi"
-
-#if defined(__TIZEN__)
-  #include <dlog.h>
-
-  #define ml_logi(...) \
-      dlog_print (DLOG_INFO, TAG_NAME, __VA_ARGS__)
-
-  #define ml_logw(...) \
-      dlog_print (DLOG_WARN, TAG_NAME, __VA_ARGS__)
-
-  #define ml_loge(...) \
-      dlog_print (DLOG_ERROR, TAG_NAME, __VA_ARGS__)
-
-  #define ml_logd(...) \
-      dlog_print (DLOG_DEBUG, TAG_NAME, __VA_ARGS__)
-
-#elif defined(__ANDROID__)
-  #include <android/log.h>
-
-  #define ml_logi(...) \
-      __android_log_print (ANDROID_LOG_INFO, TAG_NAME, __VA_ARGS__)
-
-  #define ml_logw(...) \
-      __android_log_print (ANDROID_LOG_WARN, TAG_NAME, __VA_ARGS__)
-
-  #define ml_loge(...) \
-      __android_log_print (ANDROID_LOG_ERROR, TAG_NAME, __VA_ARGS__)
-
-  #define ml_logd(...) \
-      __android_log_print (ANDROID_LOG_DEBUG, TAG_NAME, __VA_ARGS__)
-
-#else /* Linux distro */
-  #define ml_logi g_info
-  #define ml_logw g_warning
-  #define ml_loge g_critical
-  #define ml_logd g_debug
-#endif
-
 #ifdef __cplusplus
 extern "C" {
 #endif /* __cplusplus */
index 6c0ceea..efff547 100644 (file)
@@ -16,7 +16,11 @@ nnstreamer_base_deps = [
 ]
 
 if have_orcc
-  nnstreamer_base_deps += [orc_dep]
+  nnstreamer_base_deps += orc_dep
+endif
+
+if build_platform == 'tizen'
+  nnstreamer_base_deps += dependency('dlog')
 endif
 
 # Internal dependencies
diff --git a/gst/nnstreamer/nnstreamer_log.h b/gst/nnstreamer/nnstreamer_log.h
new file mode 100644 (file)
index 0000000..a28032f
--- /dev/null
@@ -0,0 +1,76 @@
+/**
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ */
+
+/**
+ * @file       nnstreamer_log.h
+ * @date       12 Mar 2020
+ * @brief      Internal log util for NNStreamer plugins and native APIs.
+ * @see                http://github.com/nnsuite/nnstreamer
+ * @author     Jaeyun Jung <jy1210.jung@samsung.com>
+ * @bug                No known bugs except for NYI items
+ */
+
+#ifndef __NNSTREAMER_LOG_H__
+#define __NNSTREAMER_LOG_H__
+
+G_BEGIN_DECLS
+
+#define TAG_NAME "nnstreamer"
+
+#if defined(__TIZEN__)
+#include <dlog.h>
+
+#define ml_logi(...) \
+    dlog_print (DLOG_INFO, TAG_NAME, __VA_ARGS__)
+
+#define ml_logw(...) \
+    dlog_print (DLOG_WARN, TAG_NAME, __VA_ARGS__)
+
+#define ml_loge(...) \
+    dlog_print (DLOG_ERROR, TAG_NAME, __VA_ARGS__)
+
+#define ml_logd(...) \
+    dlog_print (DLOG_DEBUG, TAG_NAME, __VA_ARGS__)
+
+#elif defined(__ANDROID__)
+#include <android/log.h>
+
+#define ml_logi(...) \
+    __android_log_print (ANDROID_LOG_INFO, TAG_NAME, __VA_ARGS__)
+
+#define ml_logw(...) \
+    __android_log_print (ANDROID_LOG_WARN, TAG_NAME, __VA_ARGS__)
+
+#define ml_loge(...) \
+    __android_log_print (ANDROID_LOG_ERROR, TAG_NAME, __VA_ARGS__)
+
+#define ml_logd(...) \
+    __android_log_print (ANDROID_LOG_DEBUG, TAG_NAME, __VA_ARGS__)
+
+#else /* Linux distro */
+#include <glib.h>
+
+#define ml_logi g_info
+#define ml_logw g_warning
+#define ml_loge g_critical
+#define ml_logd g_debug
+#endif
+
+#define nns_logi ml_logi
+#define nns_logw ml_logw
+#define nns_loge ml_loge
+#define nns_logd ml_logd
+
+G_END_DECLS
+#endif /* __NNSTREAMER_LOG_H__ */
index a10d27c..e4d13ab 100644 (file)
@@ -35,6 +35,7 @@
 #include <gst/base/gstcollectpads.h>
 
 #include "tensor_typedef.h"
+#include "nnstreamer_log.h"
 #include "nnstreamer_plugin_api.h"
 
 #ifdef HAVE_ORC
index 3796976..7281fde 100644 (file)
@@ -558,7 +558,7 @@ gst_tensor_filter_compare_tensors (GstTensorsInfo * info1,
 
   if (result) {
     /* print warning message */
-    g_warning ("Tensor info :\n%s", result);
+    nns_logw ("Tensor info :\n%s", result);
     g_free (result);
   }
 }
index 8938eaa..fd6626d 100644 (file)
@@ -104,6 +104,7 @@ LOCAL_MODULE    := tensor_repo_dynamic_test
 LOCAL_SRC_FILES += ../tests/nnstreamer_repo_dynamicity/tensor_repo_dynamic_test.c
 LOCAL_CFLAGS    += -O0 -DVERSION=\"$(NNSTREAMER_VERSION)\"
 LOCAL_CXXFLAGS  += -std=c++11 -DVERSION=\"$(NNSTREAMER_VERSION)\"
+LOCAL_LDLIBS    := -llog
 LOCAL_LDFLAGS   := $(CUSTOM_LINKER64)
 
 LOCAL_C_INCLUDES       := $(NNSTREAMER_INCLUDES)
index c610668..d4e12c8 100644 (file)
@@ -106,6 +106,7 @@ LOCAL_CFLAGS += -DNO_AUDIO
 LOCAL_CXXFLAGS += -DNO_AUDIO
 endif
 
+LOCAL_LDLIBS        := -llog
 LOCAL_LDFLAGS       += -fuse-ld=bfd
 LOCAL_MODULE_TAGS   := optional
 
index a3cacfc..ef38273 100644 (file)
@@ -12,7 +12,7 @@
 #include <gst/gst.h>
 #include <tensor_common.h>
 
-#define print_log(...) if (!silent) g_message (__VA_ARGS__)
+#define _print_log(...) if (!silent) g_message (__VA_ARGS__)
 #define make_gst_element(element) do{\
   element = gst_element_factory_make(#element, #element);\
   if (!element) {\
@@ -40,7 +40,7 @@ static gint return_val = 0;
 static gboolean
 bus_callback (GstBus * bus, GstMessage * message, gpointer data)
 {
-  print_log ("Got %s message\n", GST_MESSAGE_TYPE_NAME (message));
+  _print_log ("Got %s message\n", GST_MESSAGE_TYPE_NAME (message));
 
   switch (GST_MESSAGE_TYPE (message)) {
     case GST_MESSAGE_ERROR:{
@@ -48,7 +48,7 @@ bus_callback (GstBus * bus, GstMessage * message, gpointer data)
       gchar *debug;
 
       gst_message_parse_error (message, &err, &debug);
-      print_log ("Error: %s\n", err->message);
+      _print_log ("Error: %s\n", err->message);
       g_error_free (err);
       g_free (debug);
 
@@ -142,7 +142,7 @@ reload_model (GstElement *tensor_filter)
 
   g_object_set (G_OBJECT (tensor_filter), "model", model_path, NULL);
 
-  print_log ("Model %s is just reloaded\n", model_path);
+  _print_log ("Model %s is just reloaded\n", model_path);
 
   is_first = !is_first;
 
@@ -161,7 +161,7 @@ stop_loop (GMainLoop *loop)
 
   g_main_loop_quit (loop);
 
-  print_log ("Now stop the loop\n");
+  _print_log ("Now stop the loop\n");
 
   /* stop */
   return FALSE;