support tizen dlog logging system 10/53110/1
authorJongmin Lee <jm015.lee@samsung.com>
Wed, 21 Jan 2015 12:19:47 +0000 (21:19 +0900)
committerJaehwan Kim <jae.hwan.kim@samsung.com>
Wed, 2 Dec 2015 02:10:32 +0000 (11:10 +0900)
Conflicts:
src/lib/eina/eina_log.c

Change-Id: I608f5a494fb8b72ee9b40e06c618cfe601a130ef

configure.ac
src/lib/eina/eina_log.c
src/lib/eina/eina_log.h

index 56d9dd4..a8bbd62 100644 (file)
@@ -888,6 +888,15 @@ EFL_ADD_LIBS([EINA], [-lm])
 
 ## Options
 
+# dlog
+PKG_CHECK_EXISTS([dlog], [have_dlog="yes"], [have_dlog="no"])
+AC_MSG_CHECKING([Use dlog logger])
+AC_MSG_RESULT([${have_dlog}])
+if test "x${have_dlog}" = "xyes"; then
+    AC_DEFINE([HAVE_DLOG], [1], [Define to 1 if you have dlog])
+    EFL_DEPEND_PKG([EINA], [DLOG], [dlog])
+fi
+
 # Valgrind
 AC_ARG_ENABLE([valgrind],
    [AS_HELP_STRING([--disable-valgrind],[enable valgrind mempool declaration. @<:@default=disabled@:>@])],
index 6fc9626..9cce55b 100644 (file)
 #include <assert.h>
 #include <errno.h>
 
+/*--- TIZEN_ONLY : begin ---*/
+#include <syslog.h>
+
+#ifdef HAVE_DLOG
+# include <dlog.h>
+#  ifdef LOG_TAG
+#   undef LOG_TAG
+#  endif
+# define LOG_TAG "EFL"
+# define _SECURE_LOG
+#endif
+/*--- TIZEN_ONLY : end ---*/
+
 #ifdef HAVE_SYSTEMD
 # include <systemd/sd-journal.h>
 #endif
 #define EINA_LOG_ENV_FUNCTION_DISABLE "EINA_LOG_FUNCTION_DISABLE"
 #define EINA_LOG_ENV_BACKTRACE "EINA_LOG_BACKTRACE"
 
+/*--- TIZEN_ONLY : begin ---*/
+#define EINA_LOG_ENV_SYSLOG_ENABLE "EINA_LOG_SYSLOG_ENABLE"
+
+#ifdef HAVE_DLOG
+# define EINA_LOG_ENV_DLOG_ENABLE "EINA_LOG_DLOG_ENABLE"
+#endif
+/*--- TIZEN_ONLY : end ---*/
+
 #ifdef EINA_ENABLE_LOG
 
 // Structure for storing domain level settings passed from the command line
@@ -1367,6 +1388,17 @@ eina_log_init(void)
    if ((tmp = getenv(EINA_LOG_ENV_ABORT_LEVEL)))
       _abort_level_on_critical = atoi(tmp);
 
+   /*--- TIZEN_ONLY : begin ---*/
+   if ((tmp = getenv(EINA_LOG_ENV_SYSLOG_ENABLE)) && (atoi(tmp) == 1))
+      _print_cb = eina_log_print_cb_syslog;
+
+#ifdef HAVE_DLOG
+   /* dlog has more higher priority than syslog */
+   if ((tmp = getenv(EINA_LOG_ENV_DLOG_ENABLE)) && (atoi(tmp) == 1))
+      _print_cb = eina_log_print_cb_dlog;
+#endif
+   /*--- TIZEN_ONLY : end ---*/
+
    eina_log_print_prefix_update();
 
    // Global log level
@@ -2047,6 +2079,162 @@ end:
 #endif
 }
 
