[Log] rename log util
authorJaeyun Jung <jy1210.jung@samsung.com>
Wed, 13 Dec 2023 11:39:15 +0000 (20:39 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Thu, 14 Dec 2023 06:41:05 +0000 (15:41 +0900)
Code clean, rename macro and use predefined log util.

Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
12 files changed:
daemon/gdbus-util.c
daemon/log.h
daemon/main.c
daemon/model-dbus-impl.cc
daemon/modules.c
daemon/pipeline-dbus-impl.cc
daemon/resource-dbus-impl.cc
daemon/service-db.cc
tests/daemon/unittest_gdbus_util.cc
tests/daemon/unittest_ml_agent.cc
tests/daemon/unittest_service_db.cc
tests/dbus/test-dbus-impl.c

index 76095cce0488a13c5c6970dcba2851b42621dfc3..f65dc16fad3ce133b1cf4b2bda7c4506eeabae0e 100644 (file)
@@ -26,7 +26,7 @@ int
 gdbus_export_interface (gpointer instance, const char *obj_path)
 {
   if (g_dbus_sys_conn == NULL) {
-    _E ("Cannot get the dbus connection to the system message bus");
+    ml_loge ("Cannot get the dbus connection to the system message bus");
     return -ENOSYS;
   }
 
@@ -125,7 +125,7 @@ gdbus_get_system_connection (gboolean is_session)
 
   g_dbus_sys_conn = g_bus_get_sync (bus_type, NULL, &err);
   if (g_dbus_sys_conn == NULL) {
-    _E ("Cannot connect to the system message bus: %s", err ? err->message : "Unknown error");
+    ml_loge ("Cannot connect to the system message bus: %s", err ? err->message : "Unknown error");
     g_clear_error (&err);
     return -ENOSYS;
   }
@@ -151,7 +151,7 @@ gdbus_initialize (void)
   GError *err = NULL;
 
   if (!gst_init_check (NULL, NULL, &err))
-    _E ("Failed to initialize GStreamer: %s", (err ? err->message : "Unknown error"));
+    ml_loge ("Failed to initialize GStreamer: %s", (err ? err->message : "Unknown error"));
 
   g_clear_error (&err);
 }
index e933bc6b7546537492a18a85d85bae7369b27e51..2afe4bf2646a46b6da41d30d567476ac51fee9ec 100644 (file)
     dlog_print(prio, tag, "%s: %s(%d) > " fmt, __MODULE__, __func__, __LINE__, ##arg);\
   } while (0); })
 
-#define _D(fmt, arg...)                LOG_V(DLOG_DEBUG, AGENT_LOG_TAG, fmt, ##arg)
-#define _I(fmt, arg...)                LOG_V(DLOG_INFO, AGENT_LOG_TAG, fmt, ##arg)
-#define _W(fmt, arg...)                LOG_V(DLOG_WARN, AGENT_LOG_TAG, fmt, ##arg)
-#define _E(fmt, arg...)                LOG_V(DLOG_ERROR, AGENT_LOG_TAG, fmt, ##arg)
-#define _F(fmt, arg...)                LOG_V(DLOG_FATAL, AGENT_LOG_TAG, fmt, ##arg)
+#define ml_logd(fmt, arg...) LOG_V(DLOG_DEBUG, AGENT_LOG_TAG, fmt, ##arg)
+#define ml_logi(fmt, arg...) LOG_V(DLOG_INFO, AGENT_LOG_TAG, fmt, ##arg)
+#define ml_logw(fmt, arg...) LOG_V(DLOG_WARN, AGENT_LOG_TAG, fmt, ##arg)
+#define ml_loge(fmt, arg...) LOG_V(DLOG_ERROR, AGENT_LOG_TAG, fmt, ##arg)
+#define ml_logf(fmt, arg...) LOG_V(DLOG_FATAL, AGENT_LOG_TAG, fmt, ##arg)
 #else
 #include <glib.h>
 
-#define _D g_debug
-#define _I g_info
-#define _W g_warning
-#define _E g_critical
-#define _F g_error
+#define ml_logd g_debug
+#define ml_logi g_info
+#define ml_logw g_warning
+#define ml_loge g_critical
+#define ml_logf g_error
 #endif
 
 #endif /* __LOG_H__ */
index fd4498261c71a8751dfd441bc3b87306266e0e40..1a70e53aab0ea7fd189e05674985f5da97c4e3f7 100644 (file)
@@ -33,7 +33,7 @@ static gboolean is_session = FALSE;
 static void
 handle_sigterm (int signo)
 {
-  _D ("received SIGTERM signal %d", signo);
+  ml_logd ("received SIGTERM signal %d", signo);
   g_main_loop_quit (g_mainloop);
 }
 
