From cb50eb20567035f940b9cc7421f4eb192285b597 Mon Sep 17 00:00:00 2001 From: shenchenkai Date: Wed, 2 Jun 2021 16:41:09 +0800 Subject: [PATCH] show real time Signed-off-by: shenchenkai Change-Id: Ib2888c192b9461cf3907ea82a47383e87e14828c --- frameworks/mini/hiview_output_log.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/frameworks/mini/hiview_output_log.c b/frameworks/mini/hiview_output_log.c index 7eb20e6..6960370 100755 --- a/frameworks/mini/hiview_output_log.c +++ b/frameworks/mini/hiview_output_log.c @@ -25,6 +25,8 @@ #include "securec.h" #include "ohos_types.h" +#include + #define SINGLE_FMT_MAX_LEN 8 #define FMT_CONVERT_TRMINATOR 2 @@ -324,17 +326,22 @@ int32 LogContentFmt(char *outStr, int32 outStrLen, const uint8 *pLogContent) static int32 LogCommonFmt(char *outStr, int32 outStrLen, const HiLogCommon *commonContentPtr) { int32 ret; - uint32 time, day, hour, mte, sec; + time_t time; + uint32 year, month, day, hour, min, sec; uint8_t level; + struct tm nowTime = {0}; time = commonContentPtr->time; - day = time / SECONDS_PER_DAY; - hour = time % SECONDS_PER_DAY / SECONDS_PER_HOUR; - mte = time % SECONDS_PER_HOUR / SECONDS_PER_MINUTE; - sec = time % SECONDS_PER_MINUTE; + localtime_r(&time, &nowTime); + year = nowTime.tm_year + 1900; + month = nowTime.tm_mon + 1; + day = nowTime.tm_mday; + hour = nowTime.tm_hour; + min = nowTime.tm_min; + sec = nowTime.tm_sec; level = CLEAR_HASH_FLAG(commonContentPtr->level); - ret = snprintf_s(outStr, outStrLen, outStrLen - 1, "%02d %02d:%02d:%02d 0 %d %c %d/%s: ", - day, hour, mte, sec, commonContentPtr->task, g_logLevelInfo[level], + ret = snprintf_s(outStr, outStrLen, outStrLen - 1, "%04d-%02d-%02d %02d:%02d:%02d 0 %d %c %d/%s: ", + year, month, day, hour, min, sec, commonContentPtr->task, g_logLevelInfo[level], commonContentPtr->module, HiLogGetModuleName(commonContentPtr->module)); return ret; -- Gitee