+/*--- TIZEN_ONLY : begin ---*/
+EAPI void
+eina_log_print_cb_syslog(const Eina_Log_Domain *d,
+                         Eina_Log_Level level,
+                         const char *file,
+                         const char *fnc,
+                         int line,
+                         const char *fmt,
+                         EINA_UNUSED  void *data,
+                         va_list args)
+{
+#ifdef EINA_ENABLE_LOG
+   int priority;
+   const char buf[512];
+
+   switch (level)
+     {
+      case EINA_LOG_LEVEL_CRITICAL:
+         priority = LOG_CRIT;
+         break;
+      case EINA_LOG_LEVEL_ERR:
+         priority = LOG_ERR;
+         break;
+      case EINA_LOG_LEVEL_WARN:
+         priority = LOG_WARNING;
+         break;
+      case EINA_LOG_LEVEL_INFO:
+         priority = LOG_INFO;
+         break;
+      case EINA_LOG_LEVEL_DBG:
+         priority = LOG_DEBUG;
+         break;
+      default:
+         priority = level + LOG_CRIT;
+         break;
+     }
+
+   vsnprintf((char *)buf, sizeof(buf), fmt, args);
+
+   syslog(priority, "%s<%u> %s:%d %s() %s", d->name, eina_log_pid_get(),
+          file, line, fnc, buf);
+
+#ifdef EINA_LOG_BACKTRACE
+   if (EINA_UNLIKELY(level < _backtrace_level))
+     {
+        void *bt[256];
+        char **strings;
+        int btlen;
+        int i;
+
+        btlen = backtrace((void **)bt, 256);
+        strings = backtrace_symbols((void **)bt, btlen);
+        syslog(priority, "%s<%u> %s:%d %s() *** Backtrace ***", d->name,
+               eina_log_pid_get(), file, line, fnc);
+        for (i = 0; i < btlen; ++i)
+           syslog(priority, "%s<%u> %s:%d %s() %s", d->name,
+                  eina_log_pid_get(), file, line, fnc, strings[i]);
+        free(strings);
+     }
+#endif
+
+#else
+   (void) d;
+   (void) file;
+   (void) fnc;
+   (void) line;
+   (void) fmt;
+   (void) data;
+   (void) args;
+#endif
+}
+
+#ifdef HAVE_DLOG
+EAPI void
+eina_log_print_cb_dlog(const Eina_Log_Domain *d,
+                         Eina_Log_Level level,
+                         const char *file,
+                         const char *fnc,
+                         int line,
+                         const char *fmt,
+                         EINA_UNUSED void *data,
+                         va_list args)
+{
+#ifdef EINA_ENABLE_LOG
+   int log_level;
+   const char buf[512];
+   char tmp_log_level[512];
+
+   switch (level)
+     {
+      case EINA_LOG_LEVEL_CRITICAL:
+         log_level = DLOG_FATAL;
+         strcpy(tmp_log_level, "FATAL");
+         break;
+      case EINA_LOG_LEVEL_ERR:
+         log_level = DLOG_ERROR;
+         strcpy(tmp_log_level, "ERROR");
+         break;
+      case EINA_LOG_LEVEL_WARN:
+         log_level = DLOG_WARN;
+         strcpy(tmp_log_level, "WARNING");
+         break;
+      case EINA_LOG_LEVEL_INFO:
+         log_level = DLOG_INFO;
+         strcpy(tmp_log_level, "INFO");
+         break;
+      case EINA_LOG_LEVEL_DBG:
+         log_level = DLOG_DEBUG;
+         strcpy(tmp_log_level, "DEBUG");
+         break;
+      default:
+         log_level = DLOG_VERBOSE;
+         strcpy(tmp_log_level, "VERBOSE");
+         break;
+     }
+
+   vsnprintf((char *)buf, sizeof(buf), fmt, args);
+
+#ifdef _SECURE_LOG
+   print_log(log_level, LOG_TAG, "%s<%u> %s:%d %s() %s", d->name,
+             eina_log_pid_get(), file, line, fnc, buf);
+#endif
+
+#ifdef EINA_LOG_BACKTRACE
+   if (EINA_UNLIKELY(level < _backtrace_level))
+     {
+        void *bt[256];
+        char **strings;
+        int btlen;
+        int i;
+
+        btlen = backtrace((void **)bt, 256);
+        strings = backtrace_symbols((void **)bt, btlen);
+        print_log(log_level, LOG_TAG, "%s<%u> %s:%d %s() *** Backtrace ***",
+                  d->name, eina_log_pid_get(), file, line, fnc);
+        for (i = 0; i < btlen; ++i)
+           print_log(log_level, LOG_TAG, "%s<%u> %s:%d %s() %s", d->name,
+                    eina_log_pid_get(), file, line, fnc, strings[i]);
+        free(strings);
+     }
+#endif
+
+#else
+   (void) d;
+   (void) file;
+   (void) fnc;
+   (void) line;
+   (void) fmt;
+   (void) data;
+   (void) args;
+#endif
+}
+#endif
+
+/*--- TIZEN_ONLY : end ---*/
+
 EAPI void
 eina_log_print(int domain, Eina_Log_Level level, const char *file,
                const char *fnc, int line, const char *fmt, ...)
index 84e7f23..a4e600c 100644 (file)
@@ -933,6 +933,60 @@ EAPI void eina_log_print_cb_file(const Eina_Log_Domain *d,
                                  void                  *data,
                                  va_list                args);
 
+/*--- TIZEN_ONLY : begin ---*/
+/**
+ * @brief Alternative logging function, this outputs to the system log.
+ *
+ * @details This function never gives color as the output.
+ *
+ * @param[in] d The domain
+ * @param[in] level Not used
+ * @param[in] file The file that is logged
+ * @param[in] fnc The function that is logged
+ * @param[in] line The line that is logged
+ * @param[in] fmt The ouptut format to use
+ * @param[in] data Not Used
+ * @param[in] args The arguments needed by the format
+ *
+ */
+EAPI void eina_log_print_cb_syslog(const Eina_Log_Domain *d,
+                                   Eina_Log_Level         level,
+                                   const char            *file,
+                                   const char            *fnc,
+                                   int                    line,
+                                   const char            *fmt,
+                                   void                  *data,
+                                   va_list                args);
+
+#ifdef HAVE_DLOG
+/**
+ * @brief Alternative logging function, this outputs to the dlog.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in] d The domain
+ * @param[in] level Not used
+ * @param[in] file The file that is logged
+ * @param[in] fnc The function that is logged
+ * @param[in] line The line that is logged
+ * @param[in] fmt The ouptut format to use
+ * @param[in] data Not Used
+ * @param[in] args The arguments needed by the format
+ *
+ */
+EAPI void eina_log_print_cb_dlog(const Eina_Log_Domain *d,
+                                 Eina_Log_Level         level,
+                                 const char            *file,
+                                 const char            *fnc,
+                                 int                    line,
+                                 const char            *fmt,
+                                 void                  *data,
+                                 va_list                args);
+#endif
+
+/*--- TIZEN_ONLY : end ---*/
+
+
 
 /**
  * Alternative logging method, this will output to systemd journal.