diff --git a/frameworks/mini/BUILD.gn b/frameworks/mini/BUILD.gn index 4ac2d4f5579dd61ca765b71608af356d461217a8..b45091081ccea8a2e096fcfbf3ca08c3b7b92fc1 100755 --- a/frameworks/mini/BUILD.gn +++ b/frameworks/mini/BUILD.gn @@ -14,50 +14,51 @@ import("//build/lite/ndk/ndk.gni") declare_args() { - ohos_hiviewdfx_hilog_lite_file_size = 8192 - ohos_hiviewdfx_hilog_lite_disable_cache = false - ohos_hiviewdfx_hilog_lite_limit_level_default = 30 - ohos_hiviewdfx_hilog_lite_disable_print_limit = false + ohos_hiviewdfx_hilog_lite_file_size = 8192 + ohos_hiviewdfx_hilog_lite_disable_cache = false + ohos_hiviewdfx_hilog_lite_limit_level_default = 30 + ohos_hiviewdfx_hilog_lite_disable_print_limit = false + ohos_hiviewdfx_log_static_cache_size = 1024 + ohos_hiviewdfx_hiview_hilog_file_buf_size = 512 } config("hilog_lite_config") { - include_dirs = [ - "//base/hiviewdfx/hiview_lite", - "//utils/native/lite/include", - "//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite", - "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", - ] + include_dirs = [ + "//base/hiviewdfx/hiview_lite", + "//utils/native/lite/include", + "//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", + ] } static_library("hilog_lite") { - sources = [ - "hiview_log.c", - "hiview_log_limit.c", - "hiview_output_log.c", - ] - cflags = [ "-Wall" ] - defines = [ - "HIVIEW_LOG_FILE_SIZE = $ohos_hiviewdfx_hilog_lite_file_size", - "LOG_LIMIT_DEFAULT = $ohos_hiviewdfx_hilog_lite_limit_level_default" - ] - if (ohos_hiviewdfx_hilog_lite_disable_cache) { - defines += ["DISABLE_HILOG_CACHE"] - } - if(ohos_hiviewdfx_hilog_lite_disable_print_limit) { - defines += ["DISABLE_HILOG_LITE_PRINT_LIMIT"] - } - public_configs = [ - "//base/hiviewdfx/hiview_lite:hiview_lite_config", - ":hilog_lite_config" - ] - deps = ["//base/hiviewdfx/hiview_lite"] + sources = [ + "hiview_log.c", + "hiview_log_limit.c", + "hiview_output_log.c", + ] + cflags = [ "-Wall" ] + defines = [ + "HIVIEW_LOG_FILE_SIZE = $ohos_hiviewdfx_hilog_lite_file_size", + "LOG_LIMIT_DEFAULT = $ohos_hiviewdfx_hilog_lite_limit_level_default", + "LOG_STATIC_CACHE_SIZE = $ohos_hiviewdfx_log_static_cache_size", + "HIVIEW_HILOG_FILE_BUF_SIZE = $ohos_hiviewdfx_hiview_hilog_file_buf_size", + ] + if (ohos_hiviewdfx_hilog_lite_disable_cache) { + defines += [ "DISABLE_HILOG_CACHE" ] + } + if (ohos_hiviewdfx_hilog_lite_disable_print_limit) { + defines += [ "DISABLE_HILOG_LITE_PRINT_LIMIT" ] + } + public_configs = [ + "//base/hiviewdfx/hiview_lite:hiview_lite_config", + ":hilog_lite_config", + ] + deps = [ "//base/hiviewdfx/hiview_lite" ] } ndk_lib("hilog_lite_ndk") { - deps = [ - ":hilog_lite" - ] - head_files = [ - "//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite", - ] + deps = [ ":hilog_lite" ] + head_files = + [ "//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite" ] } diff --git a/frameworks/mini/hiview_log.c b/frameworks/mini/hiview_log.c index 76c892772cd88a9a7d3435fa46dd23250712c5ac..b8d5022b824fb94150ead52c07f0f8cd831150c5 100755 --- a/frameworks/mini/hiview_log.c +++ b/frameworks/mini/hiview_log.c @@ -13,8 +13,9 @@ * limitations under the License. */ -#include "string.h" -#include "stdarg.h" +#include +#include +#include #include "ohos_init.h" #include "hiview_def.h" #include "hiview_util.h" @@ -50,7 +51,8 @@ static void HiLogInit(void) HiLogRegisterModule(HILOG_MODULE_SEN, "SEN") == FALSE || HiLogRegisterModule(HILOG_MODULE_SCY, "SCY") == FALSE || HiLogRegisterModule(HILOG_MODULE_SOFTBUS, "SOFTBUS") == FALSE || - HiLogRegisterModule(HILOG_MODULE_POWERMGR, "POWERMGR") == FALSE) { + HiLogRegisterModule(HILOG_MODULE_POWERMGR, "POWERMGR") == FALSE || + HiLogRegisterModule(HILOG_MODULE_UIKIT, "UIKIT") == FALSE) { return; } @@ -218,3 +220,18 @@ void HiLogOutputFileUnLock(void) { HiLogOutputFileUnLockImp(); } + +uint32 HiLogGetLogLevel(void) +{ + return g_hiviewConfig.level; +} + +boolean HiLogSetLogLevel(uint8 level) +{ + if (level >= HILOG_LV_DEBUG && level < HILOG_LV_MAX) { + g_hiviewConfig.level = level; + printf("Set log level: %d\n", level); + return TRUE; + } + return FALSE; +} diff --git a/frameworks/mini/hiview_output_log.c b/frameworks/mini/hiview_output_log.c index 3735b7dc4837e6869420ed9b4932511c8b906670..560b30516db6b6bda87bef7134d95f671dca86b9 100755 --- a/frameworks/mini/hiview_output_log.c +++ b/frameworks/mini/hiview_output_log.c @@ -234,7 +234,6 @@ static void OutputLog2TextFile(const Request *req) HIVIEW_MutexLock(g_logFlushInfo.mutex); HiLogContent logContent; char tempOutStr[LOG_FMT_MAX_LEN] = {0}; - (void)req; if (g_logCache.usedSize < sizeof(HiLogCommon)) { HIVIEW_MutexUnlock(g_logFlushInfo.mutex); @@ -263,6 +262,9 @@ static void OutputLog2TextFile(const Request *req) } } HIVIEW_MutexUnlock(g_logFlushInfo.mutex); + if (req != NULL && req->msgValue == SYNC_FILE) { + HIVIEW_FileSync(g_logFile.fhandle); + } } static void OutputLog2BinFile(const Request *req) @@ -273,7 +275,6 @@ static void OutputLog2BinFile(const Request *req) uint16 valueLen; uint8 *tmpBuffer = NULL; uint16 outputSize = g_logCache.usedSize; - (void)req; if (outputSize < sizeof(HiLogCommon)) { HIVIEW_MutexUnlock(g_logFlushInfo.mutex); @@ -309,6 +310,9 @@ static void OutputLog2BinFile(const Request *req) } HIVIEW_MemFree(MEM_POOL_HIVIEW_ID, tmpBuffer); HIVIEW_MutexUnlock(g_logFlushInfo.mutex); + if (req != NULL && req->msgValue == SYNC_FILE) { + HIVIEW_FileSync(g_logFile.fhandle); + } } uint32 GetLogFileSize(void) @@ -512,24 +516,26 @@ void FlushLog(boolean syncFlag) if (syncFlag == FALSE) { switch (opt) { case OUTPUT_OPTION_TEXT_FILE: - HiviewSendMessage(HIVIEW_SERVICE, HIVIEW_MSG_OUTPUT_LOG_TEXT_FILE, 0); + HiviewSendMessage(HIVIEW_SERVICE, HIVIEW_MSG_OUTPUT_LOG_TEXT_FILE, SYNC_FILE); break; case OUTPUT_OPTION_BIN_FILE: - HiviewSendMessage(HIVIEW_SERVICE, HIVIEW_MSG_OUTPUT_LOG_BIN_FILE, 0); + HiviewSendMessage(HIVIEW_SERVICE, HIVIEW_MSG_OUTPUT_LOG_BIN_FILE, SYNC_FILE); break; case OUTPUT_OPTION_FLOW: - HiviewSendMessage(HIVIEW_SERVICE, HIVIEW_MSG_OUTPUT_LOG_FLOW, 0); + HiviewSendMessage(HIVIEW_SERVICE, HIVIEW_MSG_OUTPUT_LOG_FLOW, SYNC_FILE); break; default: break; } } else { + Request request = {0}; + request.msgValue = SYNC_FILE; switch (opt) { case OUTPUT_OPTION_TEXT_FILE: - OutputLog2TextFile(NULL); + OutputLog2TextFile(&request); break; case OUTPUT_OPTION_BIN_FILE: - OutputLog2BinFile(NULL); + OutputLog2BinFile(&request); break; case OUTPUT_OPTION_FLOW: OutputLogRealtime(NULL); diff --git a/interfaces/native/kits/hilog_lite/hiview_log.h b/interfaces/native/kits/hilog_lite/hiview_log.h index 7dc77985e1641467961b54bf3bcc94926bdc8d92..af98d876cb7ec8fad1ba23c5453adf9a39985216 100755 --- a/interfaces/native/kits/hilog_lite/hiview_log.h +++ b/interfaces/native/kits/hilog_lite/hiview_log.h @@ -116,6 +116,8 @@ typedef enum { HILOG_MODULE_SOFTBUS, /** PowerMgr */ HILOG_MODULE_POWERMGR, + /** UIKit */ + HILOG_MODULE_UIKIT, /** OEM Customize */ HILOG_MODULE_OEM_CUSTOMIZE = 32, /** Maximum number of modules */ @@ -481,6 +483,19 @@ void HILOG_HashPrintf(uint8 module, uint8 level, const char *nums, uint32 hash, #define HILOG_FATAL_HASH(mod, hash, ...) #endif +/* + * Interface for get hilog level + * @return Returns current hilog level. + */ +uint32 HiLogGetLogLevel(void); + +/* + * Interface for set hilog level + * @param level identifies the level to be set + * @return Returns TRUE if setting log level is successful; returns FALSE otherwise. + */ +boolean HiLogSetLogLevel(uint8 level); + #ifdef __cplusplus #if __cplusplus }