change dlog control logic
authorjuho <juho80.son@samsung.com>
Mon, 17 Jun 2013 13:40:29 +0000 (22:40 +0900)
committerjuho <juho80.son@samsung.com>
Mon, 17 Jun 2013 13:44:54 +0000 (22:44 +0900)
and sync with latest version of private code.

we don't use Environment Variable not anymore.
so we read the configuration file.
for reduce file read operation delay.
copy that file to /tmp as init time by dlog.sh script.
It will be changed, when dlog apply to systemd service.

sync with latest version of private.
added secure dlog macro.
removed unused script for platform environment variable.
added systemd-journal features.

Change-Id: Ia844c90b7cabff66dfbd5d5eb89738b948b0d350

14 files changed:
.dloglevel [deleted file]
Makefile.am
configure.ac
dlog.pc.in
dlog.sh
dlog_dump.sh [new file with mode: 0755]
dlogctrl
include/dlog.h
log.c
logutil.c
packaging/dlog.spec
packaging/dlogutil.manifest
packaging/tizen-debug-level.service [deleted file]
tizen_platform_env.sh [deleted file]

diff --git a/.dloglevel b/.dloglevel
deleted file mode 100644 (file)
index d00491f..0000000
+++ /dev/null
@@ -1 +0,0 @@
-1
index c16223f..9d3ec97 100755 (executable)
@@ -1,12 +1,4 @@
-
-
-if SD_JOURNAL_SUPPORT
-AM_CFLAGS = @CFLAGS@ -I$(srcdir)/include \
-             -I$(srcdir)/include/internal -DSD_JOURNAL_SUPPORT
-else
-AM_CFLAGS = @CFLAGS@ -I$(srcdir)/include \
-             -I$(srcdir)/include/internal
-endif
+AM_CFLAGS = -I$(srcdir)/include
 
 dlog_includedir = $(includedir)/dlog
 dlog_include_HEADERS = \
@@ -18,11 +10,8 @@ libdlog_la_SOURCES =  \
        log.c \
        include/dlog.h
 
-if SD_JOURNAL_SUPPORT
-libdlog_la_LIBADD = -lpthread -lsystemd-journal
-else
-libdlog_la_LIBADD = -lpthread
-endif
+libdlog_la_LIBADD = -lpthread $(systemd_journal_LIBS)
+
 bin_PROGRAMS= dlogutil
 
 dlogutil_SOURCES = \
index 186a593..68a02ec 100755 (executable)
@@ -20,11 +20,21 @@ AC_PROG_LIBTOOL
 # checks arch
 AM_CONDITIONAL(DEVELOP_VER, test $DEVELOP_VER = yes)
 
-SD_JOURNAL_SUPPORT=no
-
-#AC_DEFINE([SD_JOURNAL_SUPPORT], [], [Description])
-
-AM_CONDITIONAL(SD_JOURNAL_SUPPORT, test $SD_JOURNAL_SUPPORT = yes)
+# check for libsystemd-journal
+AC_ARG_WITH([systemd-journal],
+       AS_HELP_STRING([--with-systemd-journal], [check for systemd-journal]),
+       [], [with_systemd_journal=check])
+have_systemd_journal=no
+if test "x$with_systemd_journal" != "xno"; then
+       PKG_CHECK_MODULES(systemd_journal, [libsystemd-journal],
+               [AC_DEFINE(HAVE_SYSTEMD_JOURNAL, 1, [Define if systemd journal is available])
+               have_systemd_journal=yes],
+           have_systemd_journal=no)
+       if test "x$have_systemd_journal" = "xno" -a "x$with_systemd_journal" = "xyes"; then
+               AC_MSG_ERROR([systemd journal requested but libraries not found])
+       fi
+fi
+AM_CONDITIONAL(HAVE_SYSTEMD_JOURNAL, [test "x$have_systemd_journal" = "xyes"])
 
 #AM_CONDITIONAL([ARCH_IS_ARM], [test "x$ARCH" = "xarm"])
 if test "x$ARCH" = "xarm" ; then
index 1fcb33b..b0d787d 100755 (executable)
@@ -7,5 +7,5 @@ Name: dlog
 Description: logging service
 Version: 1.0
 Requires: 
-Libs: -L${libdir} -ldlog -lpthread
+Libs: -L${libdir} -ldlog -lpthread @systemd_journal_LIBS@
 Cflags: -I${includedir}/dlog
diff --git a/dlog.sh b/dlog.sh
index 9676793..4c59aac 100644 (file)
--- a/dlog.sh
+++ b/dlog.sh
@@ -1,2 +1,7 @@
 #!/bin/sh
-/usr/bin/dlogutil -r 5120 -n 1 -f /var/log/dlog -v threadtime *:W &
+cp /opt/etc/platformlog.conf /tmp/.platformlog.conf
+chmod 660 /tmp/.platformlog.conf
+chown root:app_logging /tmp/.platformlog.conf
+chsmack -a '_' -e 'none' /tmp/.platformlog.conf
+/usr/bin/dlogutil -b system -r 5120 -n 1 -f /var/log/dlog_system -v threadtime *:I &
+/usr/bin/dlogutil -b main -r 3072 -n 1 -f /var/log/dlog_main -v threadtime *:W &
diff --git a/dlog_dump.sh b/dlog_dump.sh
new file mode 100755 (executable)
index 0000000..bf0124d
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/sh
+if [ -z "$1" ]; then
+       exit
+else
+       LOG_DST_DIR=$1
+fi
+#--------------------------------------
+#    dump dlog logs /dev/log_main, log_system, log_radio
+#--------------------------------------
+DLOG_LOG_DIR=${LOG_DST_DIR}/dlog_log
+mkdir -p "${DLOG_LOG_DIR}"
+dlogutil -b radio -d -v time -f ${DLOG_LOG_DIR}/dump_dlog_radio.log -r 512 -n 1 &
+dlogutil -b system -d -v time -f ${DLOG_LOG_DIR}/dump_dlog_system.log -r 1024 -n 1 &
+dlogutil -b main -d -v time -f ${DLOG_LOG_DIR}/dump_dlog_main.log -r 4096 -n 1 &
index 70751e7..3eea301 100755 (executable)
--- a/dlogctrl
+++ b/dlogctrl
@@ -41,18 +41,14 @@ fi
 
 if [ "$MODE" = "set" ]; then
        if [ "$OBJ" = "platformlog" ] && [ "$VAL" = "1" ] ; then
-               touch /opt/etc/dlog/.platformloggingmode 2>/dev/null
+               echo 1 > /opt/etc/platformlog.conf 2>/dev/null
        elif [ "$OBJ" = "platformlog" ] && [ "$VAL" = "0" ] ; then
-               rm -f /opt/etc/dlog/.platformloggingmode 2>/dev/null
+               echo 0 > /opt/etc/platformlog.conf 2>/dev/null
        fi
     echo "You must reboot this target to apply the change!"
 else
        if [ "$OBJ" = "platformlog" ]; then
-               if [ -e "/opt/etc/dlog/.platformloggingmode" ]; then
-                       echo 1
-               else
-                       echo 0
-               fi
+               cat /opt/etc/platformlog.conf 2>/dev/null
        fi
 fi
 
