From 41c90223f5806f26836fa21952f5a4e741ad32ed Mon Sep 17 00:00:00 2001 From: jeon Date: Tue, 26 Mar 2019 21:15:06 +0900 Subject: [PATCH] log: support dlog logging system Change-Id: I6057171180db13ef2e7020737741ceb822863d7f --- configure.ac | 8 +++++- packaging/pepper.spec | 1 + src/lib/pepper/Makefile.am | 5 ++++ src/lib/pepper/pepper-utils.h | 14 ++++++++-- src/lib/pepper/utils-log.c | 50 ++++++++++++++++++++++++++++++++--- 5 files changed, 71 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index ff6c3b3..3057e7d 100644 --- a/configure.ac +++ b/configure.ac @@ -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" diff --git a/packaging/pepper.spec b/packaging/pepper.spec index ba521e6..f4213ab 100644 --- a/packaging/pepper.spec +++ b/packaging/pepper.spec @@ -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. diff --git a/src/lib/pepper/Makefile.am b/src/lib/pepper/Makefile.am index 858805a..52c3810 100644 --- a/src/lib/pepper/Makefile.am +++ b/src/lib/pepper/Makefile.am @@ -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 \ diff --git a/src/lib/pepper/pepper-utils.h b/src/lib/pepper/pepper-utils.h index 17f59c0..bf49ba8 100644 --- a/src/lib/pepper/pepper-utils.h +++ b/src/lib/pepper/pepper-utils.h @@ -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, ...) \ diff --git a/src/lib/pepper/utils-log.c b/src/lib/pepper/utils-log.c index 94b523f..3d80992 100644 --- a/src/lib/pepper/utils-log.c +++ b/src/lib/pepper/utils-log.c @@ -32,9 +32,21 @@ #include #include #include +#include + +#ifdef HAVE_DLOG +# include +# 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 +} -- 2.34.1