@@ -45,6 +45,7 @@ static int
 postinit (void)
 {
   int ret;
+
   /** Register signal handler */
   signal (SIGTERM, handle_sigterm);
 
@@ -62,7 +63,7 @@ postinit (void)
 static int
 parse_args (gint *argc, gchar ***argv)
 {
-  GError *err;
+  GError *err = NULL;
   GOptionContext *context = NULL;
   gboolean ret;
 
@@ -74,7 +75,7 @@ parse_args (gint *argc, gchar ***argv)
 
   context = g_option_context_new (NULL);
   if (!context) {
-    _E ("Failed to call g_option_context_new\n");
+    ml_loge ("Failed to call g_option_context_new\n");
     return -ENOMEM;
   }
 
@@ -82,11 +83,10 @@ parse_args (gint *argc, gchar ***argv)
   g_option_context_set_help_enabled (context, TRUE);
   g_option_context_set_ignore_unknown_options (context, TRUE);
 
-  err = NULL;
   ret = g_option_context_parse (context, argc, argv, &err);
   g_option_context_free (context);
   if (!ret) {
-    _E ("Fail to option parsing: %s", err->message);
+    ml_loge ("Fail to option parsing: %s", err->message);
     g_clear_error (&err);
     return -EINVAL;
   }
@@ -109,11 +109,11 @@ main (int argc, char **argv)
 
   init_modules (NULL);
   if (postinit () < 0)
-    _E ("cannot init system");
+    ml_loge ("cannot init system");
 
   /* Register package manager callback */
   if (pkg_mgr_init () < 0) {
-    _E ("cannot init package manager");
+    ml_loge ("cannot init package manager");
   }
 
   g_main_loop_run (g_mainloop);
@@ -124,7 +124,7 @@ main (int argc, char **argv)
   g_mainloop = NULL;
 
   if (pkg_mgr_deinit () < 0)
-    _W ("cannot finalize package manager");
+    ml_logw ("cannot finalize package manager");
 
   return 0;
 }
index 0fbfded15462df2f7fda45a1071d1393e310f747..904eaa4c48eb27a1074bdc7996204f2fc8984efd 100644 (file)
@@ -65,10 +65,10 @@ gdbus_cb_model_register (MachinelearningServiceModel *obj,
     db.connectDB ();
     db.set_model (name, path, is_active, description, app_info, &version);
   } catch (const std::invalid_argument &e) {
-    _E ("%s", e.what ());
+    ml_loge ("%s", e.what ());
     ret = -EINVAL;
   } catch (const std::exception &e) {
-    _E ("%s", e.what ());
+    ml_loge ("%s", e.what ());
     ret = -EIO;
   }
 
@@ -100,10 +100,10 @@ gdbus_cb_model_update_description (MachinelearningServiceModel *obj,
     db.connectDB ();
     db.update_model_description (name, version, description);
   } catch (const std::invalid_argument &e) {
-    _E ("%s", e.what ());
+    ml_loge ("%s", e.what ());
     ret = -EINVAL;
   } catch (const std::exception &e) {
-    _E ("%s", e.what ());
+    ml_loge ("%s", e.what ());
     ret = -EIO;
   }
 
@@ -133,10 +133,10 @@ gdbus_cb_model_activate (MachinelearningServiceModel *obj,
     db.connectDB ();
     db.activate_model (name, version);
   } catch (const std::invalid_argument &e) {
-    _E ("%s", e.what ());
+    ml_loge ("%s", e.what ());
     ret = -EINVAL;
   } catch (const std::exception &e) {
-    _E ("%s", e.what ());
+    ml_loge ("%s", e.what ());
     ret = -EIO;
   }
 
@@ -166,10 +166,10 @@ gdbus_cb_model_get (MachinelearningServiceModel *obj,
     db.connectDB ();
     db.get_model (name, model_info, version);
   } catch (const std::invalid_argument &e) {
-    _E ("%s", e.what ());
+    ml_loge ("%s", e.what ());
     ret = -EINVAL;
   } catch (const std::exception &e) {
-    _E ("%s", e.what ());
+    ml_loge ("%s", e.what ());
     ret = -EIO;
   }
 
@@ -199,10 +199,10 @@ gdbus_cb_model_get_activated (MachinelearningServiceModel *obj,
     db.connectDB ();
     db.get_model (name, model_info, -1);
   } catch (const std::invalid_argument &e) {
-    _E ("%s", e.what ());
+    ml_loge ("%s", e.what ());
     ret = -EINVAL;
   } catch (const std::exception &e) {
-    _E ("%s", e.what ());
+    ml_loge ("%s", e.what ());
     ret = -EIO;
   }
 
@@ -233,10 +233,10 @@ gdbus_cb_model_get_all (MachinelearningServiceModel *obj,
     db.connectDB ();
     db.get_model (name, all_model_list, 0);
   } catch (const std::invalid_argument &e) {
-    _E ("%s", e.what ());
+    ml_loge ("%s", e.what ());
     ret = -EINVAL;
   } catch (const std::exception &e) {
-    _E ("%s", e.what ());
+    ml_loge ("%s", e.what ());
     ret = -EIO;
   }
 
@@ -267,10 +267,10 @@ gdbus_cb_model_delete (MachinelearningServiceModel *obj,
     db.connectDB ();
     db.delete_model (name, version);
   } catch (const std::invalid_argument &e) {
-    _E ("%s", e.what ());
+    ml_loge ("%s", e.what ());
     ret = -EINVAL;
   } catch (const std::exception &e) {
-    _E ("%s", e.what ());
+    ml_loge ("%s", e.what ());
     ret = -EIO;
   }
 
@@ -335,24 +335,25 @@ static int
 probe_model_module (void *data)
 {
   int ret = 0;
-  _D ("probe_model_module");
+
+  ml_logd ("probe_model_module");
 
   g_gdbus_instance = gdbus_get_model_instance ();
   if (NULL == g_gdbus_instance) {
-    _E ("cannot get a dbus instance for the %s interface\n", DBUS_MODEL_INTERFACE);
+    ml_loge ("cannot get a dbus instance for the %s interface\n", DBUS_MODEL_INTERFACE);
     return -ENOSYS;
   }
 
   ret = gdbus_connect_signal (g_gdbus_instance, ARRAY_SIZE (handler_infos), handler_infos);
   if (ret < 0) {
-    _E ("cannot register callbacks as the dbus method invocation handlers\n ret: %d", ret);
+    ml_loge ("cannot register callbacks as the dbus method invocation handlers\n ret: %d", ret);
     ret = -ENOSYS;
     goto out;
   }
 
   ret = gdbus_export_interface (g_gdbus_instance, DBUS_MODEL_PATH);
   if (ret < 0) {
-    _E ("cannot export the dbus interface '%s' at the object path '%s'\n",
+    ml_loge ("cannot export the dbus interface '%s' at the object path '%s'\n",
         DBUS_MODEL_INTERFACE, DBUS_MODEL_PATH);
     ret = -ENOSYS;
     goto out_disconnect;
index 364162e06cce59ae1e9696e090db06be5c59fd0f..eb98d278cc1cd6e34ecad381a8aed0dd0da5768a 100644 (file)
@@ -52,7 +52,7 @@ init_modules (void *data)
     elem_n = elem->next;
 
     if (module->probe && module->probe (data) != 0) {
-      _E ("[%s] probe fail", module->name);
+      ml_loge ("[%s] probe fail", module->name);
       module_head = g_list_remove (module_head, (gconstpointer) module);
       elem = elem_n;
       continue;
index d351293904c781ab4852064a801f52dfc90f2806..d761d277ed15f49f1fc6fc432e7858a29892ce6e 100644 (file)
@@ -53,7 +53,7 @@ _pipeline_free (gpointer data)
   pipeline_s *p;
 
   if (!data) {
-    _E ("internal error, the data should not be NULL");
+    ml_loge ("internal error, the data should not be NULL");
     return;
   }
 
@@ -101,17 +101,17 @@ dbus_cb_core_set_pipeline (MachinelearningServicePipeline *obj, GDBusMethodInvoc
     db.connectDB ();
     db.set_pipeline (service_name, pipeline_desc);
   } catch (const std::invalid_argument &e) {
-    _E ("An exception occurred during write to the DB. Error message: %s", e.what ());
+    ml_loge ("An exception occurred during write to the DB. Error message: %s", e.what ());
     result = -EINVAL;
   } catch (const std::exception &e) {
-    _E ("An exception occurred during write to the DB. Error message: %s", e.what ());
+    ml_loge ("An exception occurred during write to the DB. Error message: %s", e.what ());
     result = -EIO;
   }
 
   db.disconnectDB ();
 
   if (result) {
-    _E ("Failed to set pipeline description of %s", service_name);
+    ml_loge ("Failed to set pipeline description of %s", service_name);
     machinelearning_service_pipeline_complete_set_pipeline (obj, invoc, result);
     return TRUE;
   }
@@ -136,17 +136,17 @@ dbus_cb_core_get_pipeline (MachinelearningServicePipeline *obj,
     db.connectDB ();
     db.get_pipeline (service_name, stored_pipeline_description);
   } catch (const std::invalid_argument &e) {
-    _E ("An exception occurred during read the DB. Error message: %s", e.what ());
+    ml_loge ("An exception occurred during read the DB. Error message: %s", e.what ());
     result = -EINVAL;
   } catch (const std::exception &e) {
-    _E ("An exception occurred during read the DB. Error message: %s", e.what ());
+    ml_loge ("An exception occurred during read the DB. Error message: %s", e.what ());
     result = -EIO;
   }
 
   db.disconnectDB ();
 
   if (result) {
-    _E ("Failed to get pipeline description of %s", service_name);
+    ml_loge ("Failed to get pipeline description of %s", service_name);
   }
 
   machinelearning_service_pipeline_complete_get_pipeline (
@@ -169,11 +169,11 @@ dbus_cb_core_delete_pipeline (MachinelearningServicePipeline *obj,
     db.connectDB ();
     db.delete_pipeline (service_name);
   } catch (const std::invalid_argument &e) {
-    _E ("An exception occurred during delete an item in the DB. Error message: %s",
+    ml_loge ("An exception occurred during delete an item in the DB. Error message: %s",
         e.what ());
     result = -EINVAL;
   } catch (const std::exception &e) {
-    _E ("An exception occurred during delete an item in the DB. Error message: %s",
+    ml_loge ("An exception occurred during delete an item in the DB. Error message: %s",
         e.what ());
     result = -EIO;
   }
@@ -181,7 +181,7 @@ dbus_cb_core_delete_pipeline (MachinelearningServicePipeline *obj,
   db.disconnectDB ();
 
   if (result) {
-    _E ("Failed to delete the pipeline description of %s", service_name);
+    ml_loge ("Failed to delete the pipeline description of %s", service_name);
     machinelearning_service_pipeline_complete_delete_pipeline (obj, invoc, result);
     return TRUE;
   }
@@ -212,24 +212,24 @@ dbus_cb_core_launch_pipeline (MachinelearningServicePipeline *obj,
     db.connectDB ();
     db.get_pipeline (service_name, stored_pipeline_description);
   } catch (const std::invalid_argument &e) {
-    _E ("An exception occurred during read the DB. Error message: %s", e.what ());
+    ml_loge ("An exception occurred during read the DB. Error message: %s", e.what ());
     result = -EINVAL;
   } catch (const std::exception &e) {
-    _E ("An exception occurred during read the DB. Error message: %s", e.what ());
+    ml_loge ("An exception occurred during read the DB. Error message: %s", e.what ());
     result = -EIO;
   }
 
   db.disconnectDB ();
 
   if (result) {
-    _E ("Failed to launch pipeline of %s", service_name);
+    ml_loge ("Failed to launch pipeline of %s", service_name);
     machinelearning_service_pipeline_complete_launch_pipeline (obj, invoc, result, -1);
     return TRUE;
   }
 
   pipeline = gst_parse_launch (stored_pipeline_description.c_str (), &err);
   if (!pipeline || err) {
-    _E ("gst_parse_launch with %s Failed. error msg: %s",
+    ml_loge ("gst_parse_launch with %s Failed. error msg: %s",
         stored_pipeline_description.c_str (), (err) ? err->message : "unknown reason");
     g_clear_error (&err);
 
@@ -244,7 +244,7 @@ dbus_cb_core_launch_pipeline (MachinelearningServicePipeline *obj,
   /** now set pipeline as paused state */
   sc_ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
   if (sc_ret == GST_STATE_CHANGE_FAILURE) {
-    _E ("Failed to set the state of the pipeline to PAUSED. For the detail, please check the GStreamer log message. The input pipeline was %s",
+    ml_loge ("Failed to set the state of the pipeline to PAUSED. For the detail, please check the GStreamer log message. The input pipeline was %s",
         stored_pipeline_description.c_str ());
 
     gst_object_unref (pipeline);
@@ -285,7 +285,7 @@ dbus_cb_core_start_pipeline (MachinelearningServicePipeline *obj,
   p = (pipeline_s *) g_hash_table_lookup (pipeline_table, GINT_TO_POINTER (id));
 
   if (!p) {
-    _E ("The callback start_pipeline is called, but there is no pipeline matched with ID.");
+    ml_loge ("The callback start_pipeline is called, but there is no pipeline matched with ID.");
     G_UNLOCK (pipeline_table_lock);
     result = -EINVAL;
   } else {
@@ -295,7 +295,7 @@ dbus_cb_core_start_pipeline (MachinelearningServicePipeline *obj,
     g_mutex_unlock (&p->lock);
 
     if (sc_ret == GST_STATE_CHANGE_FAILURE) {
-      _E ("Failed to set the state of the pipline to PLAYING whose service name is %s.",
+      ml_loge ("Failed to set the state of the pipline to PLAYING whose service name is %s.",
           p->service_name);
       result = -ESTRPIPE;
     }
@@ -321,7 +321,7 @@ dbus_cb_core_stop_pipeline (MachinelearningServicePipeline *obj,
   p = (pipeline_s *) g_hash_table_lookup (pipeline_table, GINT_TO_POINTER (id));
 
   if (!p) {
-    _E ("The callback stop_pipeline is called, but there is no pipeline matched with ID.");
+    ml_loge ("The callback stop_pipeline is called, but there is no pipeline matched with ID.");
     G_UNLOCK (pipeline_table_lock);
     result = -EINVAL;
   } else {
@@ -331,7 +331,7 @@ dbus_cb_core_stop_pipeline (MachinelearningServicePipeline *obj,
     g_mutex_unlock (&p->lock);
 
     if (sc_ret == GST_STATE_CHANGE_FAILURE) {
-      _E ("Failed to set the state of the pipline to PAUSED whose service name is %s.",
+      ml_loge ("Failed to set the state of the pipline to PAUSED whose service name is %s.",
           p->service_name);
       result = -ESTRPIPE;
     }
@@ -356,7 +356,7 @@ dbus_cb_core_destroy_pipeline (MachinelearningServicePipeline *obj,
   p = (pipeline_s *) g_hash_table_lookup (pipeline_table, GINT_TO_POINTER (id));
 
   if (!p) {
-    _E ("The callback destroy_pipeline is called, but there is no pipeline matched with ID.");
+    ml_loge ("The callback destroy_pipeline is called, but there is no pipeline matched with ID.");
     result = -EINVAL;
   } else {
     /**
@@ -370,7 +370,7 @@ dbus_cb_core_destroy_pipeline (MachinelearningServicePipeline *obj,
      *   sc_ret = gst_element_set_state (p->element, GST_STATE_NULL);
      *   g_mutex_unlock (&p->lock);
      *   if (sc_ret == GST_STATE_CHANGE_FAILURE) {
-     *     _E ("Failed to set the state of the pipeline to NULL whose service name is %s. Destroy it anyway.", p->service_name);
+     *     ml_loge ("Failed to set the state of the pipeline to NULL whose service name is %s. Destroy it anyway.", p->service_name);
      *     result = -ESTRPIPE;
      *   }
      */
@@ -399,7 +399,7 @@ dbus_cb_core_get_state (MachinelearningServicePipeline *obj,
   p = (pipeline_s *) g_hash_table_lookup (pipeline_table, GINT_TO_POINTER (id));
 
   if (!p) {
-    _E ("The callback get_state is called, but there is no pipeline matched with ID.");
+    ml_loge ("The callback get_state is called, but there is no pipeline matched with ID.");
     result = -EINVAL;
     machinelearning_service_pipeline_complete_get_state (obj, invoc, result, (gint) state);
     G_UNLOCK (pipeline_table_lock);
@@ -412,7 +412,7 @@ dbus_cb_core_get_state (MachinelearningServicePipeline *obj,
   g_mutex_unlock (&p->lock);
 
   if (sc_ret == GST_STATE_CHANGE_FAILURE) {
-    _E ("Failed to get the state of the pipline whose service name is %s.", p->service_name);
+    ml_loge ("Failed to get the state of the pipline whose service name is %s.", p->service_name);
     result = -ESTRPIPE;
     machinelearning_service_pipeline_complete_get_state (obj, invoc, result, (gint) state);
     return TRUE;
@@ -484,20 +484,20 @@ probe_pipeline_module (void *data)
 
   g_gdbus_instance = gdbus_get_pipeline_instance ();
   if (g_gdbus_instance == NULL) {
-    _E ("cannot get a dbus instance for the %s interface\n", DBUS_PIPELINE_INTERFACE);
+    ml_loge ("cannot get a dbus instance for the %s interface\n", DBUS_PIPELINE_INTERFACE);
     return -ENOSYS;
   }
 
   ret = gdbus_connect_signal (g_gdbus_instance, ARRAY_SIZE (handler_infos), handler_infos);
   if (ret < 0) {
-    _E ("cannot register callbacks as the dbus method invocation handlers\n ret: %d", ret);
+    ml_loge ("cannot register callbacks as the dbus method invocation handlers\n ret: %d", ret);
     ret = -ENOSYS;
     goto out;
   }
 
   ret = gdbus_export_interface (g_gdbus_instance, DBUS_PIPELINE_PATH);
   if (ret < 0) {
-    _E ("cannot export the dbus interface '%s' at the object path '%s'\n",
+    ml_loge ("cannot export the dbus interface '%s' at the object path '%s'\n",
         DBUS_PIPELINE_INTERFACE, DBUS_PIPELINE_PATH);
     ret = -ENOSYS;
     goto out_disconnect;
index 04d9b073a8fffc7f3e6e47eee24db99ec1c0de41..6105ef2126045741ec585745ce8da870500a3872 100644 (file)
@@ -61,10 +61,10 @@ gdbus_cb_resource_add (MachinelearningServiceResource *obj, GDBusMethodInvocatio
     db.connectDB ();
     db.set_resource (name, path, description, app_info);
   } catch (const std::invalid_argument &e) {
-    _E ("%s", e.what ());
+    ml_loge ("%s", e.what ());
     ret = -EINVAL;
   } catch (const std::exception &e) {
-    _E ("%s", e.what ());
+    ml_loge ("%s", e.what ());
     ret = -EIO;
   }
 
@@ -93,10 +93,10 @@ gdbus_cb_resource_get (MachinelearningServiceResource *obj,
     db.connectDB ();
     db.get_resource (name, res_info);
   } catch (const std::invalid_argument &e) {
-    _E ("%s", e.what ());
+    ml_loge ("%s", e.what ());
     ret = -EINVAL;
   } catch (const std::exception &e) {
-    _E ("%s", e.what ());
+    ml_loge ("%s", e.what ());
     ret = -EIO;
   }
 
@@ -124,10 +124,10 @@ gdbus_cb_resource_delete (MachinelearningServiceResource *obj,
     db.connectDB ();
     db.delete_resource (name);
   } catch (const std::invalid_argument &e) {
-    _E ("%s", e.what ());
+    ml_loge ("%s", e.what ());
     ret = -EINVAL;
   } catch (const std::exception &e) {
-    _E ("%s", e.what ());
+    ml_loge ("%s", e.what ());
     ret = -EIO;
   }
 
@@ -168,25 +168,26 @@ static int
 probe_resource_module (void *data)
 {
   int ret = 0;
-  _D ("probe_resource_module");
+
+  ml_logd("probe_resource_module");
 
   g_gdbus_res_instance = gdbus_get_resource_instance ();
   if (NULL == g_gdbus_res_instance) {
-    _E ("cannot get a dbus instance for the %s interface\n", DBUS_RESOURCE_INTERFACE);
+    ml_loge ("cannot get a dbus instance for the %s interface\n", DBUS_RESOURCE_INTERFACE);
     return -ENOSYS;
   }
 
   ret = gdbus_connect_signal (
       g_gdbus_res_instance, ARRAY_SIZE (res_handler_infos), res_handler_infos);
   if (ret < 0) {
-    _E ("cannot register callbacks as the dbus method invocation handlers\n ret: %d", ret);
+    ml_loge ("cannot register callbacks as the dbus method invocation handlers\n ret: %d", ret);
     ret = -ENOSYS;
     goto out;
   }
 
   ret = gdbus_export_interface (g_gdbus_res_instance, DBUS_RESOURCE_PATH);
   if (ret < 0) {
-    _E ("cannot export the dbus interface '%s' at the object path '%s'\n",
+    ml_loge ("cannot export the dbus interface '%s' at the object path '%s'\n",
         DBUS_RESOURCE_INTERFACE, DBUS_RESOURCE_PATH);
     ret = -ENOSYS;
     goto out_disconnect;
index ebe849d461b90867b290192f989e2adc58f60dcf..53038c5b5ecb41c36184990ece616955a4e2d35e 100644 (file)
@@ -167,7 +167,7 @@ MLServiceDB::connectDB ()
 
   rc = sqlite3_open (_path.c_str (), &_db);
   if (rc != SQLITE_OK) {
-    _E ("Failed to open database: %s (%d)", sqlite3_errmsg (_db), rc);
+    ml_loge ("Failed to open database: %s (%d)", sqlite3_errmsg (_db), rc);
     goto error;
   }
 
@@ -204,7 +204,7 @@ MLServiceDB::get_table_version (const std::string tbl_name, const int default_ve
 
   rc = sqlite3_prepare_v2 (_db, sql.c_str (), -1, &res, nullptr);
   if (rc != SQLITE_OK) {
-    _W ("Failed to get the version of table %s: %s (%d)", tbl_name.c_str (),
+    ml_logw ("Failed to get the version of table %s: %s (%d)", tbl_name.c_str (),
         sqlite3_errmsg (_db), rc);
     return -1;
   }
@@ -232,7 +232,7 @@ MLServiceDB::set_table_version (const std::string tbl_name, const int tbl_ver)
   sqlite3_finalize (res);
 
   if (!is_done)
-    _W ("Failed to update version of table %s.", tbl_name.c_str ());
+    ml_logw ("Failed to update version of table %s.", tbl_name.c_str ());
   return is_done;
 }
 
@@ -248,7 +248,7 @@ MLServiceDB::create_table (const std::string tbl_name)
 
   rc = sqlite3_exec (_db, sql.c_str (), nullptr, nullptr, &errmsg);
   if (rc != SQLITE_OK) {
-    _W ("Failed to create table %s: %s (%d)", tbl_name.c_str (), errmsg, rc);
+    ml_logw ("Failed to create table %s: %s (%d)", tbl_name.c_str (), errmsg, rc);
     sqlite3_clear_errmsg (errmsg);
     return false;
   }
@@ -268,7 +268,7 @@ MLServiceDB::set_transaction (bool begin)
   rc = sqlite3_exec (_db, begin ? "BEGIN TRANSACTION;" : "END TRANSACTION;",
       nullptr, nullptr, &errmsg);
   if (rc != SQLITE_OK)
-    _W ("Failed to %s transaction: %s (%d)", begin ? "begin" : "end", errmsg, rc);
+    ml_logw ("Failed to %s transaction: %s (%d)", begin ? "begin" : "end", errmsg, rc);
 
   sqlite3_clear_errmsg (errmsg);
   return (rc == SQLITE_OK);
@@ -500,7 +500,7 @@ MLServiceDB::set_model (const std::string name, const std::string model, const b
 
   long long int last_id = sqlite3_last_insert_rowid (_db);
   if (last_id == 0) {
-    _E ("Failed to get last inserted row id: %s", sqlite3_errmsg (_db));
+    ml_loge ("Failed to get last inserted row id: %s", sqlite3_errmsg (_db));
     throw std::runtime_error ("Failed to get last inserted row id.");
   }
 
@@ -518,7 +518,7 @@ MLServiceDB::set_model (const std::string name, const std::string model, const b
     throw std::runtime_error ("Failed to end transaction.");
 
   if (_version == 0) {
-    _E ("Failed to get model version with name %s: %s", name.c_str (),
+    ml_loge ("Failed to get model version with name %s: %s", name.c_str (),
         sqlite3_errmsg (_db));
     throw std::invalid_argument ("Failed to get model version of " + name);
   }
@@ -776,7 +776,7 @@ MLServiceDB::set_resource (const std::string name, const std::string path,
 
   long long int last_id = sqlite3_last_insert_rowid (_db);
   if (last_id == 0) {
-    _E ("Failed to get last inserted row id: %s", sqlite3_errmsg (_db));
+    ml_loge ("Failed to get last inserted row id: %s", sqlite3_errmsg (_db));
     throw std::runtime_error ("Failed to get last inserted row id.");
   }
 }
index 5a96b65d807a40909a0567e85f6f822566bcd99e..35e4b75ec252d10d85b10ae8f0ccc08fafebd537 100755 (executable)
@@ -12,6 +12,7 @@
 #include "../dbus/test-dbus-interface.h"
 #include "dbus-interface.h"
 #include "gdbus-util.h"
+#include "log.h"
 #include "test-dbus.h"
 
 /**
@@ -72,7 +73,7 @@ TEST_F (GDbusTest, call_method)
   /* Test: Call the DBus method */
   machinelearning_service_test_call_get_state_sync (proxy, &status, &result, NULL, &error);
   if (error != NULL) {
-    g_critical ("Error : %s", error->message);
+    ml_loge ("Error : %s", error->message);
     g_error_free (error);
     FAIL ();
   }
@@ -126,13 +127,13 @@ main (int argc, char **argv)
   try {
     testing::InitGoogleTest (&argc, argv);
   } catch (...) {
-    g_warning ("catch 'testing::internal::<unnamed>::ClassUniqueToAlwaysTrue'");
+    ml_logw ("catch 'testing::internal::<unnamed>::ClassUniqueToAlwaysTrue'");
   }
 
   try {
     result = RUN_ALL_TESTS ();
   } catch (...) {
-    g_warning ("catch `testing::internal::GoogleTestFailureException`");
+    ml_logw ("catch `testing::internal::GoogleTestFailureException`");
   }
 
   return result;
index 1a46edb0f37f7fdc62521763134390beaeaed018..52806866c5024d004eaca7ee0ba4739d87ad17be 100644 (file)
@@ -10,6 +10,7 @@
 #include <gtest/gtest.h>
 #include <gio/gio.h>
 
+#include "log.h"
 #include "ml-agent-interface.h"
 
 /**
@@ -591,13 +592,13 @@ main (int argc, char **argv)
   try {
     testing::InitGoogleTest (&argc, argv);
   } catch (...) {
-    g_warning ("catch 'testing::internal::<unnamed>::ClassUniqueToAlwaysTrue'");
+    ml_logw ("catch 'testing::internal::<unnamed>::ClassUniqueToAlwaysTrue'");
   }
 
   try {
     result = RUN_ALL_TESTS ();
   } catch (...) {
-    g_warning ("catch `testing::internal::GoogleTestFailureException`");
+    ml_logw ("catch `testing::internal::GoogleTestFailureException`");
   }
 
   return result;
index e6761bb41cd044c78d6e5524acc217e1bd93bb89..fde5f880c6f6f01162d1a2c2cfe99627e0ddda73 100755 (executable)
@@ -10,6 +10,7 @@
 #include <gtest/gtest.h>
 #include <gio/gio.h>
 
+#include "log.h"
 #include "service-db.hh"
 
 /**
@@ -24,7 +25,7 @@ TEST (serviceDB, set_pipeline_n)
   try {
     db.set_pipeline ("", "videotestsrc ! fakesink");
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -33,7 +34,7 @@ TEST (serviceDB, set_pipeline_n)
   try {
     db.set_pipeline ("test_key", "");
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -53,7 +54,7 @@ TEST (serviceDB, get_pipeline_n)
     std::string pipeline_description;
     db.get_pipeline ("", pipeline_description);
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -72,7 +73,7 @@ TEST (serviceDB, delete_pipeline_n)
   try {
     db.delete_pipeline ("");
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -92,7 +93,7 @@ TEST (serviceDB, set_model_n)
   try {
     db.set_model ("", "model", true, "description", "", &version);
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -101,7 +102,7 @@ TEST (serviceDB, set_model_n)
   try {
     db.set_model ("test", "", true, "description", "", &version);
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -110,7 +111,7 @@ TEST (serviceDB, set_model_n)
   try {
     db.set_model ("test", "model", true, "", "", NULL);
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -169,7 +170,7 @@ TEST (serviceDB, update_model_scenario)
 
     db.delete_model ("test", 0);
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 0);
@@ -190,7 +191,7 @@ TEST (serviceDB, get_model_n)
     std::string model_description;
     db.get_model ("", model_description, 0);
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -200,7 +201,7 @@ TEST (serviceDB, get_model_n)
     std::string model_description;
     db.get_model ("test", model_description, -54321);
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -219,7 +220,7 @@ TEST (serviceDB, update_model_description_n)
   try {
     db.update_model_description ("", 1, "description");
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -228,7 +229,7 @@ TEST (serviceDB, update_model_description_n)
   try {
     db.update_model_description ("test", 1, "");
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -237,7 +238,7 @@ TEST (serviceDB, update_model_description_n)
   try {
     db.update_model_description ("test", 0, "description");
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -256,7 +257,7 @@ TEST (serviceDB, activate_model_n)
   try {
     db.activate_model ("", 1);
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -265,7 +266,7 @@ TEST (serviceDB, activate_model_n)
   try {
     db.activate_model ("test", 0);
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -284,7 +285,7 @@ TEST (serviceDB, delete_model_n)
   try {
     db.delete_model ("", 0);
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -309,7 +310,7 @@ TEST (serviceDB, delete_model_unregistered_n)
   try {
     db.delete_model ("test", version);
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -334,7 +335,7 @@ TEST (serviceDB, delete_model_activated_n)
   try {
     db.delete_model ("test", version);
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -354,7 +355,7 @@ TEST (serviceDBNotInitalized, set_pipeline_n)
   try {
     db.set_pipeline ("test", "videotestsrc ! fakesink");
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -372,7 +373,7 @@ TEST (serviceDBNotInitalized, get_pipeline_n)
     std::string pd;
     db.get_pipeline ("test", pd);
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -389,7 +390,7 @@ TEST (serviceDBNotInitalized, delete_pipeline_n)
   try {
     db.delete_pipeline ("test");
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -407,7 +408,7 @@ TEST (serviceDBNotInitalized, set_model_n)
     guint version;
     db.set_model ("test", "model", true, "description", "", &version);
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -424,7 +425,7 @@ TEST (serviceDBNotInitalized, update_model_description_n)
   try {
     db.update_model_description ("test", 0, "description");
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -441,7 +442,7 @@ TEST (serviceDBNotInitalized, activate_model_n)
   try {
     db.activate_model ("test", 0);
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -459,7 +460,7 @@ TEST (serviceDBNotInitalized, get_model_n)
     std::string model_path;
     db.get_model ("test", model_path, 0);
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -476,7 +477,7 @@ TEST (serviceDBNotInitalized, delete_model_n)
   try {
     db.delete_model ("test", 0U);
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -495,7 +496,7 @@ TEST (serviceDB, set_resource_n)
   try {
     db.set_resource ("", "resource", "description", "");
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -504,7 +505,7 @@ TEST (serviceDB, set_resource_n)
   try {
     db.set_resource ("test", "", "description", "");
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -548,7 +549,7 @@ TEST (serviceDB, update_resource_scenario)
 
     db.delete_resource ("test");
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 0);
@@ -570,7 +571,7 @@ TEST (serviceDB, get_resource_n)
     std::string res_description;
     db.get_resource ("", res_description);
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -597,7 +598,7 @@ TEST (serviceDB, get_resource_unregistered_n)
     std::string res_description;
     db.get_resource ("test", res_description);
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -618,7 +619,7 @@ TEST (serviceDB, delete_resource_n)
   try {
     db.delete_resource ("");
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -643,7 +644,7 @@ TEST (serviceDB, delete_resource_unregistered_n)
   try {
     db.delete_resource ("test");
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -662,7 +663,7 @@ TEST (serviceDBNotInitalized, set_resource_n)
   try {
     db.set_resource ("test", "resource", "description", "");
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -680,7 +681,7 @@ TEST (serviceDBNotInitalized, get_resource_n)
     std::string res_description;
     db.get_resource ("test", res_description);
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -697,7 +698,7 @@ TEST (serviceDBNotInitalized, delete_resource_n)
   try {
     db.delete_resource ("test");
   } catch (const std::exception &e) {
-    g_critical ("Got Exception: %s", e.what ());
+    ml_loge ("Got Exception: %s", e.what ());
     gotException = 1;
   }
   EXPECT_EQ (gotException, 1);
@@ -714,13 +715,13 @@ main (int argc, char **argv)
   try {
     testing::InitGoogleTest (&argc, argv);
   } catch (...) {
-    g_warning ("catch 'testing::internal::<unnamed>::ClassUniqueToAlwaysTrue'");
+    ml_logw ("catch 'testing::internal::<unnamed>::ClassUniqueToAlwaysTrue'");
   }
 
   try {
     result = RUN_ALL_TESTS ();
   } catch (...) {
-    g_warning ("catch `testing::internal::GoogleTestFailureException`");
+    ml_logw ("catch `testing::internal::GoogleTestFailureException`");
   }
 
   return result;
index 9a0367e6ee21cfc74ed8d3b3a9b61af370bdd22a..0a4bedcf9776735ebf8672e339a6017258eb1b4d 100755 (executable)
@@ -72,7 +72,7 @@ gdbus_put_instance_test (MachinelearningServiceTest ** instance)
 static void
 init_test (void *data)
 {
-  g_debug ("init_test module");
+  ml_logd ("init_test module");
 
   gdbus_initialize ();
 }
@@ -95,10 +95,12 @@ static int
 probe_test (void *data)
 {
   int ret = 0;
-  g_debug ("probe_test");
+
+  ml_logd ("probe_test");
+
   g_gdbus_instance = gdbus_get_instance_test ();
   if (g_gdbus_instance == NULL) {
-    g_critical ("Cannot get the dbus instance for the %s interface.",
+    ml_loge ("Cannot get the dbus instance for the %s interface.",
         DBUS_TEST_INTERFACE);
     return -ENOSYS;
   }
@@ -106,7 +108,7 @@ probe_test (void *data)
   ret = gdbus_connect_signal (g_gdbus_instance,
       ARRAY_SIZE (g_gdbus_signal_infos), g_gdbus_signal_infos);
   if (ret < 0) {
-    g_critical ("Cannot register callbacks as the dbus method invocation handlers (ret: %d).",
+    ml_loge ("Cannot register callbacks as the dbus method invocation handlers (ret: %d).",
         ret);
     ret = -ENOSYS;
     goto out;
@@ -114,7 +116,7 @@ probe_test (void *data)
 
   ret = gdbus_export_interface (g_gdbus_instance, DBUS_TEST_PATH);
   if (ret < 0) {
-    g_critical ("Cannot export the dbus interface '%s' at the object path '%s'.",
+    ml_loge ("Cannot export the dbus interface '%s' at the object path '%s'.",
         DBUS_TEST_INTERFACE, DBUS_TEST_PATH);
     ret = -ENOSYS;
     goto out_disconnect;