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 <minggui.cao@intel.com>
Reviewed-by: Yin Fengwei <fengwei.yin@intel.com>
This commit is contained in:
Minggui Cao 2020-04-15 10:31:50 +08:00 committed by wenlingz
parent a7a5c41e75
commit 9f036cff6a
1 changed files with 10 additions and 2 deletions

View File

@ -64,7 +64,7 @@ static int probe_disk_log_file(void)
DIR *dir; DIR *dir;
if (stat(LOG_PATH_NODE, &st)) { 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", pr_err(DISK_PREFIX"create path: %s failed! Error: %s\n",
LOG_PATH_NODE, strerror(errno)); LOG_PATH_NODE, strerror(errno));
return -1; return -1;
@ -143,6 +143,9 @@ static void write_to_disk(const char *fmt, va_list args)
int len; int len;
int write_cnt; int write_cnt;
struct timespec times = {0, 0}; struct timespec times = {0, 0};
struct tm *lt;
time_t tt;
if ((disk_fd < 0) && disk_log_enabled) { 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) if (len < 0)
return; return;
time(&tt);
lt = localtime(&tt);
clock_gettime(CLOCK_MONOTONIC, &times); clock_gettime(CLOCK_MONOTONIC, &times);
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) { if (len < 0 || len >= DISK_LOG_MAX_LEN) {
free(buf); free(buf);
return; return;