diff --git a/services/log/init_log.c b/services/log/init_log.c index c4aae73f1e7ff63176fc6fc44015f7be1abde1a7..a2386cc54e557224ab7590d3b4726d90c6d78120 100644 --- a/services/log/init_log.c +++ b/services/log/init_log.c @@ -53,8 +53,10 @@ static void LogToFile(const char *logFile, const char *tag, const char *info) FILE *outfile = NULL; INIT_CHECK_ONLY_RETURN((outfile = fopen(logFile, "a+")) != NULL); struct tm t; - char dateTime[80]; // 80 data time - strftime(dateTime, sizeof(dateTime), "%Y-%m-%d %H:%M:%S", localtime_r(&curr.tv_sec, &t)); + char dateTime[80] = {"00-00-00 00:00:00"}; // 80 data time + if (localtime_r(&curr.tv_sec, &t) != NULL) { + strftime(dateTime, sizeof(dateTime), "%Y-%m-%d %H:%M:%S", &t); + } (void)fprintf(outfile, "[%s.%ld][pid=%d %d][%s]%s \n", dateTime, curr.tv_nsec, getpid(), gettid(), tag, info); (void)fflush(outfile); fclose(outfile);