From e701e9e2f125242fc9af9e7fae12c9118e920a6a Mon Sep 17 00:00:00 2001 From: juho Date: Wed, 5 Dec 2012 18:12:03 +0900 Subject: [PATCH] change dlog output format and dlog platform logging ctrl Change-Id: I6f1d6f4d86ef5540e2df4487f45a04157f982d57 --- .debuglevel | 1 - .dloglevel | 1 + Makefile.am | 2 +- dlogctrl | 59 ++++++++ dlogutil.manifest | 22 +-- include/dlog.h | 411 +++++++++++++++++++------------------------------- log.c | 143 ++++++++++++------ logutil.c | 2 +- packaging/dlog.spec | 25 +-- tizen_platform_env.sh | 30 ++++ 10 files changed, 367 insertions(+), 329 deletions(-) delete mode 100755 .debuglevel create mode 100644 .dloglevel create mode 100755 dlogctrl create mode 100755 tizen_platform_env.sh diff --git a/.debuglevel b/.debuglevel deleted file mode 100755 index 6ec88ea..0000000 --- a/.debuglevel +++ /dev/null @@ -1 +0,0 @@ -export TIZEN_DEBUG_LEVEL=1 # diff --git a/.dloglevel b/.dloglevel new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/.dloglevel @@ -0,0 +1 @@ +1 diff --git a/Makefile.am b/Makefile.am index 65bd8b8..2e82e56 100755 --- a/Makefile.am +++ b/Makefile.am @@ -14,7 +14,7 @@ libdlog_la_SOURCES = \ log.c \ include/dlog.h -libdlog_la_LIBADD = -lpthread +libdlog_la_LIBADD = -lpthread -lsystemd-journal bin_PROGRAMS= dlogutil diff --git a/dlogctrl b/dlogctrl new file mode 100755 index 0000000..840bd45 --- /dev/null +++ b/dlogctrl @@ -0,0 +1,59 @@ +#!/bin/sh +MODE=none +OBJ=none +VAL=none +#echo "tizen_platform_logging_ctrl" +case "$1" in +get) + MODE=get +;; +set) + MODE=set +;; + +*) +echo "Usage: tplctrl {get|set} {platformlog} {1|0}" +exit 1 +esac + +case "$2" in +platformlog) + OBJ=platformlog +;; +*) + echo "Usage: tplctrl {get|set} {platformlog} {1|0}" +exit 1 +esac + +if [ "$MODE" = "set" ]; then + case "$3" in + 1) + VAL=1 + ;; + 0) + VAL=0 + ;; + *) + echo "Usage: tplctrl {get|set} {platformlog} {1|0}" + exit 1 + esac +fi + +if [ "$MODE" = "set" ]; then + if [ "$OBJ" = "platformlog" ] && [ "$VAL" = "1" ] ; then + touch /opt/etc/dlog/.platformloggingmode 2>/dev/null + elif [ "$OBJ" = "platformlog" ] && [ "$VAL" = "0" ] ; then + rm -f /opt/etc/dlog/.platformloggingmode 2>/dev/null + fi +else + if [ "$OBJ" = "platformlog" ]; then + if [ -e "/opt/etc/dlog/.platformloggingmode" ]; then + echo 1 + else + echo 0 + fi + fi + +fi + +exit 0 diff --git a/dlogutil.manifest b/dlogutil.manifest index 6eaf29b..2eecb07 100644 --- a/dlogutil.manifest +++ b/dlogutil.manifest @@ -1,11 +1,15 @@ - - - - - - - - - + + + + + + + + + + + + diff --git a/include/dlog.h b/include/dlog.h index 9a9f69e..b29c25f 100755 --- a/include/dlog.h +++ b/include/dlog.h @@ -13,15 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - - -/** +/** * @file dlog.h * @version 0.4 * @brief This file is the header file of interface of dlog. */ - - /** * @addtogroup APPLICATION_FRAMEWORK * @{ @@ -31,8 +27,6 @@ * @{ */ - - #ifndef _DLOG_H_ #define _DLOG_H_ @@ -62,6 +56,11 @@ 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. */ @@ -79,16 +78,15 @@ typedef enum { typedef enum { LOG_ID_MAIN = 0, - LOG_ID_RADIO, - LOG_ID_SYSTEM, - LOG_ID_APPS, - LOG_ID_MAX + LOG_ID_RADIO, + LOG_ID_SYSTEM, + LOG_ID_APPS, + LOG_ID_MAX } log_id_t; -#define CONDITION(cond) (__builtin_expect((cond)!=0, 0)) +#define CONDITION(cond) (__builtin_expect((cond) != 0, 0)) // --------------------------------------------------------------------- - /** * Simplified macro to send a verbose log message using the current LOG_TAG. */ @@ -96,11 +94,10 @@ typedef enum { #if LOG_NDEBUG #define LOGV(...) ((void)0) #else -#define LOGV(...) ((void)LOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) - +#define LOGV(format, arg...) \ + (LOG_ON() ? (LOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif #endif - /** * Simplified macro to send a conditional verbose log message using the current LOG_TAG. */ @@ -109,268 +106,296 @@ typedef enum { #define LOGV_IF(cond, ...) ((void)0) #else #define LOGV_IF(cond, ...) \ - ( (CONDITION(cond)) \ - ? ((void)LOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \ - : (void)0 ) + (((CONDITION(cond)) && (LOG_ON())) ? \ + (LOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif #endif - /** * Simplified macro to send a debug log message using the current LOG_TAG. */ #ifndef LOGD -#define LOGD(...) ((void)LOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) +#define LOGD(format, arg...) \ + (LOG_ON() ? (LOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif - /** - * Simplified macro to send a conditional debug log message using the current LOG_TAG. + * Simplified macro to send a conditional verbose log message using the current LOG_TAG. */ #ifndef LOGD_IF #define LOGD_IF(cond, ...) \ - ( (CONDITION(cond)) \ - ? ((void)LOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \ - : (void)0 ) + (((CONDITION(cond)) && (LOG_ON())) ? \ + (LOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif /** * Simplified macro to send an info log message using the current LOG_TAG. */ #ifndef LOGI -#define LOGI(...) ((void)LOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) +#define LOGI(format, arg...) \ + (LOG_ON() ? (LOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif - /** - * Simplified macro to send a conditional info log message using the current LOG_TAG. + * Simplified macro to send a conditional verbose log message using the current LOG_TAG. */ #ifndef LOGI_IF #define LOGI_IF(cond, ...) \ - ( (CONDITION(cond)) \ - ? ((void)LOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \ - : (void)0 ) + (((CONDITION(cond)) && (LOG_ON())) ? \ + (LOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif /** * Simplified macro to send a warning log message using the current LOG_TAG. */ #ifndef LOGW -#define LOGW(...) ((void)LOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) +#define LOGW(format, arg...) \ + (LOG_ON() ? (LOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif - /** - * Simplified macro to send a conditional warning log message using the current LOG_TAG. + * Simplified macro to send a conditional verbose log message using the current LOG_TAG. */ #ifndef LOGW_IF #define LOGW_IF(cond, ...) \ - ( (CONDITION(cond)) \ - ? ((void)LOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \ - : (void)0 ) + (((CONDITION(cond)) && (LOG_ON())) ? \ + (LOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif /** * Simplified macro to send an error log message using the current LOG_TAG. */ #ifndef LOGE -#define LOGE(...) ((void)LOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) +#define LOGE(format, arg...) \ + (LOG_ON() ? (LOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif - /** - * Simplified macro to send a conditional error log message using the current LOG_TAG. + * Simplified macro to send a conditional verbose log message using the current LOG_TAG. */ #ifndef LOGE_IF #define LOGE_IF(cond, ...) \ - ( (CONDITION(cond)) \ - ? ((void)LOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \ - : (void)0 ) + (((CONDITION(cond)) && (LOG_ON())) ? \ + (LOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) +#endif +/** + * Simplified macro to send an error log message using the current LOG_TAG. + */ +#ifndef LOGF +#define LOGF(format, arg...) \ + (LOG_ON() ? (LOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) +#endif +/** + * Simplified macro to send a conditional verbose log message using the current LOG_TAG. + */ +#ifndef LOGF_IF +#define LOGF_IF(cond, ...) \ + (((CONDITION(cond)) && (LOG_ON())) ? \ + (LOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif // --------------------------------------------------------------------- - /** - * Simplified macro to send a verbose radio log message using the current LOG_TAG. + * Simplified radio macro to send a verbose log message using the current LOG_TAG. */ #ifndef RLOGV #if LOG_NDEBUG #define RLOGV(...) ((void)0) #else -#define RLOGV(...) ((void)RLOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) +#define RLOGV(format, arg...) \ + (LOG_ON() ? (RLOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif #endif - /** - * Simplified macro to send a conditional verbose radio log message using the current LOG_TAG. - */ + * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG. + */ #ifndef RLOGV_IF #if LOG_NDEBUG #define RLOGV_IF(cond, ...) ((void)0) #else #define RLOGV_IF(cond, ...) \ - ( (CONDITION(cond)) \ - ? ((void)RLOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \ - : (void)0 ) + (((CONDITION(cond)) && (LOG_ON())) ? \ + (RLOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif #endif - + /** - * Simplified macro to send a debug radio log message using the current LOG_TAG. + * Simplified radio macro to send a debug log message using the current LOG_TAG. */ #ifndef RLOGD -#define RLOGD(...) ((void)RLOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) +#define RLOGD(format, arg...) \ + (LOG_ON() ? (RLOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif - /** - * Simplified macro to send a conditional debug radio log message using the current LOG_TAG. - */ + * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG. + */ #ifndef RLOGD_IF #define RLOGD_IF(cond, ...) \ - ( (CONDITION(cond)) \ - ? ((void)RLOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \ - : (void)0 ) + (((CONDITION(cond)) && (LOG_ON())) ? \ + (RLOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif - + /** - * Simplified macro to send an info radio log message using the current LOG_TAG. + * Simplified radio macro to send an info log message using the current LOG_TAG. */ #ifndef RLOGI -#define RLOGI(...) ((void)RLOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) +#define RLOGI(format, arg...) \ + (LOG_ON() ? (RLOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif - /** - * Simplified macro to send a conditional info radio log message using the current LOG_TAG. + * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG. */ #ifndef RLOGI_IF #define RLOGI_IF(cond, ...) \ - ( (CONDITION(cond)) \ - ? ((void)RLOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \ - : (void)0 ) + (((CONDITION(cond)) && (LOG_ON())) ? \ + (RLOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif - + /** - * Simplified macro to send a warning radio log message using the current LOG_TAG. + * Simplified radio macro to send a warning log message using the current LOG_TAG. */ #ifndef RLOGW -#define RLOGW(...) ((void)RLOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) +#define RLOGW(format, arg...) \ + (LOG_ON() ? (RLOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif - /** - * Simplified macro to send a conditional warning radio log message using the current LOG_TAG. + * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG. */ #ifndef RLOGW_IF #define RLOGW_IF(cond, ...) \ - ( (CONDITION(cond)) \ - ? ((void)RLOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \ - : (void)0 ) + (((CONDITION(cond)) && (LOG_ON())) ? \ + (RLOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif - + /** - * Simplified macro to send an error radio log message using the current LOG_TAG. + * Simplified radio macro to send an error log message using the current LOG_TAG. */ #ifndef RLOGE -#define RLOGE(...) ((void)RLOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) +#define RLOGE(format, arg...) \ + (LOG_ON() ? (RLOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif - /** - * Simplified macro to send a conditional error radio log message using the current LOG_TAG. - */ + * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG. + */ #ifndef RLOGE_IF #define RLOGE_IF(cond, ...) \ - ( (CONDITION(cond)) \ - ? ((void)RLOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \ - : (void)0 ) + (((CONDITION(cond)) && (LOG_ON())) ? \ + (RLOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)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)) : ((void)0)) +#endif +/** + * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG. + */ +#ifndef RLOGF_IF +#define RLOGF_IF(cond, ...) \ + (((CONDITION(cond)) && (LOG_ON())) ? \ + (RLOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif -// --------------------------------------------------------------------- +// --------------------------------------------------------------------- /** - * Simplified macro to send a verbose system log message using the current LOG_TAG. + * Simplified system macro to send a verbose log message using the current LOG_TAG. */ #ifndef SLOGV #if LOG_NDEBUG #define SLOGV(...) ((void)0) #else -#define SLOGV(...) ((void)SLOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) +#define SLOGV(format, arg...) \ + (LOG_ON() ? (SLOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif #endif - /** - * Simplified macro to send a conditional verbose system log message using the current LOG_TAG. + * Simplified macro to send a conditional verbose log message using the current LOG_TAG. */ #ifndef SLOGV_IF #if LOG_NDEBUG #define SLOGV_IF(cond, ...) ((void)0) #else #define SLOGV_IF(cond, ...) \ - ( (CONDITION(cond)) \ - ? ((void)SLOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \ - : (void)0 ) + (((CONDITION(cond)) && (LOG_ON())) ? \ + (SLOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif #endif - + /** - * Simplified macro to send a debug system log message using the current LOG_TAG. + * Simplified system macro to send a debug log message using the current LOG_TAG. */ #ifndef SLOGD -#define SLOGD(...) ((void)SLOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) +#define SLOGD(format, arg...) \ + (LOG_ON() ? (SLOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif - /** - * Simplified macro to send a conditional debug system log message using the current LOG_TAG. + * Simplified system macro to send a conditional verbose log message using the current LOG_TAG. */ #ifndef SLOGD_IF #define SLOGD_IF(cond, ...) \ - ( (CONDITION(cond)) \ - ? ((void)SLOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \ - : (void)0 ) + (((CONDITION(cond)) && (LOG_ON())) ? \ + (SLOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif - + /** - * Simplified macro to send an info system log message using the current LOG_TAG. + * Simplified system macro to send an info log message using the current LOG_TAG. */ #ifndef SLOGI -#define SLOGI(...) ((void)SLOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) +#define SLOGI(format, arg...) \ + (LOG_ON() ? (SLOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif - /** - * Simplified macro to send a conditional info system log message using the current LOG_TAG. + * Simplified system macro to send a conditional verbose log message using the current LOG_TAG. */ #ifndef SLOGI_IF #define SLOGI_IF(cond, ...) \ - ( (CONDITION(cond)) \ - ? ((void)SLOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \ - : (void)0 ) + (((CONDITION(cond)) && (LOG_ON())) ? \ + (SLOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif - + /** - * Simplified macro to send a warning system log message using the current LOG_TAG. + * Simplified system macro to send a warning log message using the current LOG_TAG. */ #ifndef SLOGW -#define SLOGW(...) ((void)SLOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) +#define SLOGW(format, arg...) \ + (LOG_ON() ? (SLOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif - /** - * Simplified macro to send a conditional warning system log message using the current LOG_TAG. + * Simplified system macro to send a conditional verbose log message using the current LOG_TAG. */ #ifndef SLOGW_IF #define SLOGW_IF(cond, ...) \ - ( (CONDITION(cond)) \ - ? ((void)SLOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \ - : (void)0 ) + (((CONDITION(cond)) && (LOG_ON())) ? \ + (SLOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif - + /** - * Simplified macro to send an error system log message using the current LOG_TAG. + * Simplified system macro to send an error log message using the current LOG_TAG. */ #ifndef SLOGE -#define SLOGE(...) ((void)SLOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) +#define SLOGE(format, arg...) \ + (LOG_ON() ? (SLOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif - /** - * Simplified macro to send a conditional error system log message using the current LOG_TAG. + * Simplified system macro to send a conditional verbose log message using the current LOG_TAG. */ #ifndef SLOGE_IF #define SLOGE_IF(cond, ...) \ - ( (CONDITION(cond)) \ - ? ((void)SLOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \ - : (void)0 ) + (((CONDITION(cond)) && (LOG_ON())) ? \ + (SLOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)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)) : ((void)0)) +#endif +/** + * Simplified system macro to send a conditional verbose log message using the current LOG_TAG. + */ +#ifndef SLOGF_IF +#define SLOGF_IF(cond, ...) \ + (((CONDITION(cond)) && (LOG_ON())) ? \ + (SLOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0)) #endif // --------------------------------------------------------------------- @@ -383,75 +408,26 @@ typedef enum { #define ALOGV(...) ((void)0) #else #define ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) - -#endif -#endif - -/** - * Simplified macro to send a conditional verbose log message using the current LOG_TAG. - */ -#ifndef ALOGV_IF -#if LOG_NDEBUG -#define ALOGV_IF(cond, ...) ((void)0) -#else -#define ALOGV_IF(cond, ...) \ - ( (CONDITION(cond)) \ - ? ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \ - : (void)0 ) #endif #endif - /** * Simplified macro to send a debug log message using the current LOG_TAG. */ #ifndef ALOGD #define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) #endif - -/** - * Simplified macro to send a conditional debug log message using the current LOG_TAG. - */ -#ifndef ALOGD_IF -#define ALOGD_IF(cond, ...) \ - ( (CONDITION(cond)) \ - ? ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \ - : (void)0 ) -#endif - /** * Simplified macro to send an info log message using the current LOG_TAG. */ #ifndef ALOGI #define ALOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) #endif - -/** - * Simplified macro to send a conditional info log message using the current LOG_TAG. - */ -#ifndef ALOGI_IF -#define ALOGI_IF(cond, ...) \ - ( (CONDITION(cond)) \ - ? ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \ - : (void)0 ) -#endif - /** * Simplified macro to send a warning log message using the current LOG_TAG. */ #ifndef ALOGW #define ALOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) #endif - -/** - * Simplified macro to send a conditional warning log message using the current LOG_TAG. - */ -#ifndef ALOGW_IF -#define ALOGW_IF(cond, ...) \ - ( (CONDITION(cond)) \ - ? ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \ - : (void)0 ) -#endif - /** * Simplified macro to send an error log message using the current LOG_TAG. */ @@ -459,19 +435,7 @@ typedef enum { #define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) #endif -/** - * Simplified macro to send a conditional error log message using the current LOG_TAG. - */ -#ifndef ALOGE_IF -#define ALOGE_IF(cond, ...) \ - ( (CONDITION(cond)) \ - ? ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \ - : (void)0 ) -#endif -// TODO : support fatal log - // --------------------------------------------------------------------- - /** * Basic log message macro that allows you to specify a priority and a tag * @@ -488,41 +452,19 @@ typedef enum { #endif /** - * Log macro that allows you to pass in a varargs ("args" is a va_list). + * tizen app log macro that allows you to specify a priority and a tag. */ -#ifndef LOG_VA -#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. */ @@ -531,15 +473,6 @@ typedef enum { 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 - - /* * =========================================================================== * @@ -549,32 +482,20 @@ typedef enum { #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) - /** * @brief send log. must specify log_id ,priority, tag and format string. * @pre none * @post none - * @see __dlog_vprint + * @see __dlog_print * @remarks you must not use this API directly. use macros instead. * @param[in] log_id log device id * @param[in] prio priority @@ -592,30 +513,8 @@ typedef enum { * @endcode */ int __dlog_print(log_id_t log_id, int prio, const char *tag, const char *fmt, ...); - -/** - * @brief send log with va_list. must specify log_id ,priority, tag and format string. - * @pre none - * @post none - * @see __dlog_print - * @remarks you must not use this API directly. use macros instead. - * @param[in] log_id log device id - * @param[in] prio priority - * @param[in] tag tag - * @param[in] fmt format string - * @param[in] ap va_list - * @return Operation result - * @retval 0>= Success - * @retval -1 Error - * @code - // you have to use LOG_VA(), SLOG_VA(), RLOG_VA() family not to use __dlog_print() directly - // so below example is just for passing Documentation Verification !!! -#define LOG_TAG USR_TAG -#include - __dlog_vprint(LOG_ID_MAIN, DLOG_INFO, USR_TAG, "you must not use this API directly", ap); - * @endcode - */ int __dlog_vprint(log_id_t log_id, int prio, const char *tag, const char *fmt, va_list ap); +int _get_logging_on(); #ifdef __cplusplus } diff --git a/log.c b/log.c index d7be833..6c5235f 100755 --- a/log.c +++ b/log.c @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #ifdef HAVE_PTHREADS #include #endif @@ -25,7 +24,9 @@ #include #include #include - +#ifdef SD_JOURNAL_LOG +#include +#endif #define LOG_BUF_SIZE 1024 #define LOG_MAIN "log_main" @@ -33,23 +34,59 @@ #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_debug_level= DLOG_SILENT; +static int g_logging_on = 1; +static int g_dlog_level = DLOG_SILENT; 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; #ifdef HAVE_PTHREADS static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER; #endif - - static int __write_to_log_null(log_id_t log_id, log_priority prio, const char *tag, const char *msg) { - return -1; + return -1; +} +#ifdef SD_JOURNAL_LOG +static 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 __write_to_log_kernel(log_id_t log_id, log_priority prio, const char *tag, const char *msg) +{ + sd_journal_print(dlog_pri_to_journal_pri(prio), "%s %s", tag, msg); + return 1; +} +#else static int __write_to_log_kernel(log_id_t log_id, log_priority prio, const char *tag, const char *msg) { ssize_t ret; @@ -57,19 +94,19 @@ static int __write_to_log_kernel(log_id_t log_id, log_priority prio, const char struct iovec vec[3]; if (log_id < LOG_ID_APPS) { - if(prio