log: support dlog logging system 75/202275/2
authorjeon <jhyuni.kang@samsung.com>
Tue, 26 Mar 2019 12:15:06 +0000 (21:15 +0900)
committerjeon <jhyuni.kang@samsung.com>
Wed, 27 Mar 2019 01:08:37 +0000 (10:08 +0900)
Change-Id: I6057171180db13ef2e7020737741ceb822863d7f

configure.ac
packaging/pepper.spec
src/lib/pepper/Makefile.am
src/lib/pepper/pepper-utils.h
src/lib/pepper/utils-log.c

index ff6c3b3..3057e7d 100644 (file)
@@ -36,9 +36,15 @@ if test x$have_tbm = xyes; then
    AC_DEFINE([HAVE_TBM], [1], [Build the tbm backend])
    PEPPER_REQUIRES="$PEPPER_REQUIRES libtbm wayland-tbm-server"
 fi
-
 AM_CONDITIONAL([HAVE_TBM], [test "x${have_tbm}" = "xyes"])
 
+PKG_CHECK_MODULES(DLOG, dlog, [have_dlog="yes"], [have_dlog="no"])
+if test "x${have_dlog}" = "xyes"; then
+       AC_DEFINE([HAVE_DLOG], [1], [Define to 1 if you have dlog])
+       PEPPER_REQUIRES="$PEPPER_REQUIRES dlog"
+fi
+AM_CONDITIONAL([HAVE_DLOG], [test "x${have_dlog}" = "xyes"])
+
 PEPPER_DIR="-I\$(top_srcdir)/src/lib/pepper"
 PEPPER_LIB="\$(top_srcdir)/src/lib/pepper/libpepper.la"
 
index ba521e6..f4213ab 100644 (file)
@@ -32,6 +32,7 @@ BuildRequires:  pkgconfig(tizen-extension-client)
 %if "%{ENABLE_TDM}" == "1"
 BuildRequires:  pkgconfig(libtdm)
 %endif
+BuildRequires:  pkgconfig(dlog)
 
 %description
 Pepper is a lightweight and flexible library for developing various types of wayland compositors.
index 858805a..52c3810 100644 (file)
@@ -8,6 +8,11 @@ libpepper_include_HEADERS = pepper.h pepper-utils.h pepper-utils-pixman.h pepper
 libpepper_la_CFLAGS = $(AM_CFLAGS) $(PEPPER_CFLAGS)
 libpepper_la_LIBADD = $(PEPPER_LIBS) -lm
 
+if HAVE_DLOG
+libpepper_la_CFLAGS += $(DLOG_CFLAGS)
+libpepper_la_LIBADD += $(DLOG_LIBS)
+endif
+
 libpepper_la_SOURCES = pepper.h                 \
                        pepper-internal.h        \
                        object.c                 \
index 17f59c0..bf49ba8 100644 (file)
@@ -315,17 +315,27 @@ pepper_id_allocator_free(pepper_id_allocator_t *allocator, uint32_t id);
 PEPPER_API int
 pepper_create_anonymous_file(off_t size);
 
+typedef enum pepper_log_level {
+       PEPPER_LOG_LEVEL_NONE,
+       PEPPER_LOG_LEVEL_DEBUG,
+       PEPPER_LOG_LEVEL_ERROR
+} pepper_log_level_t;
+
 PEPPER_API int
 pepper_log(const char *domain, int level, const char *format, ...);
 
+PEPPER_API void
+pepper_log_dlog_enable(pepper_bool_t enabled);
+
 #define PEPPER_ERROR(fmt, ...)                                                          \
     do {                                                                                \
-        pepper_log("ERROR", 0, "%s:%s: " fmt, __FILE__, __FUNCTION__, ##__VA_ARGS__);  \
+        pepper_log("ERROR", PEPPER_LOG_LEVEL_ERROR, "%s:%s: " fmt,                      \
+                   __FILE__, __FUNCTION__, ##__VA_ARGS__);                              \
     } while (0)
 
 #define PEPPER_TRACE(fmt, ...)                                                          \
     do {                                                                                \
-        pepper_log("DEBUG", 0, fmt, ##__VA_ARGS__);                                     \
+        pepper_log("DEBUG", PEPPER_LOG_LEVEL_DEBUG, fmt, ##__VA_ARGS__);                \
     } while (0)
 
 #define PEPPER_CHECK(exp, action, fmt, ...)                                             \
index 94b523f..3d80992 100644 (file)
 #include <stdarg.h>
 #include <time.h>
 #include <sys/time.h>
+#include <config.h>
+
+#ifdef HAVE_DLOG
+# include <dlog.h>
+#  ifdef LOG_TAG
+#   undef LOG_TAG
+#  endif
+# define LOG_TAG "PEPPER"
+#endif
 
 static FILE *pepper_log_file;
 static int pepper_log_verbosity = 3;
+#ifdef HAVE_DLOG
+static pepper_bool_t pepper_dlog_enable = PEPPER_FALSE;
+#endif
 static int cached_tm_mday = -1;
 
 static void __attribute__ ((constructor))
@@ -85,26 +97,56 @@ pepper_print_domain(const char *log_domain)
 }
 
 static int
-pepper_vlog(const char *format, va_list ap)
+pepper_vlog(const char *format, int level, va_list ap)
 {
+#ifdef HAVE_DLOG
+       int dlog_level = DLOG_INFO;
+
+       if (pepper_dlog_enable)
+       {
+               if (level == PEPPER_LOG_LEVEL_DEBUG)
+                       dlog_level = DLOG_DEBUG;
+               else if (level == PEPPER_LOG_LEVEL_ERROR)
+                       dlog_level = DLOG_ERROR;
+
+               return dlog_vprint(dlog_level, LOG_TAG, format, ap);
+       }
+#endif
        return vfprintf(pepper_log_file, format, ap);
 }
 
 PEPPER_API int
 pepper_log(const char *domain, int level, const char *format, ...)
 {
-       int l;
+       int l = 0;
        va_list argp;
 
        if (level > pepper_log_verbosity || level < 0)
                return 0;
-
+#ifdef HAVE_DLOG
+       if (!pepper_dlog_enable)
+       {
+               l = pepper_print_timestamp();
+               l += pepper_print_domain(domain);
+       }
+#else
        l = pepper_print_timestamp();
        l += pepper_print_domain(domain);
+#endif
 
        va_start(argp, format);
-       l += pepper_vlog(format, argp);
+       l += pepper_vlog(format, level, argp);
        va_end(argp);
 
        return l;
 }
+
+PEPPER_API void
+pepper_log_dlog_enable(pepper_bool_t enabled)
+{
+#ifdef HAVE_DLOG
+       pepper_dlog_enable = enabled;
+#else
+       ;
+#endif
+}