summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIevgen Vagin <i.vagin@samsung.com>2016-05-04 21:52:06 +0300
committerIevgen Vagin <i.vagin@samsung.com>2016-05-11 12:22:44 +0300
commited8f15d61d464b82dc793772bfb8850d885d1194 (patch)
tree7b18b876c3dba1cd7865e0bab25e9891c023890b /src
parenta274b00058e0375a4e326614ddbaf590a20bd0ff (diff)
downloadmurphy-ed8f15d61d464b82dc793772bfb8850d885d1194.tar.gz
murphy-ed8f15d61d464b82dc793772bfb8850d885d1194.tar.bz2
murphy-ed8f15d61d464b82dc793772bfb8850d885d1194.zip
Note: to enable plugin, it has to be loaded in configuration file (/etc/murphy/murphy.lua) by m:try_load_plugin('dlog') command; dlog support is enabled by default; use --disable-dlog configure command to build without dlog support Change-Id: I1e85f52a5ac58f24e1639e4b2945e9555b79289b Signed-off-by: Ievgen Vagin <i.vagin@samsung.com>
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am29
-rw-r--r--src/plugins/plugin-dlog.c72
-rw-r--r--src/plugins/resource-native/libmurphy-resource/resource-log.c31
3 files changed, 131 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 605de80..07be7ea 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1051,6 +1051,11 @@ libmurphy_resource_la_LDFLAGS = \
libmurphy_resource_la_LIBADD = \
libmurphy-common.la
+if DLOG_ENABLED
+libmurphy_resource_la_CFLAGS += $(DLOG_CFLAGS) -DDLOG_ENABLED
+libmurphy_resource_la_LIBADD += $(DLOG_LIBS)
+endif
+
libmurphy_resource_la_DEPENDENCIES = \
libmurphy-common.la \
linker-script.resource \
@@ -1426,6 +1431,30 @@ endif
endif
endif
+# dlog (logging) plugin
+if DLOG_ENABLED
+DLOG_PLUGIN_SOURCES = plugins/plugin-dlog.c
+DLOG_PLUGIN_CFLAGS = $(DLOG_CFLAGS)
+DLOG_PLUGIN_LIBS = $(DLOG_LIBS)
+
+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
+endif
+
###################################
# murphy daemon
diff --git a/src/plugins/plugin-dlog.c b/src/plugins/plugin-dlog.c
new file mode 100644
index 0000000..be99417
--- /dev/null
+++ b/src/plugins/plugin-dlog.c
@@ -0,0 +1,72 @@
+#include <stdlib.h>
+#include <dlog.h>
+
+#include <murphy/common.h>
+#include <murphy/core.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "MURPHYD"
+
+/* Logger function */
+
+static void dlogger(void *data, mrp_log_level_t level, const char *file,
+ int line, const char *func, const char *format, va_list ap)
+{
+ va_list cp;
+ int prio;
+ char fbuf[1024];
+
+ MRP_UNUSED(data);
+
+ va_copy(cp, ap);
+ switch (level) {
+ case MRP_LOG_ERROR: prio = DLOG_ERROR; break;
+ case MRP_LOG_WARNING: prio = DLOG_WARN; break;
+ case MRP_LOG_INFO: prio = DLOG_INFO; break;
+ case MRP_LOG_DEBUG: prio = DLOG_DEBUG; break;
+ default: prio = DLOG_INFO;
+ }
+
+ snprintf(fbuf, sizeof(fbuf), "%s: %s(%d) > %s", file, func, line, format);
+ dlog_vprint(prio, LOG_TAG, fbuf, cp);
+
+ va_end(cp);
+}
+
+/* Plugin initialization */
+
+static int dlogger_init(mrp_plugin_t *plugin)
+{
+ MRP_UNUSED(plugin);
+
+ if (mrp_log_register_target("dlog", dlogger, NULL))
+ mrp_log_info("dlog: registered logging target.");
+ else
+ mrp_log_error("dlog: failed to register logging target.");
+
+ return TRUE;
+}
+
+/* Plugin deinitialization */
+
+static void dlogger_exit(mrp_plugin_t *plugin)
+{
+ MRP_UNUSED(plugin);
+
+ mrp_log_unregister_target("dlog");
+
+ return;
+}
+
+#define DLOGGER_DESCRIPTION "A dlog based logger for Murphy."
+#define DLOGGER_HELP "dlog logger support for Murphy."
+#define DLOGGER_VERSION MRP_VERSION_INT(0, 0, 1)
+#define DLOGGER_AUTHORS "Ievgen Vagin <i.vagin@samsung.com>"
+
+MURPHY_REGISTER_PLUGIN("dlog",
+ DLOGGER_VERSION, DLOGGER_DESCRIPTION,
+ DLOGGER_AUTHORS, DLOGGER_HELP, MRP_SINGLETON,
+ dlogger_init, dlogger_exit,
+ NULL, 0, NULL, 0, NULL, 0, NULL);
diff --git a/src/plugins/resource-native/libmurphy-resource/resource-log.c b/src/plugins/resource-native/libmurphy-resource/resource-log.c
index d5433f9..e1a0e8f 100644
--- a/src/plugins/resource-native/libmurphy-resource/resource-log.c
+++ b/src/plugins/resource-native/libmurphy-resource/resource-log.c
@@ -33,9 +33,38 @@
#include "resource-api.h"
#include "resource-private.h"
+#ifdef DLOG_ENABLED
+#include <dlog.h>
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "MURPHY_RESOURCE"
+#endif
+
static void default_logger(mrp_log_level_t level, const char *file,
int line, const char *func,
const char *format, va_list args)
+#ifdef DLOG_ENABLED
+{
+ va_list cp;
+ int prio;
+ char fbuf[1024];
+
+ va_copy(cp, args);
+ switch (level) {
+ case MRP_LOG_ERROR: prio = DLOG_ERROR; break;
+ case MRP_LOG_WARNING: prio = DLOG_WARN; break;
+ case MRP_LOG_INFO: prio = DLOG_INFO; break;
+ case MRP_LOG_DEBUG: prio = DLOG_DEBUG; break;
+ default: prio = DLOG_INFO;
+ }
+
+ snprintf(fbuf, sizeof(fbuf), "%s: %s(%d) > %s", file, func, line, format);
+ dlog_vprint(prio, LOG_TAG, fbuf, cp);
+
+ va_end(cp);
+}
+#else
{
va_list ap;
@@ -43,7 +72,7 @@ static void default_logger(mrp_log_level_t level, const char *file,
mrp_log_msgv(level, file, line, func, format, ap);
va_end(ap);
}
-
+#endif
static mrp_res_logger_t __res_logger = default_logger;