summaryrefslogtreecommitdiff
path: root/utils/log_util.h
diff options
context:
space:
mode:
authorhaohuang <haohuang@codeaurora.org>2019-09-16 16:03:09 +0800
committerhaohuang <haohuang@codeaurora.org>2019-11-29 16:28:04 +0800
commitd71529af0f5b103cdbe2679148bd7268cb4713b8 (patch)
tree37acfdeb4fb01c87982bbd8b18f168898bd5f4f2 /utils/log_util.h
parenta43430218337739c0c1143dc55474d1036d50558 (diff)
downloadgps-d71529af0f5b103cdbe2679148bd7268cb4713b8.tar.gz
Logging buffer implemented by skip list
Use skip list to implement a log buffer, log sentences will be inserted into this buffer once the log print function is called. the buffer will be dumped when GNSS process crash/killed or send SIGUSR1 signal manually. Change-Id: I5e23cdf30c263fa59108070c9dbfd95c49c2e9b6 CRs-Fixed: 2571326
Diffstat (limited to 'utils/log_util.h')
-rw-r--r--utils/log_util.h62
1 files changed, 55 insertions, 7 deletions
diff --git a/utils/log_util.h b/utils/log_util.h
index 192baeb..13c08bc 100644
--- a/utils/log_util.h
+++ b/utils/log_util.h
@@ -30,9 +30,13 @@
#ifndef __LOG_UTIL_H__
#define __LOG_UTIL_H__
+#include <stdbool.h>
+
#if defined (USE_ANDROID_LOGGING) || defined (ANDROID)
// Android and LE targets with logcat support
#include <utils/Log.h>
+#include <unistd.h>
+#include <sys/syscall.h>
#elif defined (USE_GLIB)
// LE targets with no logcat support
@@ -41,6 +45,7 @@
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h>
+#include <sys/syscall.h>
#ifndef LOG_TAG
#define LOG_TAG "GPS_UTILS"
@@ -90,18 +95,20 @@ typedef struct loc_logger_s
{
unsigned long DEBUG_LEVEL;
unsigned long TIMESTAMP;
+ bool LOG_BUFFER_ENABLE;
} loc_logger_s_type;
+
/*=============================================================================
*
* EXTERNAL DATA
*
*============================================================================*/
-extern loc_logger_s_type loc_logger;
// Logging Improvements
extern const char *loc_logger_boolStr[];
+extern loc_logger_s_type loc_logger;
extern const char *boolStr[];
extern const char VOID_RET[];
extern const char FROM_AFW[];
@@ -117,8 +124,49 @@ extern const char EXIT_ERROR_TAG[];
* MODULE EXPORTED FUNCTIONS
*
*============================================================================*/
-extern void loc_logger_init(unsigned long debug, unsigned long timestamp);
+inline void loc_logger_init(unsigned long debug, unsigned long timestamp)
+{
+ loc_logger.DEBUG_LEVEL = debug;
+#ifdef TARGET_BUILD_VARIANT_USER
+ // force user builds to 2 or less
+ if (loc_logger.DEBUG_LEVEL > 2) {
+ loc_logger.DEBUG_LEVEL = 2;
+ }
+#endif
+ loc_logger.TIMESTAMP = timestamp;
+}
+
+inline void log_buffer_init(bool enabled) {
+ loc_logger.LOG_BUFFER_ENABLE = enabled;
+}
+
extern char* get_timestamp(char* str, unsigned long buf_size);
+extern void log_buffer_insert(char *str, unsigned long buf_size, int level);
+
+/*=============================================================================
+ *
+ * LOGGING BUFFER MACROS
+ *
+ *============================================================================*/
+#ifndef LOG_NDEBUG
+#define LOG_NDEBUG 0
+#endif
+#define TOTAL_LOG_LEVELS 5
+#define LOGGING_BUFFER_MAX_LEN 1024
+#define IF_LOG_BUFFER_ENABLE if (loc_logger.LOG_BUFFER_ENABLE)
+#define INSERT_BUFFER(flag, level, format, x...) \
+{ \
+ IF_LOG_BUFFER_ENABLE { \
+ if (flag == 0) { \
+ char timestr[32]; \
+ get_timestamp(timestr, sizeof(timestr)); \
+ char log_str[LOGGING_BUFFER_MAX_LEN]; \
+ snprintf(log_str, LOGGING_BUFFER_MAX_LEN, "%s %d %ld %s :" format "\n", \
+ timestr, getpid(), syscall(SYS_gettid), LOG_TAG==NULL ? "": LOG_TAG, ##x);\
+ log_buffer_insert(log_str, sizeof(log_str), level); \
+ } \
+ } \
+}
#ifndef DEBUG_DMN_LOC_API
@@ -133,11 +181,11 @@ extern char* get_timestamp(char* str, unsigned long buf_size);
#define IF_LOC_LOGD if((loc_logger.DEBUG_LEVEL >= 4) && (loc_logger.DEBUG_LEVEL <= 5))
#define IF_LOC_LOGV if((loc_logger.DEBUG_LEVEL >= 5) && (loc_logger.DEBUG_LEVEL <= 5))
-#define LOC_LOGE(...) IF_LOC_LOGE { ALOGE(__VA_ARGS__); }
-#define LOC_LOGW(...) IF_LOC_LOGW { ALOGW(__VA_ARGS__); }
-#define LOC_LOGI(...) IF_LOC_LOGI { ALOGI(__VA_ARGS__); }
-#define LOC_LOGD(...) IF_LOC_LOGD { ALOGD(__VA_ARGS__); }
-#define LOC_LOGV(...) IF_LOC_LOGV { ALOGV(__VA_ARGS__); }
+#define LOC_LOGE(...) IF_LOC_LOGE { ALOGE(__VA_ARGS__); INSERT_BUFFER(LOG_NDEBUG, 0, __VA_ARGS__);}
+#define LOC_LOGW(...) IF_LOC_LOGW { ALOGW(__VA_ARGS__); INSERT_BUFFER(LOG_NDEBUG, 1, __VA_ARGS__);}
+#define LOC_LOGI(...) IF_LOC_LOGI { ALOGI(__VA_ARGS__); INSERT_BUFFER(LOG_NDEBUG, 2, __VA_ARGS__);}
+#define LOC_LOGD(...) IF_LOC_LOGD { ALOGD(__VA_ARGS__); INSERT_BUFFER(LOG_NDEBUG, 3, __VA_ARGS__);}
+#define LOC_LOGV(...) IF_LOC_LOGV { ALOGV(__VA_ARGS__); INSERT_BUFFER(LOG_NDEBUG, 4, __VA_ARGS__);}
#else /* DEBUG_DMN_LOC_API */