[lxc-devel] [lxc/master] log: support dlog

2xsec on Github lxc-bot at linuxcontainers.org
Tue Sep 11 07:10:46 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 607 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180911/47c79c5b/attachment.bin>
-------------- next part --------------
From 5c7bfc02315769b12ac47c7ba4d8601386ce9cca Mon Sep 17 00:00:00 2001
From: 2xsec <dh48.jeong at samsung.com>
Date: Tue, 11 Sep 2018 16:04:25 +0900
Subject: [PATCH] log: support dlog

Signed-off-by: 2xsec <dh48.jeong at samsung.com>
---
 configure.ac        | 16 ++++++++++++
 src/lxc/Makefile.am |  4 +++
 src/lxc/log.c       | 59 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+)

diff --git a/configure.ac b/configure.ac
index 502b9ae1d..92d6601d7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -693,6 +693,19 @@ AC_ARG_ENABLE([thread-safety],
 	[], [enable_thread_safety=yes])
 AM_CONDITIONAL([ENFORCE_THREAD_SAFETY], [test "x$enable_thread_safety" = "xyes"])
 
+AC_ARG_ENABLE([dlog],
+	[AC_HELP_STRING([--enable-dlog], [enable dlog support [default=no]])],
+	[], [enable_dlog=no])
+AM_CONDITIONAL([ENABLE_DLOG], [test "x$enable_dlog" = "xyes"])
+
+AM_COND_IF([ENABLE_DLOG],
+	[PKG_CHECK_MODULES([DLOG],[dlog],[],[
+		AC_CHECK_HEADER([dlog.h],[],[AC_MSG_ERROR([You must install the dlog development package in order to compile lxc])])
+		AC_CHECK_LIB([dlog], [dlog_print],[],[AC_MSG_ERROR([You must install the dlog development package in order to compile lxc])])
+		AC_SUBST([DLOG_LIBS], [-ldlog])
+		])
+	])
+
 # Files requiring some variable expansion
 AC_CONFIG_FILES([
 	Makefile
@@ -939,4 +952,7 @@ Paths:
 
 Thread-safety:
  - enforce: $enable_thread_safety
+
+Dlog:
+ - enable: $enable_dlog
 EOF
diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am
index 1f8c5d980..08fa8e03a 100644
--- a/src/lxc/Makefile.am
+++ b/src/lxc/Makefile.am
@@ -211,6 +211,10 @@ if ENABLE_SELINUX
 AM_CFLAGS += -DHAVE_SELINUX
 endif
 
+if ENABLE_DLOG
+AM_CFLAGS += -DHAVE_DLOG
+endif
+
 if USE_CONFIGPATH_LOGS
 AM_CFLAGS += -DUSE_CONFIGPATH_LOGS
 endif
diff --git a/src/lxc/log.c b/src/lxc/log.c
index dd15bdd50..4f6611726 100644
--- a/src/lxc/log.c
+++ b/src/lxc/log.c
@@ -49,6 +49,13 @@
 #include "include/strlcpy.h"
 #endif
 
+#if HAVE_DLOG
+#include <dlog.h>
+
+#undef LOG_TAG
+#define LOG_TAG "LXC"
+#endif
+
 /* We're logging in seconds and nanoseconds. Assuming that the underlying
  * datatype is currently at maximum a 64bit integer, we have a date string that
  * is of maximum length (2^64 - 1) * 2 = (21 + 21) = 42.
@@ -347,6 +354,41 @@ static int log_append_logfile(const struct lxc_log_appender *appender,
 	return ret;
 }
 
+#if HAVE_DLOG
+static int log_append_dlog(const struct lxc_log_appender *appender,
+			     struct lxc_log_event *event)
+{
+	if (event->priority < LXC_LOG_LEVEL_ERROR)
+		return 0;
+
+	switch(event->priority) {
+	case LXC_LOG_LEVEL_TRACE:
+	case LXC_LOG_LEVEL_DEBUG:
+		LOG_VA(LOG_DEBUG, LOG_TAG, event->fmt, *event->vap);
+		break;
+	case LXC_LOG_LEVEL_INFO:
+		LOG_VA(LOG_INFO, LOG_TAG, event->fmt, *event->vap);
+		break;
+	case LXC_LOG_LEVEL_NOTICE:
+	case LXC_LOG_LEVEL_WARN:
+		LOG_VA(LOG_WARN, LOG_TAG, event->fmt, *event->vap);
+		break;
+	case LXC_LOG_LEVEL_ERROR:
+		LOG_VA(LOG_ERROR, LOG_TAG, event->fmt, *event->vap);
+		break;
+	case LXC_LOG_LEVEL_CRIT:
+	case LXC_LOG_LEVEL_ALERT:
+	case LXC_LOG_LEVEL_FATAL:
+		LOG_VA(LOG_FATAL, LOG_TAG, event->fmt, *event->vap);
+		break;
+	default:
+		break;
+	}
+
+	return 0;
+}
+#endif
+
 static struct lxc_log_appender log_appender_syslog = {
 	.name		= "syslog",
 	.append		= log_append_syslog,
@@ -365,6 +407,14 @@ static struct lxc_log_appender log_appender_logfile = {
 	.next		= NULL,
 };
 
+#if HAVE_DLOG
+static struct lxc_log_appender log_appender_dlog = {
+	.name		= "dlog",
+	.append		= log_append_dlog,
+	.next		= NULL,
+};
+#endif
+
 static struct lxc_log_category log_root = {
 	.name		= "root",
 	.priority	= LXC_LOG_LEVEL_ERROR,
@@ -372,12 +422,21 @@ static struct lxc_log_category log_root = {
 	.parent		= NULL,
 };
 
+#if HAVE_DLOG
+struct lxc_log_category lxc_log_category_lxc = {
+	.name		= "lxc",
+	.priority	= LXC_LOG_LEVEL_ERROR,
+	.appender	= &log_appender_dlog,
+	.parent		= &log_root
+};
+#else
 struct lxc_log_category lxc_log_category_lxc = {
 	.name		= "lxc",
 	.priority	= LXC_LOG_LEVEL_ERROR,
 	.appender	= &log_appender_logfile,
 	.parent		= &log_root
 };
+#endif
 
 /*---------------------------------------------------------------------------*/
 static int build_dir(const char *name)


More information about the lxc-devel mailing list