index 8fe6647..65f5c4f 100755 (executable)
@@ -59,11 +59,10 @@ extern "C" {
 #define LOG_TAG NULL
 #endif
 
-#define LOG_ON() _get_logging_on()
-
 #ifndef __MODULE__
 #define __MODULE__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
 #endif
+
 /*
  * log priority values, in ascending priority order.
  */
@@ -77,6 +76,7 @@ typedef enum {
        DLOG_ERROR,
        DLOG_FATAL,
        DLOG_SILENT,
+       DLOG_PRIO_MAX   /* Keep this always at the end. */
 } log_priority;
 
 typedef enum {
@@ -89,470 +89,240 @@ typedef enum {
 
 #define CONDITION(cond)     (__builtin_expect((cond) != 0, 0))
 
-// ---------------------------------------------------------------------
-/**
- * Secure Log Macro.
- */
-
-#define _SECURE_LOG 1
+#define _SECURE_LOG /* Temporary default added, This define code will be removed */
 
-#ifndef SECLOG
-#if _SECURE_LOG
-#define SECLOG(...)   (0)
+// Macro inner work---------------------------------------------------------------
+#undef _SECURE_
+#ifndef _SECURE_LOG
+#define _SECURE_ (0)
 #else
-#define SECLOG(format, arg...) \
-       (LOG_ON() ? (SLOG(LOG_WARN, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
-#endif
-
+#define _SECURE_ (1)
+#endif
+#undef LOG_
+#define LOG_(id, prio, tag, fmt, arg...) \
+       ( __dlog_print(id, prio, tag, "%s: %s(%d) > " fmt, __MODULE__, __func__, __LINE__, ##arg))
+#undef SECURE_LOG_
+#define SECURE_LOG_(id, prio, tag, fmt, arg...) \
+       (_SECURE_ ? ( __dlog_print(id, prio, tag, "%s: %s(%d) > [SECURE_LOG] " fmt, __MODULE__, __func__, __LINE__, ##arg)) : (0))
 // ---------------------------------------------------------------------
 /**
- * Simplified macro to send a verbose log message using the current LOG_TAG.
- */
-#ifndef LOGV
-#if LOG_NDEBUG
-#define LOGV(...)   (0)
-#else
-#define LOGV(format, arg...) \
-       (LOG_ON() ? (LOG(LOG_VERBOSE, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
-#endif
-/**
- * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
+ * For Secure Log.
+ * Normally we strip Secure log from release builds.
+ * Please use this macros.
  */
-#ifndef LOGV_IF
-#if LOG_NDEBUG
-#define LOGV_IF(cond, format, arg...)   (0)
-#else
-#define LOGV_IF(cond, format, arg...) \
-       (((CONDITION(cond)) && (LOG_ON())) ? \
-         (LOG(LOG_VERBOSE, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
-#endif
 /**
- * Simplified macro to send a debug log message using the current LOG_TAG.
- */
-#ifndef LOGD
-#define LOGD(format, arg...) \
-       (LOG_ON() ? (LOG(LOG_DEBUG, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
-/**
- * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
+ * For Application and etc.
+ * Simplified macro to send a main log message using the current LOG_TAG.
+ * Example:
+ *  SECURE_LOGD("app debug %d", num);
+ *  SECURE_LOGE("app error %d", num);
  */
-#ifndef LOGD_IF
-#define LOGD_IF(cond, format, arg...) \
-       (((CONDITION(cond)) && (LOG_ON())) ? \
-         (LOG(LOG_DEBUG, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
-
+#define SECURE_LOGD(format, arg...) SECURE_LOG_(LOG_ID_MAIN, DLOG_DEBUG, LOG_TAG, format, ##arg)
+#define SECURE_LOGI(format, arg...) SECURE_LOG_(LOG_ID_MAIN, DLOG_INFO, LOG_TAG, format, ##arg)
+#define SECURE_LOGW(format, arg...) SECURE_LOG_(LOG_ID_MAIN, DLOG_WARN, LOG_TAG, format, ##arg)
+#define SECURE_LOGE(format, arg...) SECURE_LOG_(LOG_ID_MAIN, DLOG_ERROR, LOG_TAG, format, ##arg)
 /**
- * Simplified macro to send an info log message using the current LOG_TAG.
+ * For Framework and system etc.
+ * Simplified macro to send a system log message using the current LOG_TAG.
+ * Example:
+ *  SECURE_SLOGD("system debug %d", num);
+ *  SECURE_SLOGE("system error %d", num);
  */
-#ifndef LOGI
-#define LOGI(format, arg...) \
-       (LOG_ON() ? (LOG(LOG_INFO, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
+#define SECURE_SLOGD(format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, DLOG_DEBUG, LOG_TAG, format, ##arg)
+#define SECURE_SLOGI(format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, DLOG_INFO, LOG_TAG, format, ##arg)
+#define SECURE_SLOGW(format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, DLOG_WARN, LOG_TAG, format, ##arg)
+#define SECURE_SLOGE(format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, DLOG_ERROR, LOG_TAG, format, ##arg)
 /**
- * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
+ * For Modem and radio etc.
+ * Simplified macro to send a radio log message using the current LOG_TAG.
+ * Example:
+ *  SECURE_RLOGD("radio debug %d", num);
+ *  SECURE_RLOGE("radio error %d", num);
  */
-#ifndef LOGI_IF
-#define LOGI_IF(cond, format, arg...) \
-       (((CONDITION(cond)) && (LOG_ON())) ? \
-         (LOG(LOG_INFO, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
-
+#define SECURE_RLOGD(format, arg...) SECURE_LOG_(LOG_ID_RADIO, DLOG_DEBUG, LOG_TAG, format, ##arg)
+#define SECURE_RLOGI(format, arg...) SECURE_LOG_(LOG_ID_RADIO, DLOG_INFO, LOG_TAG, format, ##arg)
+#define SECURE_RLOGW(format, arg...) SECURE_LOG_(LOG_ID_RADIO, DLOG_WARN, LOG_TAG, format, ##arg)
+#define SECURE_RLOGE(format, arg...) SECURE_LOG_(LOG_ID_RADIO, DLOG_ERROR, LOG_TAG, format, ##arg)
 /**
- * Simplified macro to send a warning log message using the current LOG_TAG.
+ * For Tizen OSP Application macro.
  */
-#ifndef LOGW
-#define LOGW(format, arg...) \
-       (LOG_ON() ? (LOG(LOG_WARN, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
+#define SECURE_ALOGD(format, arg...) SECURE_LOG_(LOG_ID_APPS, DLOG_DEBUG, LOG_TAG, format, ##arg)
+#define SECURE_ALOGI(format, arg...) SECURE_LOG_(LOG_ID_APPS, DLOG_INFO, LOG_TAG, format, ##arg)
+#define SECURE_ALOGW(format, arg...) SECURE_LOG_(LOG_ID_APPS, DLOG_WARN, LOG_TAG, format, ##arg)
+#define SECURE_ALOGE(format, arg...) SECURE_LOG_(LOG_ID_APPS, DLOG_ERROR, LOG_TAG, format, ##arg)
 /**
- * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
+ * If you want use redefined macro.
+ * You can use this macro.
+ * This macro need priority and tag arguments.
  */
-#ifndef LOGW_IF
-#define LOGW_IF(cond, format, arg...) \
-       (((CONDITION(cond)) && (LOG_ON())) ? \
-         (LOG(LOG_WARN, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
+#define SECURE_LOG(priority, tag, format, arg...) SECURE_LOG_(LOG_ID_MAIN, D##priority, tag, format, ##arg)
+#define SECURE_SLOG(priority, tag, format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, D##priority, tag, format, ##arg)
+#define SECURE_RLOG(priority, tag, format, arg...) SECURE_LOG_(LOG_ID_RADIO, D##priority, tag, format, ##arg)
+#define SECURE_ALOG(priority, tag, format, arg...) SECURE_LOG_(LOG_ID_APPS, D##priority, tag, format, ##arg)
 
+#define SECLOG(format, arg...) do { } while (0)
 /**
- * Simplified macro to send an error log message using the current LOG_TAG.
+ * For Application and etc.
+ * Simplified macro to send a main log message using the current LOG_TAG.
+ * Example:
+ *  LOGD("app debug %d", num);
+ *  LOGE("app error %d", num);
  */
-#ifndef LOGE
-#define LOGE(format, arg...) \
-       (LOG_ON() ? (LOG(LOG_ERROR, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
+#define LOGD(format, arg...) LOG_(LOG_ID_MAIN, DLOG_DEBUG, LOG_TAG, format, ##arg)
+#define LOGI(format, arg...) LOG_(LOG_ID_MAIN, DLOG_INFO, LOG_TAG, format, ##arg)
+#define LOGW(format, arg...) LOG_(LOG_ID_MAIN, DLOG_WARN, LOG_TAG, format, ##arg)
+#define LOGE(format, arg...) LOG_(LOG_ID_MAIN, DLOG_ERROR, LOG_TAG, format, ##arg)
 /**
- * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
+ * For Framework and system etc.
+ * Simplified macro to send a system log message using the current LOG_TAG.
+ * Example:
+ *  SLOGD("system debug %d", num);
+ *  SLOGE("system error %d", num);
  */
-#ifndef LOGE_IF
-#define LOGE_IF(cond, format, arg...) \
-       (((CONDITION(cond)) && (LOG_ON())) ? \
-         (LOG(LOG_ERROR, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
+#define SLOGD(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_DEBUG, LOG_TAG, format, ##arg)
+#define SLOGI(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_INFO, LOG_TAG, format, ##arg)
+#define SLOGW(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_WARN, LOG_TAG, format, ##arg)
+#define SLOGE(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_ERROR, LOG_TAG, format, ##arg)
 /**
- * Simplified macro to send an error log message using the current LOG_TAG.
+ * For Modem and radio etc.
+ * Simplified macro to send a radio log message using the current LOG_TAG.
+ * Example:
+ *  RLOGD("radio debug %d", num);
+ *  RLOGE("radio error %d", num);
  */
-#ifndef LOGF
-#define LOGF(format, arg...) \
-       (LOG_ON() ? (LOG(LOG_FATAL, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
+#define RLOGD(format, arg...) LOG_(LOG_ID_RADIO, DLOG_DEBUG, LOG_TAG, format, ##arg)
+#define RLOGI(format, arg...) LOG_(LOG_ID_RADIO, DLOG_INFO, LOG_TAG, format, ##arg)
+#define RLOGW(format, arg...) LOG_(LOG_ID_RADIO, DLOG_WARN, LOG_TAG, format, ##arg)
+#define RLOGE(format, arg...) LOG_(LOG_ID_RADIO, DLOG_ERROR, LOG_TAG, format, ##arg)
 /**
- * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
+ * For Tizen OSP Application macro.
  */
-#ifndef LOGF_IF
-#define LOGF_IF(cond, format, arg...) \
-       (((CONDITION(cond)) && (LOG_ON())) ? \
-         (LOG(LOG_FATAL, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
+#define ALOGD(format, arg...) LOG_(LOG_ID_APPS, DLOG_DEBUG, LOG_TAG, format, ##arg)
+#define ALOGI(format, arg...) LOG_(LOG_ID_APPS, DLOG_INFO, LOG_TAG, format, ##arg)
+#define ALOGW(format, arg...) LOG_(LOG_ID_APPS, DLOG_WARN, LOG_TAG, format, ##arg)
+#define ALOGE(format, arg...) LOG_(LOG_ID_APPS, DLOG_ERROR, LOG_TAG, format, ##arg)
 
-// ---------------------------------------------------------------------
-/**
- * Simplified radio macro to send a verbose log message using the current LOG_TAG.
- */
-#ifndef RLOGV
-#if LOG_NDEBUG
-#define RLOGV(...)   (0)
-#else
-#define RLOGV(format, arg...) \
-       (LOG_ON() ? (RLOG(LOG_VERBOSE, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
-#endif
 /**
- * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
+ * Conditional Macro.
+ * Don't use this macro. It's just compatibility.
  */
-#ifndef RLOGV_IF
-#if LOG_NDEBUG
-#define RLOGV_IF(cond, format, arg...)   (0)
-#else
-#define RLOGV_IF(cond, format, arg...) \
-       (((CONDITION(cond)) && (LOG_ON())) ? \
-         (RLOG(LOG_VERBOSE, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
-#endif
-
-/**
- * Simplified radio macro to send a debug log message using the current LOG_TAG.
- */
-#ifndef RLOGD
-#define RLOGD(format, arg...) \
-       (LOG_ON() ? (RLOG(LOG_DEBUG, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
-/**
- * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
- */
-#ifndef RLOGD_IF
+#define LOGD_IF(cond, format, arg...) \
+    ((CONDITION(cond)) ? (LOGD(format, ##arg)) : (0))
+#define LOGI_IF(cond, format, arg...) \
+    ((CONDITION(cond)) ? (LOGI(format, ##arg)) : (0))
+#define LOGW_IF(cond, format, arg...) \
+    ((CONDITION(cond)) ? (LOGW(format, ##arg)) : (0))
+#define LOGE_IF(cond, format, arg...) \
+    ((CONDITION(cond)) ? (LOGE(format, ##arg)) : (0))
+#define SLOGD_IF(cond, format, arg...) \
+    ((CONDITION(cond)) ? (SLOGD(format, ##arg)) : (0))
+#define SLOGI_IF(cond, format, arg...) \
+    ((CONDITION(cond)) ? (SLOGI(format, ##arg)) : (0))
+#define SLOGW_IF(cond, format, arg...) \
+    ((CONDITION(cond)) ? (SLOGW(format, ##arg)) : (0))
+#define SLOGE_IF(cond, format, arg...) \
+    ((CONDITION(cond)) ? (SLOGE(format, ##arg)) : (0))
 #define RLOGD_IF(cond, format, arg...) \
-       (((CONDITION(cond)) && (LOG_ON())) ? \
-         (RLOG(LOG_DEBUG, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
-
-/**
- * Simplified radio macro to send an info log message using the current LOG_TAG.
- */
-#ifndef RLOGI
-#define RLOGI(format, arg...) \
-       (LOG_ON() ? (RLOG(LOG_INFO, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
-/**
- * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
- */
-#ifndef RLOGI_IF
+    ((CONDITION(cond)) ? (RLOGD(format, ##arg)) : (0))
 #define RLOGI_IF(cond, format, arg...) \
-       (((CONDITION(cond)) && (LOG_ON())) ? \
-         (RLOG(LOG_INFO, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
-
-/**
- * Simplified radio macro to send a warning log message using the current LOG_TAG.
- */
-#ifndef RLOGW
-#define RLOGW(format, arg...) \
-       (LOG_ON() ? (RLOG(LOG_WARN, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
-/**
- * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
- */
-#ifndef RLOGW_IF
+    ((CONDITION(cond)) ? (RLOGI(format, ##arg)) : (0))
 #define RLOGW_IF(cond, format, arg...) \
-       (((CONDITION(cond)) && (LOG_ON())) ? \
-         (RLOG(LOG_WARN, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
-
-/**
- * Simplified radio macro to send an error log message using the current LOG_TAG.
- */
-#ifndef RLOGE
-#define RLOGE(format, arg...) \
-       (LOG_ON() ? (RLOG(LOG_ERROR, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
-/**
- * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
- */
-#ifndef RLOGE_IF
+    ((CONDITION(cond)) ? (RLOGW(format, ##arg)) : (0))
 #define RLOGE_IF(cond, format, arg...) \
-       (((CONDITION(cond)) && (LOG_ON())) ? \
-         (RLOG(LOG_ERROR, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
-/**
- * Simplified radio macro to send an error log message using the current LOG_TAG.
- */
-#ifndef RLOGF
-#define RLOGF(format, arg...) \
-       (LOG_ON() ? (RLOG(LOG_FATAL, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
+    ((CONDITION(cond)) ? (RLOGE(format, ##arg)) : (0))
+
 /**
- * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
+ * Basic log message macro that allows you to specify a priority and a tag
+ * if you want to use this macro directly, you must add this messages for unity of messages.
+ * (LOG(prio, tag, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg))
+ *
+ * Example:
+ *  #define MYMACRO(prio, tag, format, arg...) \
+ *          LOG(prio, tag, format, ##arg)
+ *
+ *  MYMACRO(LOG_DEBUG, MYTAG, "test mymacro %d", num);
+ *
  */
-#ifndef RLOGF_IF
-#define RLOGF_IF(cond, format, arg...) \
-       (((CONDITION(cond)) && (LOG_ON())) ? \
-         (RLOG(LOG_FATAL, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
+#ifndef LOG
+#define LOG(priority, tag, format, arg...) LOG_(LOG_ID_MAIN, D##priority, tag, format, ##arg)
 #endif
+#define SLOG(priority, tag, format, arg...) LOG_(LOG_ID_SYSTEM, D##priority, tag, format, ##arg)
+#define RLOG(priority, tag, format, arg...) LOG_(LOG_ID_RADIO, D##priority, tag, format, ##arg)
+#define ALOG(priority, tag, format, arg...) LOG_(LOG_ID_APPS, D##priority, tag, format, ##arg)
 
 
 // ---------------------------------------------------------------------
-/**
- * Simplified system macro to send a verbose log message using the current LOG_TAG.
- */
-#ifndef SLOGV
+// Don't use below macro no more!! It will be removed -- Verbose and Fatal priority macro will be removed --
+#define COMPATIBILITY_ON
+
+#ifdef COMPATIBILITY_ON
+#define LOG_ON() _get_logging_on()
 #if LOG_NDEBUG
-#define SLOGV(...)   (0)
+#define LOGV(format, arg...) (0)
 #else
-#define SLOGV(format, arg...) \
-       (LOG_ON() ? (SLOG(LOG_VERBOSE, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
+#define LOGV(format, arg...) LOG_(LOG_ID_MAIN, DLOG_DEBUG, LOG_TAG, format, ##arg)
 #endif
-#endif
-/**
- * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
- */
-#ifndef SLOGV_IF
+#define LOGF(format, arg...) LOG_(LOG_ID_MAIN, DLOG_ERROR, LOG_TAG, format, ##arg)
 #if LOG_NDEBUG
-#define SLOGV_IF(cond, format, arg...)   (0)
+#define SLOGV(format, arg...) (0)
 #else
-#define SLOGV_IF(cond, format, arg...) \
-       (((CONDITION(cond)) && (LOG_ON())) ? \
-         (SLOG(LOG_VERBOSE, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
-#endif
-
-/**
- * Simplified system macro to send a debug log message using the current LOG_TAG.
- */
-#ifndef SLOGD
-#define SLOGD(format, arg...) \
-       (LOG_ON() ? (SLOG(LOG_DEBUG, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
-/**
- * Simplified system macro to send a conditional verbose log message using the current LOG_TAG.
- */
-#ifndef SLOGD_IF
-#define SLOGD_IF(cond, format, arg...) \
-       (((CONDITION(cond)) && (LOG_ON())) ? \
-         (SLOG(LOG_DEBUG, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
-
-/**
- * Simplified system macro to send an info log message using the current LOG_TAG.
- */
-#ifndef SLOGI
-#define SLOGI(format, arg...) \
-       (LOG_ON() ? (SLOG(LOG_INFO, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
-/**
- * Simplified system macro to send a conditional verbose log message using the current LOG_TAG.
- */
-#ifndef SLOGI_IF
-#define SLOGI_IF(cond, format, arg...) \
-       (((CONDITION(cond)) && (LOG_ON())) ? \
-         (SLOG(LOG_INFO, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
-
-/**
- * Simplified system macro to send a warning log message using the current LOG_TAG.
- */
-#ifndef SLOGW
-#define SLOGW(format, arg...) \
-       (LOG_ON() ? (SLOG(LOG_WARN, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
-/**
- * Simplified system macro to send a conditional verbose log message using the current LOG_TAG.
- */
-#ifndef SLOGW_IF
-#define SLOGW_IF(cond, format, arg...) \
-       (((CONDITION(cond)) && (LOG_ON())) ? \
-         (SLOG(LOG_WARN, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
-
-/**
- * Simplified system macro to send an error log message using the current LOG_TAG.
- */
-#ifndef SLOGE
-#define SLOGE(format, arg...) \
-       (LOG_ON() ? (SLOG(LOG_ERROR, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
-/**
- * Simplified system macro to send a conditional verbose log message using the current LOG_TAG.
- */
-#ifndef SLOGE_IF
-#define SLOGE_IF(cond, format, arg...) \
-       (((CONDITION(cond)) && (LOG_ON())) ? \
-         (SLOG(LOG_ERROR, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
-/**
- * Simplified system macro to send an error log message using the current LOG_TAG.
- */
-#ifndef SLOGF
-#define SLOGF(format, arg...) \
-       (LOG_ON() ? (SLOG(LOG_FATAL, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
+#define SLOGV(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_DEBUG, LOG_TAG, format, ##arg)
 #endif
-/**
- * Simplified system macro to send a conditional verbose log message using the current LOG_TAG.
- */
-#ifndef SLOGF_IF
-#define SLOGF_IF(cond, format, arg...) \
-       (((CONDITION(cond)) && (LOG_ON())) ? \
-         (SLOG(LOG_FATAL, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
-#endif
-
-// ---------------------------------------------------------------------
-
-/**
- * Simplified macro to send a verbose log message using the current LOG_TAG.
- */
-#ifndef ALOGV
+#define SLOGF(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_ERROR, LOG_TAG, format, ##arg)
 #if LOG_NDEBUG
-#define ALOGV(...)   (0)
+#define RLOGV(format, arg...) (0)
 #else
-#define ALOGV(...) (ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
-#endif
-#endif
-/**
- * Simplified macro to send a debug log message using the current LOG_TAG.
- */
-#ifndef ALOGD
-#define ALOGD(...) (ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
-#endif
-/**
- * Simplified macro to send an info log message using the current LOG_TAG.
- */
-#ifndef ALOGI
-#define ALOGI(...) (ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
-#endif
-/**
- * Simplified macro to send a warning log message using the current LOG_TAG.
- */
-#ifndef ALOGW
-#define ALOGW(...) (ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
+#define RLOGV(format, arg...) LOG_(LOG_ID_RADIO, DLOG_DEBUG, LOG_TAG, format, ##arg)
 #endif
-/**
- * Simplified macro to send an error log message using the current LOG_TAG.
- */
-#ifndef ALOGE
-#define ALOGE(...) (ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
-#endif
-
-
-// ---------------------------------------------------------------------
-/**
- * Basic log message macro that allows you to specify a priority and a tag
- *
- * Example:
- *  LOG(DLOG_WARN, NULL, "Failed with error %d", errno);
- *
- * The second argument may be NULL or "" to indicate the "global" tag.
- * 
- * Future work : we want to put filename and line number automatically only when debug build mode 
- */
-#ifndef LOG
-#define LOG(priority, tag, ...) \
-       print_log(D##priority, tag, __VA_ARGS__)
+#define RLOGF(format, arg...) LOG_(LOG_ID_RADIO, DLOG_ERROR, LOG_TAG, format, ##arg)
+#if LOG_NDEBUG
+#define ALOGV(format, arg...) (0)
+#else
+#define ALOGV(format, arg...) LOG_(LOG_ID_APPS, DLOG_DEBUG, LOG_TAG, format, ##arg)
 #endif
-
-/**
- * Log macro that allows you to pass in a varargs ("args" is a va_list).
- */
-#ifndef LOG_VA
+#define ALOGF(format, arg...) LOG_(LOG_ID_APPS, DLOG_ERROR, LOG_TAG, format, ##arg)
+#define LOGV_IF(cond, format, arg...) \
+    ((CONDITION(cond)) ? (LOGD(format, ##arg)) : (0))
+#define LOGF_IF(cond, format, arg...) \
+    ((CONDITION(cond)) ? (LOGE(format, ##arg)) : (0))
+#define SLOGV_IF(cond, format, arg...) \
+    ((CONDITION(cond)) ? (SLOGD(format, ##arg)) : (0))
+#define SLOGF_IF(cond, format, arg...) \
+    ((CONDITION(cond)) ? (SLOGE(format, ##arg)) : (0))
+#define RLOGV_IF(cond, format, arg...) \
+    ((CONDITION(cond)) ? (RLOGD(format, ##arg)) : (0))
+#define RLOGF_IF(cond, format, arg...) \
+    ((CONDITION(cond)) ? (RLOGE(format, ##arg)) : (0))
 #define LOG_VA(priority, tag, fmt, args) \
     vprint_log(D##priority, tag, fmt, args)
-#endif
-
-#ifndef ALOG
-#define ALOG(priority, tag, ...) \
-       print_apps_log(D##priority, tag, __VA_ARGS__)
-#endif
-/**
- * Log macro that allows you to pass in a varargs ("args" is a va_list).
- */
-#ifndef ALOG_VA
 #define ALOG_VA(priority, tag, fmt, args) \
     vprint_apps_log(D##priority, tag, fmt, args)
-#endif
-
-/**
- * Basic radio log macro that allows you to specify a priority and a tag.
- */
-#ifndef RLOG
-#define RLOG(priority, tag, ...) \
-       print_radio_log(D##priority, tag, __VA_ARGS__)
-#endif
-/**
- * Radio log macro that allows you to pass in a varargs ("args" is a va_list).
- */
-#ifndef RLOG_VA
 #define RLOG_VA(priority, tag, fmt, args) \
     vprint_radio_log(D##priority, tag, fmt, args)
-#endif
-
-/**
- * Basic system log macro that allows you to specify a priority and a tag.
- */
-#ifndef SLOG
-#define SLOG(priority, tag, ...) \
-    print_system_log(D##priority, tag, __VA_ARGS__)
-#endif
-
-/**
- * System log macro that allows you to pass in a varargs ("args" is a va_list).
- */
-#ifndef SLOG_VA
 #define SLOG_VA(priority, tag, fmt, args) \
     vprint_system_log(D##priority, tag, fmt, args)
-#endif
-
-
-/*
- * ===========================================================================
- *
- * The stuff in the rest of this file should not be used directly.
- */
-
 #define print_apps_log(prio, tag, fmt...) \
        __dlog_print(LOG_ID_APPS, prio, tag, fmt)
-
 #define vprint_apps_log(prio, tag, fmt...) \
        __dlog_vprint(LOG_ID_APPS, prio, tag, fmt)
-
 #define print_log(prio, tag, fmt...) \
        __dlog_print(LOG_ID_MAIN, prio, tag, fmt)
-
 #define vprint_log(prio, tag, fmt...) \
        __dlog_vprint(LOG_ID_MAIN, prio, tag, fmt)
-
 #define print_radio_log(prio, tag, fmt...)\
        __dlog_print(LOG_ID_RADIO, prio, tag, fmt)
-
 #define vprint_radio_log(prio, tag, fmt...) \
        __dlog_vprint(LOG_ID_RADIO, prio, tag, fmt)
-
 #define print_system_log(prio, tag, fmt...)\
        __dlog_print(LOG_ID_SYSTEM, prio, tag, fmt)
-
 #define vprint_system_log(prio, tag, fmt...) \
        __dlog_vprint(LOG_ID_SYSTEM, prio, tag, fmt)
-
+#endif
+// Don't use above macro no more!! It will be removed -Verbose, Warning and Fatal priority macro.
+// ---------------------------------------------------------------------
+/*
+ * The stuff in the rest of this file should not be used directly.
+ */
 /**
  * @brief              send log. must specify log_id ,priority, tag and format string.
  * @pre                none
@@ -600,14 +370,9 @@ int __dlog_print(log_id_t log_id, int prio, const char *tag, const char *fmt, ..
   */
 int __dlog_vprint(log_id_t log_id, int prio, const char *tag, const char *fmt, va_list ap);
 int _get_logging_on(void);
-
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
-
-
 /** @} */
 /** @} */
-
 #endif /* _DLOG_H_*/
-
diff --git a/log.c b/log.c
index 314a42b..ef91176 100755 (executable)
--- a/log.c
+++ b/log.c
@@ -1,4 +1,4 @@
-/*
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: t -*-
  * DLOG
  * Copyright (c) 2005-2008, The Android Open Source Project
  * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
@@ -15,6 +15,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include "config.h"
 #include <pthread.h>
 #include <stdlib.h>
 #include <string.h>
@@ -24,7 +25,8 @@
 #include <stdio.h>
 #include <errno.h>
 #include <dlog.h>
-#ifdef SD_JOURNAL_SUPPORT
+#ifdef HAVE_SYSTEMD_JOURNAL
+#define SD_JOURNAL_SUPPRESS_LOCATION 1
 #include <syslog.h>
 #include <systemd/sd-journal.h>
 #endif
 #define LOG_SYSTEM     "log_system"
 #define LOG_APPS       "log_apps"
 
-static int log_fds[(int)LOG_ID_MAX] = { -1, -1, -1, -1 };
-
-static int g_logging_on = 1;
-static int g_dlog_level_init = 0;
-static int g_dlog_level = DLOG_SILENT;
+#define VALUE_MAX 2
+#define PLATFORMLOG_CONF "/tmp/.platformlog.conf"
+#define PLATFORMLOG_ORG_CONF "/opt/etc/platformlog.conf"
 
-static int __dlog_init(log_id_t, log_priority, const char *tag, const char *msg);
-static int (*write_to_log)(log_id_t, log_priority, const char *tag, const char *msg) = __dlog_init;
+static int platformlog = 0;
+static int log_fds[(int)LOG_ID_MAX] = { -1, -1, -1, -1 };
+static int (*write_to_log)(log_id_t, log_priority, const char *tag, const char *msg) = NULL;
 static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER;
+
 static int __write_to_log_null(log_id_t log_id, log_priority prio, const char *tag, const char *msg)
 {
        return -1;
@@ -76,127 +78,141 @@ static int __write_to_log_kernel(log_id_t log_id, log_priority prio, const char
 
        return ret;
 }
+
 static char dlog_pri_to_char (log_priority pri)
 {
-       switch (pri) {
-               case DLOG_VERBOSE:       return 'V';
-               case DLOG_DEBUG:         return 'D';
-               case DLOG_INFO:          return 'I';
-               case DLOG_WARN:          return 'W';
-               case DLOG_ERROR:         return 'E';
-               case DLOG_FATAL:         return 'F';
-               case DLOG_SILENT:        return 'S';
-
-               case DLOG_DEFAULT:
-               case DLOG_UNKNOWN:
-               default:
-                                                                return '?';
-       }
+       static const char pri_table[DLOG_PRIO_MAX] = {
+               [DLOG_VERBOSE] = 'V',
+               [DLOG_DEBUG] = 'D',
+               [DLOG_INFO] = 'I',
+               [DLOG_WARN] = 'W',
+               [DLOG_ERROR] = 'E',
+               [DLOG_FATAL] = 'F',
+               [DLOG_SILENT] = 'S',
+       };
+
+       if (pri < 0 || DLOG_PRIO_MAX <= pri || !pri_table[pri])
+               return '?';
+       return pri_table[pri];
 }
-#ifdef SD_JOURNAL_SUPPORT
-static int dlog_pri_to_journal_pri(log_priority prio)
+
+#ifdef HAVE_SYSTEMD_JOURNAL
+static inline int dlog_pri_to_journal_pri(log_priority prio)
 {
-       int journal_prio = LOG_DEBUG;
-
-       switch(prio) {
-       case DLOG_UNKNOWN:
-       case DLOG_DEFAULT:
-       case DLOG_VERBOSE:
-               journal_prio = LOG_DEBUG;
-               break;
-       case DLOG_DEBUG:
-               journal_prio = LOG_DEBUG;
-               break;
-       case DLOG_INFO:
-               journal_prio = LOG_INFO;
-               break;
-       case DLOG_WARN:
-               journal_prio = LOG_WARNING;
-               break;
-       case DLOG_ERROR:
-               journal_prio = LOG_ERR;
-               break;
-       case DLOG_FATAL:
-               journal_prio = LOG_CRIT;
-               break;
-       case DLOG_SILENT:
-       default:
-               journal_prio = -1;
-               break;
-       }
-       return journal_prio;
+       static int pri_table[DLOG_PRIO_MAX] = {
+               [DLOG_UNKNOWN] = LOG_DEBUG,
+               [DLOG_DEFAULT] = LOG_DEBUG,
+               [DLOG_VERBOSE] = LOG_DEBUG,
+               [DLOG_DEBUG] = LOG_DEBUG,
+               [DLOG_INFO] = LOG_INFO,
+               [DLOG_WARN] = LOG_WARNING,
+               [DLOG_ERROR] = LOG_ERR,
+               [DLOG_FATAL] = LOG_CRIT,
+               [DLOG_SILENT] = -1,
+       };
+
+       if (prio < 0 || prio >= DLOG_PRIO_MAX)
+               return -EINVAL;
+
+       return pri_table[prio];
 }
-static int __write_to_log_sd_journal_print(log_id_t log_id, log_priority prio, const char *tag, const char *msg)
+
+static inline const char* dlog_id_to_string(log_id_t log_id)
 {
-       return sd_journal_print(dlog_pri_to_journal_pri(prio), "%c %s: %s", dlog_pri_to_char(prio), tag, msg);
+       static const char* id_table[LOG_ID_MAX] = {
+               [LOG_ID_MAIN]   = LOG_MAIN,
+               [LOG_ID_RADIO]  = LOG_RADIO,
+               [LOG_ID_SYSTEM] = LOG_SYSTEM,
+               [LOG_ID_APPS]   = LOG_APPS,
+       };
+
+       if (log_id < 0 || log_id >= LOG_ID_MAX || !id_table[log_id])
+               return "UNKNOWN";
+
+       return id_table[log_id];
+}
+
+static int __write_to_log_sd_journal(log_id_t log_id, log_priority prio, const char *tag, const char *msg)
+{
+       /* XXX: sd_journal_sendv() with manually filed iov-s might be faster */
+       return sd_journal_send("MESSAGE=%s", msg,
+                              "PRIORITY=%i", dlog_pri_to_journal_pri(prio),
+                              "DLOG_PRIORITY=%d", prio,
+                              "DLOG_TAG=%s", tag,
+                              "DLOG_ID=%s", dlog_id_to_string(log_id),
+                              NULL);
 }
 #endif
-void init_dlog_level(void)
+
+static int __read_config(char *file, int *value)
 {
-       char *dlog_level_env;
-       char *logging_mode_env;
-       if (g_logging_on) {
-               logging_mode_env = getenv("TIZEN_PLATFORMLOGGING_MODE");
-               if (!logging_mode_env)
-                               g_logging_on = 0;
-                       else
-                               g_logging_on = atoi(logging_mode_env);
+       int fd, ret;
+       char val[VALUE_MAX];
+
+       if (file == NULL || value == NULL)
+               return 0;
+       memset(val, 0, sizeof(val));
+       fd = open(file, O_RDONLY);
+       if (fd < 0) {
+               return 0;
        }
-       if (g_logging_on) {
-               dlog_level_env = getenv("TIZEN_DLOG_LEVEL");
-               if (!dlog_level_env) {
-                       g_dlog_level = 8;
-               } else {
-                       g_dlog_level = atoi(dlog_level_env);
-               }
-       } else
-               g_dlog_level = 8;
-       g_dlog_level_init = 1;
+       ret = read(fd, val, 1);
+       close(fd);
+       if (ret != 1)
+               return 0;
+       *value = atoi(val);
+       return 1;
 }
-static int __dlog_init(log_id_t log_id, log_priority prio, const char *tag, const char *msg)
+
+static void __configure(void)
+{
+       int ret;
+       ret = __read_config(PLATFORMLOG_CONF, &platformlog);
+       if (!ret)
+               ret = __read_config(PLATFORMLOG_ORG_CONF, &platformlog);
+       if (!ret)
+               platformlog = 0;
+}
+
+static void __dlog_init(void)
 {
        pthread_mutex_lock(&log_init_lock);
-       // get filtering info
-       // open device
-       if (write_to_log == __dlog_init) {
-
-               log_fds[LOG_ID_MAIN] = open("/dev/"LOG_MAIN, O_WRONLY);
-               log_fds[LOG_ID_RADIO] = open("/dev/"LOG_RADIO, O_WRONLY);
-               log_fds[LOG_ID_SYSTEM] = open("/dev/"LOG_SYSTEM, O_WRONLY);
-               log_fds[LOG_ID_APPS] = open("/dev/"LOG_APPS, O_WRONLY);
-
-               if (log_fds[LOG_ID_MAIN] < 0 || log_fds[LOG_ID_RADIO] < 0) {
-                       write_to_log = __write_to_log_null;
-               } else {
-#ifdef SD_JOURNAL_SUPPORT
-                       write_to_log = __write_to_log_sd_journal_print;
+       /* configuration */
+       __configure();
+       /* open device */
+       log_fds[LOG_ID_MAIN] = open("/dev/"LOG_MAIN, O_WRONLY);
+       log_fds[LOG_ID_RADIO] = open("/dev/"LOG_RADIO, O_WRONLY);
+       log_fds[LOG_ID_SYSTEM] = open("/dev/"LOG_SYSTEM, O_WRONLY);
+       log_fds[LOG_ID_APPS] = open("/dev/"LOG_APPS, O_WRONLY);
+       if (log_fds[LOG_ID_MAIN] < 0 || log_fds[LOG_ID_RADIO] < 0) {
+               write_to_log = __write_to_log_null;
+       } else {
+#ifdef HAVE_SYSTEMD_JOURNAL
+               write_to_log = __write_to_log_sd_journal;
 #else
-                       write_to_log = __write_to_log_kernel;
+               write_to_log = __write_to_log_kernel;
 #endif
-               }
-
-               if (log_fds[LOG_ID_SYSTEM] < 0)
-                       log_fds[LOG_ID_SYSTEM] = log_fds[LOG_ID_MAIN];
-               if (log_fds[LOG_ID_APPS] < 0)
-                       log_fds[LOG_ID_APPS] = log_fds[LOG_ID_MAIN];
        }
+
+       if (log_fds[LOG_ID_SYSTEM] < 0)
+               log_fds[LOG_ID_SYSTEM] = log_fds[LOG_ID_MAIN];
+       if (log_fds[LOG_ID_APPS] < 0)
+               log_fds[LOG_ID_APPS] = log_fds[LOG_ID_MAIN];
        pthread_mutex_unlock(&log_init_lock);
-       return write_to_log(log_id, prio, tag, msg);
 }
 
 int __dlog_vprint(log_id_t log_id, int prio, const char *tag, const char *fmt, va_list ap)
 {
        char buf[LOG_BUF_SIZE];
-       if (!g_dlog_level_init) {
-               init_dlog_level();
-       }
-       if (log_id < LOG_ID_APPS) {
-               if(prio < g_dlog_level) {
-                       return 0;
-               }
-       } else if (LOG_ID_MAX <= log_id) {
+
+       if (LOG_ID_MAX <= log_id)
+               return 0;
+
+       if (write_to_log == NULL)
+               __dlog_init();
+
+       if (log_id != LOG_ID_APPS && !platformlog)
                return 0;
-       }
 
        vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
 
@@ -208,16 +224,14 @@ int __dlog_print(log_id_t log_id, int prio, const char *tag, const char *fmt, ..
        va_list ap;
        char buf[LOG_BUF_SIZE];
 
-       if (!g_dlog_level_init) {
-               init_dlog_level();
-       }
-       if (log_id < LOG_ID_APPS) {
-               if(prio < g_dlog_level) {
-                       return 0;
-               }
-       } else if (LOG_ID_MAX <= log_id) {
+       if (LOG_ID_MAX <= log_id)
+               return 0;
+
+       if (write_to_log == NULL)
+               __dlog_init();
+
+       if (log_id != LOG_ID_APPS && !platformlog)
                return 0;
-       }
 
        va_start(ap, fmt);
        vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
@@ -225,7 +239,8 @@ int __dlog_print(log_id_t log_id, int prio, const char *tag, const char *fmt, ..
 
        return write_to_log(log_id, prio, tag, buf);
 }
+
 int _get_logging_on(void)
 {
-       return g_logging_on;
+       return 1;
 }
index 03a5276..1c1355d 100755 (executable)
--- a/logutil.c
+++ b/logutil.c
@@ -288,13 +288,15 @@ static void read_log_lines(struct log_device_t* devices)
                         free(entry);
                         fprintf(stderr, "read: Unexpected EOF!\n");
                         exit(EXIT_FAILURE);
-                    }
-                    else if (entry->entry.len != ret - sizeof(struct logger_entry)) {
+                                       }
+                                       else if (entry->entry.len != ret - sizeof(struct logger_entry)) {
                         free(entry);
-                        fprintf(stderr, "read: unexpected length. Expected %d, got %d\n",
-                                entry->entry.len, ret - sizeof(struct logger_entry));
-                        exit(EXIT_FAILURE);
-                    }
+                                               fprintf(stderr, "read: unexpected length. Expected %d, got %d\n",
+                                                               entry->entry.len, ret - sizeof(struct logger_entry));
+                                               exit(EXIT_FAILURE);
+                                       }
+
+
                     entry->entry.msg[entry->entry.len] = '\0';
 
                     enqueue(dev, entry);
index 4930e4d..0cd3ef9 100755 (executable)
@@ -1,16 +1,14 @@
 Name:       dlog
 Summary:    Logging service
 Version:    0.4.1
-Release:    5
+Release:    15
 Group:      System/Libraries
 License:    Apache License, Version 2.0
 Source0:    %{name}-%{version}.tar.gz
-Source101:  dlog-main.service
-Source102:  dlog-radio.service
+Source101:  packaging/dlog-main.service
+Source102:  packaging/dlog-radio.service
 Source103:  packaging/dlogutil.manifest
 Source104:  packaging/libdlog.manifest
-Source105:  tizen-debug-level.service
-
 BuildRequires: pkgconfig(libsystemd-journal)
 Requires(post): /usr/bin/vconftool
 Requires(post): coreutils
@@ -45,15 +43,12 @@ Requires(preun): /usr/bin/systemctl
 %description -n dlogutil
 Utilities for print log data
 
-
-
 %prep
 %setup -q
 
-
 %build
 %autogen --disable-static
-%configure --disable-static
+%configure --disable-static --without-systemd-journal
 make %{?jobs:-j%jobs}
 
 %install
@@ -61,33 +56,26 @@ rm -rf %{buildroot}
 cp %{SOURCE103} .
 cp %{SOURCE104} .
 %make_install
-mkdir -p %{buildroot}/opt/etc/dlog
-cp %{_builddir}/%{name}-%{version}/.dloglevel %{buildroot}/opt/etc/dlog/.dloglevel
-mkdir -p %{buildroot}/etc/profile.d/
-cp %{_builddir}/%{name}-%{version}/tizen_platform_env.sh %{buildroot}/etc/profile.d/tizen_platform_env.sh
+mkdir -p %{buildroot}/opt/etc/dump.d/default.d
+cp %{_builddir}/%{name}-%{version}/dlog_dump.sh %{buildroot}/opt/etc/dump.d/default.d/dlog_dump.sh
 mkdir -p %{buildroot}/usr/bin/
 cp %{_builddir}/%{name}-%{version}/dlogctrl %{buildroot}/usr/bin/dlogctrl
 
 mkdir -p %{buildroot}/%{_sysconfdir}/rc.d/rc3.d
-rm -f %{buildroot}/%{_sysconfdir}/etc/rc.d/rc3.d/S05dlog
-ln -s ../init.d/dlog.sh %{buildroot}/%{_sysconfdir}/rc.d/rc3.d/S05dlog
+rm -f %{buildroot}/%{_sysconfdir}/etc/rc.d/rc3.d/S01dlog
+ln -s ../init.d/dlog.sh %{buildroot}/%{_sysconfdir}/rc.d/rc3.d/S01dlog
 
-mkdir -p %{buildroot}%{_libdir}/systemd/system/basic.target.wants
 mkdir -p %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants
 
 install -m 0644 %SOURCE101 %{buildroot}%{_libdir}/systemd/system/
 install -m 0644 %SOURCE102 %{buildroot}%{_libdir}/systemd/system/
-install -m 0644 %SOURCE105 %{buildroot}%{_libdir}/systemd/system/
 
 ln -s ../dlog-main.service %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants/dlog-main.service
 ln -s ../dlog-radio.service %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants/dlog-radio.service
-ln -s ../tizen-debug-level.service %{buildroot}%{_libdir}/systemd/system/basic.target.wants/tizen-debug-level.service
 
 mkdir -p %{buildroot}/usr/share/license
 cp LICENSE.APLv2 %{buildroot}/usr/share/license/%{name}
 
-mkdir -p %{buildroot}/opt/etc/dlog
-
 %preun -n dlogutil
 if [ $1 == 0 ]; then
     systemctl stop dlog-main.service
@@ -104,26 +92,32 @@ fi
 %postun -n dlogutil
 systemctl daemon-reload
 
-%post -n libdlog -p /sbin/ldconfig
-%postun -n libdlog -p /sbin/ldconfig
+%post -n libdlog
+/sbin/ldconfig
+echo 0 > /opt/etc/platformlog.conf
+chmod 660 /opt/etc/platformlog.conf
+chown root:app_logging /opt/etc/platformlog.conf
+if [ -f %{_libdir}/rpm-plugins/msm.so ]; then
+       chsmack -a '*' -e 'none' /opt/etc/platformlog.conf
+fi
+%postun -n libdlog
+/sbin/ldconfig
+rm /opt/etc/platformlog.conf
 
 %files  -n dlogutil
 %manifest dlogutil.manifest
 /usr/share/license/%{name}
 %doc LICENSE.APLv2
-%attr(755,root,root) /opt/etc/dlog/.dloglevel
-%attr(755,root,root) /etc/profile.d/tizen_platform_env.sh
+%attr(755,root,root) /opt/etc/dump.d/default.d/dlog_dump.sh
 %attr(755,root,app_logging) %{_bindir}/dlogutil
 %attr(755,root,app_logging) %{_bindir}/dlogctrl
 %{_sysconfdir}/rc.d/init.d/dlog.sh
-%{_sysconfdir}/rc.d/rc3.d/S05dlog
-%{_libdir}/systemd/system/tizen-debug-level.service
+%{_sysconfdir}/rc.d/rc3.d/S01dlog
 %{_libdir}/systemd/system/dlog-main.service
 %{_libdir}/systemd/system/dlog-radio.service
-%{_libdir}/systemd/system/basic.target.wants/tizen-debug-level.service
 %{_libdir}/systemd/system/multi-user.target.wants/dlog-main.service
 %{_libdir}/systemd/system/multi-user.target.wants/dlog-radio.service
-%attr(775,root,app_logging) %dir /opt/etc/dlog
+%attr(755,root,root) %dir /opt/etc/dump.d/default.d
 
 %files  -n libdlog
 %manifest libdlog.manifest
index bf95834..9c8a50e 100644 (file)
@@ -1,21 +1,18 @@
 <manifest>
        <define>
                <domain name="dlogutil"/>
-       <permit>
-               <smack permit="_" type="rx"/>
-       </permit>
        </define>
        <assign>
                <filesystem path="/usr/bin/dlogutil" label="_" exec_label="none"/>
                <filesystem path="/usr/bin/dlogctrl" label="_" exec_label="none"/>
                <filesystem path="/etc/rc.d/init.d/dlog.sh" label="_" exec_label="none"/>
-               <filesystem path="/etc/rc.d/rc3.d/S05dlog" label="_" exec_label="none"/>
-               <filesystem path="/usr/lib/systemd/system/basic.target.wants/tizen-debug-level.service" label="_" exec_label="none" />
+               <filesystem path="/etc/rc.d/rc3.d/S01dlog" label="_" exec_label="none"/>
+               <filesystem path="/opt/etc/dump.d/default.d" label="_" exec_label="none"/>
+               <filesystem path="/opt/etc/dump.d/default.d/dlog_dump.sh" label="_" exec_label="none"/>
                <filesystem path="/usr/lib/systemd/system/dlog-main.service" label="_" exec_label="none" />
                <filesystem path="/usr/lib/systemd/system/dlog-radio.service" label="_" exec_label="none" />
                <filesystem path="/usr/lib/systemd/system/multi-user.target.wants/dlog-main.service" label="_" exec_label="none" />
                <filesystem path="/usr/lib/systemd/system/multi-user.target.wants/dlog-radio.service" label="_" exec_label="none" />
-               <filesystem path="/usr/lib/systemd/system/tizen-debug-level.service" label="_" exec_label="none" />
        </assign>
        <request>
                <domain name="dlogutil"/>
diff --git a/packaging/tizen-debug-level.service b/packaging/tizen-debug-level.service
deleted file mode 100644 (file)
index 66b32b1..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-[Unit]
-Description=Set tizen debug level globally
-DefaultDependencies=no
-After=opt.mount
-Before=basic.target
-ConditionPathExists=/opt/etc/dlog/.platformloggingmode
-
-[Service]
-Type=oneshot
-ExecStart=/bin/sh -c '/usr/bin/systemctl set-environment TIZEN_PLATFORMLOGGING_MODE=1 TIZEN_DLOG_LEVEL=$(cat /opt/etc/dlog/.dloglevel)'
-
-[Install]
-WantedBy=basic.target
-
diff --git a/tizen_platform_env.sh b/tizen_platform_env.sh
deleted file mode 100755 (executable)
index 9bf35f1..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/sh
-
-if [ -e "/opt/etc/dlog/.platformloggingmode" ]; then
-       export TIZEN_PLATFORMLOGGING_MODE=1
-fi
-
-# I'm not clear why "-a" doesn't work here
-if [ "x$TIZEN_PLATFORMLOGGING_MODE" != "x" ] &&
-       [ "$TIZEN_PLATFORMLOGGING_MODE" -eq "1" ]; then
-       dlevel=$(cat /opt/etc/dlog/.dloglevel)
-       if [ "$dlevel" -eq "0" ]; then
-               export TIZEN_DLOG_LEVEL=0
-       elif [ "$dlevel" -eq "1" ]; then
-               export TIZEN_DLOG_LEVEL=1
-       elif [ "$dlevel" -eq "2" ]; then
-               export TIZEN_DLOG_LEVEL=2
-       elif [ "$dlevel" -eq "3" ]; then
-               export TIZEN_DLOG_LEVEL=3
-       elif [ "$dlevel" -eq "4" ]; then
-               export TIZEN_DLOG_LEVEL=4
-       elif [ "$dlevel" -eq "5" ]; then
-               export TIZEN_DLOG_LEVEL=5
-       elif [ "$dlevel" -eq "6" ]; then
-               export TIZEN_DLOG_LEVEL=6
-       elif [ "$dlevel" -eq "7" ]; then
-               export TIZEN_DLOG_LEVEL=7
-       elif [ "$dlevel" -eq "8" ]; then
-               export TIZEN_DLOG_LEVEL=8
-       else
-               export TIZEN_DLOG_LEVEL=8
-       fi
-fi