From 50afda0893f5f5e85b728312e6056e7f17d5ffb0 Mon Sep 17 00:00:00 2001 From: Krisztian Litkey Date: Thu, 20 Dec 2012 20:36:37 +0200 Subject: [PATCH] plugin-dlog: added a plugin that enables logging to dlog. --- configure.ac | 27 +++++++++++++++ src/Makefile.am | 32 ++++++++++++++++++ src/plugins/plugin-dlog.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+) create mode 100644 src/plugins/plugin-dlog.c diff --git a/configure.ac b/configure.ac index cee5167..d0fa01a 100644 --- a/configure.ac +++ b/configure.ac @@ -486,6 +486,31 @@ AC_SUBST(TELEPHONY_ENABLED) AC_SUBST(TELEPHONY_CFLAGS) AC_SUBST(TELEPHONY_LIBS) +# Check if dlog support was enabled. +AC_ARG_ENABLE(dlog, + [ --enable-dlog enable dlog support], + [enable_dlog=$enableval], [enable_dlog=auto]) + +if test "$enable_dlog" != "no"; then + PKG_CHECK_MODULES(DLOG, dlog, + [have_dlog=yes], [have_dlog=no]) + if test "$have_dlog" = "no" -a "$enable_dlog" = "yes"; then + AC_MSG_ERROR([dlog development libraries not found.]) + fi + + enable_dlog="$have_dlog" +else + AC_MSG_NOTICE([dlog support is disabled.]) +fi + +if test "$enable_dlog" = "yes"; then + AC_DEFINE([DLOG_ENABLED], 1, [Enable dlog support ?]) +fi +AM_CONDITIONAL(DLOG_ENABLED, [test "$enable_dlog" = "yes"]) +AC_SUBST(DLOG_ENABLED) +AC_SUBST(DLOG_CFLAGS) +AC_SUBST(DLOG_LIBS) + # Set up murphy CFLAGS and LIBS. MURPHY_CFLAGS="" MURPHY_LIBS="" @@ -582,6 +607,7 @@ AM_CONDITIONAL(DISABLED_PLUGIN_TEST, [check_if_disabled test]) AM_CONDITIONAL(DISABLED_PLUGIN_DBUS, [check_if_disabled dbus]) AM_CONDITIONAL(DISABLED_PLUGIN_GLIB, [check_if_disabled glib]) AM_CONDITIONAL(DISABLED_PLUGIN_CONSOLE, [check_if_disabled console]) +AM_CONDITIONAL(DISABLED_PLUGIN_DLOG, [check_if_disabled dlog]) AM_CONDITIONAL(DISABLED_PLUGIN_RESOURCE_DBUS, [check_if_disabled resource-dbus]) AM_CONDITIONAL(DISABLED_PLUGIN_RESOURCE_WRT, [check_if_disabled resource-wrt]) AM_CONDITIONAL(DISABLED_PLUGIN_AMB, [check_if_disabled amb]) @@ -594,6 +620,7 @@ AM_CONDITIONAL(BUILTIN_PLUGIN_TEST, [check_if_internal test]) AM_CONDITIONAL(BUILTIN_PLUGIN_DBUS, [check_if_internal dbus]) AM_CONDITIONAL(BUILTIN_PLUGIN_GLIB, [check_if_internal glib]) AM_CONDITIONAL(BUILTIN_PLUGIN_CONSOLE, [check_if_internal console]) +AM_CONDITIONAL(BUILTIN_PLUGIN_DLOG, [check_if_internal dlog]) AM_CONDITIONAL(BUILTIN_PLUGIN_RESOURCE_DBUS, [check_if_internal resource-dbus]) AM_CONDITIONAL(BUILTIN_PLUGIN_RESOURCE_WRT, [check_if_internal resource-wrt]) AM_CONDITIONAL(BUILTIN_PLUGIN_AMB, [check_if_internal amb]) diff --git a/src/Makefile.am b/src/Makefile.am index 78acaeb..3ed5e1a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1267,6 +1267,38 @@ endif endif endif +# dlog plugin +DLOG_PLUGIN_REGULAR_SOURCES = plugins/plugin-dlog.c +DLOG_PLUGIN_SOURCES = $(DLOG_PLUGIN_REGULAR_SOURCES) \ + plugin-dlog-func-info.c +DLOG_PLUGIN_CFLAGS = $(DLOG_CFLAGS) +DLOG_PLUGIN_LIBS = $(DLOG_LIBS) + +if DLOG_ENABLED +if !DISABLED_PLUGIN_DLOG +if BUILTIN_PLUGIN_DLOG +BUILTIN_PLUGINS += $(DLOG_PLUGIN_SOURCES) +BUILTIN_CFLAGS += $(DLOG_PLUGIN_CFLAGS) +BUILTIN_LIBS += $(DLOG_PLUGIN_LIBS) +else +plugin_dlog_la_SOURCES = $(DLOG_PLUGIN_SOURCES) +plugin_dlog_la_CFLAGS = $(DLOG_PLUGIN_CFLAGS) \ + $(MURPHY_CFLAGS) $(AM_CFLAGS) +plugin_dlog_la_LDFLAGS = -module -avoid-version +plugin_dlog_la_LIBADD = $(DLOG_PLUGIN_LIBS) + +plugin_LTLIBRARIES += plugin-dlog.la +endif +endif + +# debug file:line-function mapping generation +plugin-dlog-func-info.c: $(DLOG_PLUGIN_REGULAR_SOURCES) + $(QUIET_GEN)$(top_builddir)/build-aux/gen-debug-table -o $@ $^ + +clean-func-infos:: + -rm plugin-dlog-func-info.c +endif + # native resource plugin if BUILD_RESOURCES PLUGIN_RESOURCE_NATIVE_REGULAR_SOURCES = \ diff --git a/src/plugins/plugin-dlog.c b/src/plugins/plugin-dlog.c new file mode 100644 index 0000000..ce935a5 --- /dev/null +++ b/src/plugins/plugin-dlog.c @@ -0,0 +1,83 @@ +#include + +#include + +#include +#include + + +enum { + ARG_FORCE, /* force TIZEN_DEBUG_LEVEL ? */ + ARG_TAG, /* tag to pass to dlog */ +}; + +static const char *log_tag; /* tag to pass to dlog */ + + +static void logger(void *data, mrp_log_level_t level, const char *file, + int line, const char *func, const char *format, va_list ap) +{ + va_list cp; + + MRP_UNUSED(data); + MRP_UNUSED(file); + MRP_UNUSED(line); + MRP_UNUSED(func); + + va_copy(cp, ap); + switch (level) { + case MRP_LOG_ERROR: SLOG_VA(LOG_ERROR, log_tag, format, cp); break; + case MRP_LOG_WARNING: SLOG_VA(LOG_WARN, log_tag, format, cp); break; + case MRP_LOG_INFO: SLOG_VA(LOG_INFO, log_tag, format, cp); break; + case MRP_LOG_DEBUG: SLOG_VA(LOG_DEBUG, log_tag, format, cp); break; + default: break; + } + va_end(cp); +} + + +static int dlogger_init(mrp_plugin_t *plugin) +{ + mrp_plugin_arg_t *args = plugin->args; + int force; + + force = args[ARG_FORCE].bln; + log_tag = args[ARG_TAG].str; + + if (force) /* Use the Force, Luke ! */ + setenv("TIZEN_DEBUG_LEVEL", "31", TRUE); + + if (mrp_log_register_target("dlog", logger, NULL)) + mrp_log_info("dlog: registered logging target."); + else + mrp_log_error("dlog: failed to register logging target."); + + return TRUE; +} + + +static void dlogger_exit(mrp_plugin_t *plugin) +{ + MRP_UNUSED(plugin); + + mrp_log_unregister_target("dlog"); + + return; +} + +#define DLOGGER_DESCRIPTION "A dlog logger for Murphy." +#define DLOGGER_HELP "dlog logger support for Murphy." +#define DLOGGER_VERSION MRP_VERSION_INT(0, 0, 1) +#define DLOGGER_AUTHORS "Krisztian Litkey " + +static mrp_plugin_arg_t plugin_args[] = { + MRP_PLUGIN_ARGIDX(ARG_FORCE, BOOL , "force", FALSE ), + MRP_PLUGIN_ARGIDX(ARG_TAG , STRING, "tag" , "MURPHY"), +}; + +MURPHY_REGISTER_PLUGIN("dlog", + DLOGGER_VERSION, DLOGGER_DESCRIPTION, + DLOGGER_AUTHORS, DLOGGER_HELP, MRP_SINGLETON, + dlogger_init, dlogger_exit, + plugin_args, MRP_ARRAY_SIZE(plugin_args), + NULL, 0, NULL, 0, NULL); -- 2.7.4