* 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
* @{
* @{
*/
-
-
#ifndef _DLOG_H_
#define _DLOG_H_
#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.
*/
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.
*/
#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.
*/
#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
// ---------------------------------------------------------------------
#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.
*/
#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
*
#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.
*/
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
-
-
/*
* ===========================================================================
*
#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
* @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.h>
- __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
}
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
#ifdef HAVE_PTHREADS
#include <pthread.h>
#endif
#include <stdio.h>
#include <errno.h>
#include <dlog.h>
-
+#ifdef SD_JOURNAL_LOG
+#include <systemd/sd-journal.h>
+#endif
#define LOG_BUF_SIZE 1024
#define LOG_MAIN "log_main"
#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;
struct iovec vec[3];
if (log_id < LOG_ID_APPS) {
- if(prio<g_debug_level) {
+ if(prio < g_dlog_level) {
return 0;
}
} else if (LOG_ID_MAX <= log_id) {
return 0;
}
- if( log_id < LOG_ID_MAX )
+ if (log_id < LOG_ID_MAX)
log_fd = log_fds[log_id];
else
return -1; // for TC
if (!tag)
- tag = "";
+ tag = "";
vec[0].iov_base = (unsigned char *) &prio;
vec[0].iov_len = 1;
return ret;
}
-
-void init_debug_level(void)
-{
- char *debuglevel=getenv("TIZEN_DEBUG_LEVEL");
- if(!debuglevel) {
-#ifndef NDEBUG
- fprintf(stderr, "Not matched env. variable, TIZEN_DEBUG_LEVEL");
#endif
- return;
+void init_dlog_level(void)
+{
+ char *dlog_level;
+ char *logging_mode;
+ if (g_logging_on) {
+ logging_mode = getenv("TIZEN_PLATFORMLOGGING_MODE");
+ if (!logging_mode)
+ g_logging_on = 0;
+ else
+ g_logging_on = atoi(logging_mode);
}
- g_debug_level=atoi(debuglevel);
-#ifndef NDEBUG
- fprintf(stderr, "debug level init %d(%s) \n",g_debug_level,debuglevel);
-#endif
+ if (g_logging_on) {
+ dlog_level = getenv("TIZEN_DLOG_LEVEL");
+ if (!dlog_level) {
+ g_dlog_level = 8;
+ } else {
+ g_dlog_level = atoi(dlog_level);
+ }
+ } else
+ g_dlog_level = 8;
}
static int __dlog_init(log_id_t log_id, log_priority prio, const char *tag, const char *msg)
{
#ifdef HAVE_PTHREADS
- pthread_mutex_lock(&log_init_lock);
+ pthread_mutex_lock(&log_init_lock);
#endif
// get filtering info
-
// open device
- if( write_to_log == __dlog_init)
- {
+ if (write_to_log == __dlog_init) {
+#ifdef SD_JOURNAL_LOG
+ write_to_log = __write_to_log_sd_journal_print;
+#else
+ init_dlog_level();
+
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);
- init_debug_level();
-
- if( log_fds[LOG_ID_MAIN] < 0 || log_fds[LOG_ID_RADIO] < 0 )
- {
+ if (log_fds[LOG_ID_MAIN] < 0 || log_fds[LOG_ID_RADIO] < 0) {
fprintf(stderr, "open log dev is failed\n");
write_to_log = __write_to_log_null;
- }
- else
+ } else
write_to_log = __write_to_log_kernel;
- if( log_fds[LOG_ID_SYSTEM] < 0 )
- {
+ if (log_fds[LOG_ID_SYSTEM] < 0)
log_fds[LOG_ID_SYSTEM] = log_fds[LOG_ID_MAIN];
- }
- if( log_fds[LOG_ID_APPS] < 0 )
- {
+ if (log_fds[LOG_ID_APPS] < 0)
log_fds[LOG_ID_APPS] = log_fds[LOG_ID_MAIN];
- }
+#endif
}
#ifdef HAVE_PTHREADS
- pthread_mutex_unlock(&log_init_lock);
+ pthread_mutex_unlock(&log_init_lock);
#endif
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];
+ char buf[LOG_BUF_SIZE];
- vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
+ vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
- return write_to_log(log_id, prio, tag, buf);
+ return write_to_log(log_id, prio, tag, buf);
}
int __dlog_print(log_id_t log_id, int prio, const char *tag, const char *fmt, ...)
{
- va_list ap;
- char buf[LOG_BUF_SIZE];
+ va_list ap;
+ char buf[LOG_BUF_SIZE];
- va_start(ap, fmt);
- vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
- va_end(ap);
+ va_start(ap, fmt);
+ vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
+ va_end(ap);
- return write_to_log(log_id, prio, tag, buf);
+ return write_to_log(log_id, prio, tag, buf);
+}
+int _get_logging_on()
+{
+ return g_logging_on;
}
-