Add logs for watch launch/dead events 31/238131/2
authorhyunho <hhstark.kang@samsung.com>
Thu, 9 Jul 2020 00:48:44 +0000 (09:48 +0900)
committerhyunho <hhstark.kang@samsung.com>
Thu, 9 Jul 2020 05:21:50 +0000 (14:21 +0900)
Change-Id: Ie447a099f4829b8b70babe4fb10c84916a9c65b2
Signed-off-by: hyunho <hhstark.kang@samsung.com>
modules/watch/inc/amd_watch_logger.h [new file with mode: 0644]
modules/watch/src/amd_watch.c
modules/watch/src/amd_watch_logger.c [new file with mode: 0644]

diff --git a/modules/watch/inc/amd_watch_logger.h b/modules/watch/inc/amd_watch_logger.h
new file mode 100644 (file)
index 0000000..6cc30d2
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __AMD_WATCH_LOGGER_H__
+#define __AMD_WATCH_LOGGER_H__
+
+int _watch_logger_init(void);
+
+void _watch_logger_fini(void);
+
+int _watch_logger_print(const char *tag, const char *format, ...);
+
+#endif /* __AMD_WATCH_LOGGER_H__ */
index 77daaa182a3b0ab019b0efdf44027b36491e3462..8d7c85c8ecfa8ef0df5c55441c507a4932e11bf3 100644 (file)
@@ -28,6 +28,7 @@
 #include <amd.h>
 
 #include "amd_watch.h"
+#include "amd_watch_logger.h"
 
 struct watch_info {
        char *appid;
@@ -59,7 +60,9 @@ static void __send_dead_signal(const char *appid, pid_t pid, uid_t uid,
 
        amd_app_com_send("watch.dead", pid, envelope, uid);
        bundle_free(envelope);
-       _D("Send dead signal %s:%d:%u:%d", appid, pid, uid, is_faulted);
+       _I("Send dead signal %s:%d:%u:%d", appid, pid, uid, is_faulted);
+       _watch_logger_print("Send Dead", "appid(%s), pid(%d) "
+                       "uid(%d), is_faulted(%d)", appid, pid, uid, is_faulted);
 }
 
 static void __send_launch_signal(const char *appid, const char *viewer,
@@ -81,7 +84,9 @@ static void __send_launch_signal(const char *appid, const char *viewer,
 
        amd_app_com_send("watch.launch", pid, envelope, uid);
        bundle_free(envelope);
-       _D("Send launch signal %s:%d:%u", appid, pid, uid);
+       _I("Send launch signal %s:%d:%u", appid, pid, uid);
+       _watch_logger_print("Send Launch", "appid(%s), pid(%d) "
+                       "uid(%d)", appid, pid, uid);
 }
 
 static void __destroy_watch_info(gpointer data)
@@ -314,6 +319,7 @@ static int __on_package_update_error(const char *msg, int arg1, int arg2,
 EXPORT int AMD_MOD_INIT(void)
 {
        _D("watch init");
+       _watch_logger_init();
 
        amd_noti_listen(AMD_NOTI_MSG_MAIN_APP_DEAD,
                        __on_app_dead);
@@ -337,4 +343,5 @@ EXPORT void AMD_MOD_FINI(void)
                g_list_free_full(__restart_list, __destroy_watch_info);
        if (__update_list)
                g_list_free_full(__update_list, __destroy_watch_info);
+       _watch_logger_fini();
 }
diff --git a/modules/watch/src/amd_watch_logger.c b/modules/watch/src/amd_watch_logger.c
new file mode 100644 (file)
index 0000000..a65fbaa
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdarg.h>
+#include <amd.h>
+
+#include "amd_watch.h"
+#include "amd_logger.h"
+
+#define LOG_FILE "amd_watch.log"
+#define LOG_PATH LOGGER_PATH "/" LOG_FILE
+
+static amd_logger_h __logger;
+
+int _watch_logger_print(const char *tag, const char *format, ...)
+{
+       char format_buf[LOG_MAX_STRING_SIZE];
+       va_list ap;
+
+       va_start(ap, format);
+       vsnprintf(format_buf, sizeof(format_buf), format, ap);
+       va_end(ap);
+
+       return amd_logger_print(__logger, tag, format_buf);
+}
+
+int _watch_logger_init(void)
+{
+       int ret;
+
+       _D("watch logger init");
+       ret = amd_logger_create(LOG_PATH, &__logger);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+void _watch_logger_fini(void)
+{
+       _D("watch logger fini");
+       amd_logger_destroy(__logger);
+}