aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLi Xiaoming <lixm.fnst@cn.fujitsu.com>2019-08-21 13:59:29 +0800
committerLi Xiaoming <lixm.fnst@cn.fujitsu.com>2019-08-21 13:59:29 +0800
commitdd1157b6dc1daf973eeac564736cf408c9f6f7b7 (patch)
tree14f75333958560eefc9de7c2094213ed1233facd
parent838d62ed32a6cd6d71c72a7b7b272d672bc7e674 (diff)
hmi-debug.h:Optimise code quality
This patch do below things: 1) standarize code indent and style; 2) add log when message is NULL, it may be a result of vasprintf failed or disable message manually; 3) add microsecond round up check. Bug-AGL: SPEC-2760 Change-Id: I1cac7a8f4755526c40f83aa3d6dfb3fbe0819fac Signed-off-by: Li Xiaoming <lixm.fnst@cn.fujitsu.com>
-rw-r--r--homescreen/src/hmi-debug.h33
1 files changed, 21 insertions, 12 deletions
diff --git a/homescreen/src/hmi-debug.h b/homescreen/src/hmi-debug.h
index 28705f5..47ae1f7 100644
--- a/homescreen/src/hmi-debug.h
+++ b/homescreen/src/hmi-debug.h
@@ -45,26 +45,35 @@ static char ERROR_FLAG[6][20] = {"NONE", "ERROR", "WARNING", "NOTICE", "INFO", "
static void _HMI_LOG(enum LOG_LEVEL level, const char* file, const char* func, const int line, const char* prefix, const char* log, ...)
{
- const int log_level = (getenv("USE_HMI_DEBUG") == NULL)?LOG_LEVEL_ERROR:atoi(getenv("USE_HMI_DEBUG"));
- if(log_level < level)
- {
+ char *message;
+ struct timespec tp;
+ uint32_t time;
+ va_list args;
+ int ret;
+ const int log_level = (getenv("USE_HMI_DEBUG") == NULL) ? LOG_LEVEL_ERROR : atoi(getenv("USE_HMI_DEBUG"));
+
+ if(log_level < level) {
return;
}
- char *message;
- struct timespec tp;
- unsigned int time;
+ va_start(args, log);
+ if (vasprintf(&message, log, args) < 0) {
+ fprintf(stderr, "Warning: message is NULL\n");
+ vfprintf(stderr, log, args);
+ fprintf(stderr, "\n");
+ message = NULL;
+ }
clock_gettime(CLOCK_REALTIME, &tp);
- time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000);
+ time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000);
+ if (tp.tv_nsec % 1000 >= 500) {
+ time++;
+ }
- va_list args;
- va_start(args, log);
- if (log == NULL || vasprintf(&message, log, args) < 0)
- message = NULL;
fprintf(stderr, "[%10.3f] [%s %s] [%s, %s(), Line:%d] >>> %s \n", time / 1000.0, prefix, ERROR_FLAG[level], file, func, line, message);
+
va_end(args);
- free(message);
+ free(message);
}
#endif //__HMI_DEBUG_H__