e_log: support E_LOG_FILE_PATH to record enlightenment logs to a file from booting 00/97000/3 accepted/tizen/3.0/common/20161116.143351 accepted/tizen/3.0/ivi/20161116.021610 accepted/tizen/3.0/mobile/20161116.021448 accepted/tizen/3.0/tv/20161116.021516 accepted/tizen/3.0/wearable/20161116.021545 accepted/tizen/common/20161116.134314 accepted/tizen/ivi/20161115.233832 accepted/tizen/mobile/20161115.233702 accepted/tizen/tv/20161115.233746 accepted/tizen/wearable/20161115.233803 submit/tizen/20161115.022149 submit/tizen_3.0/20161115.021406
authorBoram Park <boram1288.park@samsung.com>
Mon, 7 Nov 2016 07:58:18 +0000 (16:58 +0900)
committerGwanglim Lee <gl77.lee@samsung.com>
Tue, 15 Nov 2016 02:14:49 +0000 (18:14 -0800)
Sometimes we want to see the enlightenment's log from booting. It's useful becuase
dlog doesn't have all logs. If E_LOG_FILE_PATH is set, enlightenment prints logs
not via dlog but via the file indicated by E_LOG_FILE_PATH.

Change-Id: I79a811b5809d4a06b3b1d8b7c2eb49af8c2ff933

src/bin/e_info_server.c
src/bin/e_log.c
src/bin/e_log.h

index 2db5c78a47ac4c86d98ea0bc9bce72ec0a28962c..a6dad3152cd68c8327c9d0aac51e41c67d833582 100644 (file)
@@ -899,9 +899,6 @@ _e_info_server_cb_eina_log_path(const Eldbus_Service_Interface *iface EINA_UNUSE
 {
    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
    const char *path = NULL;
-   static int old_stderr = -1;
-   int  log_fd = -1;
-   FILE *log_fl;
 
    if (!eldbus_message_arguments_get(msg, "s", &path) || !path)
      {
@@ -909,24 +906,7 @@ _e_info_server_cb_eina_log_path(const Eldbus_Service_Interface *iface EINA_UNUSE
         return reply;
      }
 
-   if (old_stderr == -1)
-     old_stderr = dup(STDOUT_FILENO);
-
-   log_fl = fopen(path, "a");
-   if (!log_fl)
-     {
-        ERR("failed: open file(%s)\n", path);
-        return reply;
-     }
-
-   fflush(stderr);
-   close(STDOUT_FILENO);
-
-   setvbuf(log_fl, NULL, _IOLBF, 512);
-   log_fd = fileno(log_fl);
-
-   dup2(log_fd, STDOUT_FILENO);
-   fclose(log_fl);
+   e_log_path_set(path);
 
    return reply;
 }
index bcbdca8c3231147b3ff3970d3bcccecaa2f6d111..f0a12c2523f22bb407520d9ec43ad9a64a8e04ea 100644 (file)
@@ -102,9 +102,47 @@ e_log_dlog_enable(Eina_Bool enable)
 }
 #endif
 
+EINTERN Eina_Bool
+e_log_path_set(const char *path)
+{
+   int  log_fd = -1;
+   FILE *log_fl;
+
+   if (!path)
+     {
+        ERR("no eina-log-path");
+        return EINA_FALSE;
+     }
+
+   log_fl = fopen(path, "a");
+   if (!log_fl)
+     {
+        ERR("failed: open file(%s)\n", path);
+        return EINA_FALSE;
+     }
+
+   fflush(stdout);
+   close(STDOUT_FILENO);
+
+   fflush(stderr);
+   close(STDERR_FILENO);
+
+   setvbuf(log_fl, NULL, _IOLBF, 512);
+   log_fd = fileno(log_fl);
+
+   dup2(log_fd, STDOUT_FILENO);
+   dup2(log_fd, STDERR_FILENO);
+
+   fclose(log_fl);
+
+   return EINA_TRUE;
+}
+
 EINTERN int
 e_log_init(void)
 {
+   const char *s;
+
    e_log_dom = eina_log_domain_register("e", EINA_COLOR_WHITE);
    eina_log_print_cb_set(_e_log_cb, NULL);
    eina_log_domain_level_set("e", 3);
@@ -114,6 +152,15 @@ e_log_init(void)
      e_log_dlog_enable(EINA_TRUE);
 #endif
 
+   s = getenv("E_LOG_FILE_PATH");
+   if (s)
+     {
+#ifdef HAVE_DLOG
+        e_log_dlog_enable(EINA_FALSE);
+#endif
+        e_log_path_set(s);
+     }
+
    return 1;
 }
 
index 70145936fcc5f63729284f5436ad1ffcc7411527..00d87b8987f1577ff8f545d7df04f9384bafde63 100644 (file)
@@ -112,6 +112,7 @@ extern E_API int e_log_dom;
 #ifdef HAVE_DLOG
 EINTERN void e_log_dlog_enable(Eina_Bool enable);
 #endif
+EINTERN Eina_Bool e_log_path_set(const char *path);
 
 EINTERN int e_log_init(void);
 EINTERN int e_log_shutdown(void);