From 9f036cff6a26359e667c4caff1418ed857857739 Mon Sep 17 00:00:00 2001 From: Minggui Cao Date: Wed, 15 Apr 2020 10:31:50 +0800 Subject: [PATCH] DM: add wall time info into disk log file 1. add wall time info into disk log file, to make it easier to sync with other log 2. improve the log path creating operation, call system to make dir to avoid the first and second level path not existed. Tracked-On: #4633 Signed-off-by: Minggui Cao Reviewed-by: Yin Fengwei --- devicemodel/log/disk_logger.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/devicemodel/log/disk_logger.c b/devicemodel/log/disk_logger.c index 37073a0a1..fd0628ab5 100644 --- a/devicemodel/log/disk_logger.c +++ b/devicemodel/log/disk_logger.c @@ -64,7 +64,7 @@ static int probe_disk_log_file(void) DIR *dir; if (stat(LOG_PATH_NODE, &st)) { - if (mkdir(LOG_PATH_NODE, 0644)) { + if (system("mkdir -p " LOG_PATH_NODE) < 0) { pr_err(DISK_PREFIX"create path: %s failed! Error: %s\n", LOG_PATH_NODE, strerror(errno)); return -1; @@ -143,6 +143,9 @@ static void write_to_disk(const char *fmt, va_list args) int len; int write_cnt; struct timespec times = {0, 0}; + struct tm *lt; + time_t tt; + if ((disk_fd < 0) && disk_log_enabled) { /** @@ -160,8 +163,13 @@ static void write_to_disk(const char *fmt, va_list args) if (len < 0) return; + time(&tt); + lt = localtime(&tt); clock_gettime(CLOCK_MONOTONIC, ×); - len = snprintf(buffer, DISK_LOG_MAX_LEN, "[%5lu.%06lu] ", times.tv_sec, times.tv_nsec / 1000); + + len = snprintf(buffer, DISK_LOG_MAX_LEN, "[%4d-%02d-%02d %02d:%02d:%02d][%5lu.%06lu] ", + lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec, + times.tv_sec, times.tv_nsec / 1000); if (len < 0 || len >= DISK_LOG_MAX_LEN) { free(buf); return;