diff --git a/adapter/properties.cpp b/adapter/properties.cpp index 39dab72433343c9f3a34952eaf0a632d8ea4aae3..aa407d75243c4ea2450f8bc5a06acc934d44e8b9 100644 --- a/adapter/properties.cpp +++ b/adapter/properties.cpp @@ -69,26 +69,17 @@ using ProcessInfo = struct { uint32_t processQuota; }; -static int PropLock(pthread_mutex_t *propLock) -{ - return pthread_mutex_trylock(propLock); -} - -static void PropUnlock(pthread_mutex_t *propLock) -{ - pthread_mutex_unlock(propLock); -} - void PropertyGet(const std::string &key, char *value, int len) { if (len < HILOG_PROP_VALUE_MAX) { return; } + /* use OHOS interface */ } void PropertySet(const std::string &key, const char* value) { -/* use OHOS interface */ + /* use OHOS interface */ } std::string GetProgName() @@ -188,13 +179,13 @@ static void UnlockByProp(uint32_t propType) static void RefreshCacheBuf(PropertyCache *cache, const char *key) { -/* use OHOS interface */ + /* use OHOS interface */ } static bool CheckCache(const PropertyCache *cache) { return true; -/* use OHOS interface */ + /* use OHOS interface */ } static bool GetSwitchCache(bool isFirst, SwitchCache& switchCache, uint32_t propType, bool defaultValue) @@ -285,14 +276,14 @@ uint16_t GetGlobalLevel() int notLocked; if (!isFirstFlag.test_and_set() || CheckCache(&levelCache.cache)) { - notLocked = PropLock(&g_globalLevelLock); + notLocked = LockByProp(PROP_GLOBAL_LOG_LEVEL); if (!notLocked) { RefreshCacheBuf(&levelCache.cache, key.c_str()); if (sscanf_s(levelCache.cache.propertyValue, "%d", &levelCache.logLevel) <= 0) { - PropUnlock(&g_globalLevelLock); + UnlockByProp(PROP_GLOBAL_LOG_LEVEL); return HILOG_LEVEL_MIN; } - PropUnlock(&g_globalLevelLock); + UnlockByProp(PROP_GLOBAL_LOG_LEVEL); return levelCache.logLevel; } else { LogLevelCache tmpCache = {{nullptr, 0xffffffff, ""}, HILOG_LEVEL_MIN}; @@ -327,14 +318,14 @@ uint16_t GetDomainLevel(uint32_t domain) return levelCache->logLevel; } else { // exist domain if (CheckCache(&it->second->cache)) { // change - notLocked = PropLock(&g_domainLevelLock); + notLocked = LockByProp(PROP_DOMAIN_LOG_LEVEL); if (!notLocked) { RefreshCacheBuf(&it->second->cache, key.c_str()); if (sscanf_s(it->second->cache.propertyValue, "%d", &it->second->logLevel) <= 0) { - PropUnlock(&g_domainLevelLock); + UnlockByProp(PROP_DOMAIN_LOG_LEVEL); return HILOG_LEVEL_MIN; } - PropUnlock(&g_domainLevelLock); + UnlockByProp(PROP_DOMAIN_LOG_LEVEL); return it->second->logLevel; } else { LogLevelCache tmpCache = {{nullptr, 0xffffffff, ""}, HILOG_LEVEL_MIN}; @@ -371,14 +362,14 @@ uint16_t GetTagLevel(const std::string& tag) return levelCache->logLevel; } else { if (CheckCache(&it->second->cache)) { - notLocked = PropLock(&g_tagLevelLock); + notLocked = LockByProp(PROP_TAG_LOG_LEVEL); if (!notLocked) { RefreshCacheBuf(&it->second->cache, key.c_str()); if (sscanf_s(it->second->cache.propertyValue, "%d", &it->second->logLevel) <= 0) { - PropUnlock(&g_tagLevelLock); + UnlockByProp(PROP_TAG_LOG_LEVEL); return HILOG_LEVEL_MIN; } - PropUnlock(&g_tagLevelLock); + UnlockByProp(PROP_TAG_LOG_LEVEL); return it->second->logLevel; } else { LogLevelCache tmpCache = {{nullptr, 0xffffffff, ""}, HILOG_LEVEL_MIN}; diff --git a/adapter/properties.h b/adapter/properties.h index cebbaa193af0ecdd55d7bffdbf5d18deefea87d0..42d1f7b6bd2d9fe7b17374c240633c434af99f83 100644 --- a/adapter/properties.h +++ b/adapter/properties.h @@ -20,6 +20,7 @@ #include #include + static const int HILOG_PROP_VALUE_MAX = 92; using PropType = enum { diff --git a/frameworks/native/include/hilogtool_msg.h b/frameworks/native/include/hilogtool_msg.h index cd4b03c68ef58b5a2d7568aa0f7d0e97ef1f3fb6..fd0d524f8d581811d91bc60e7b4c79948c1956dd 100644 --- a/frameworks/native/include/hilogtool_msg.h +++ b/frameworks/native/include/hilogtool_msg.h @@ -238,7 +238,7 @@ typedef struct { std::string compressAlgStr; std::string fileSizeStr; std::string fileNumStr; - std::string filePathStr; + std::string fileNameStr; std::string jobIdStr; } LogPersistParam; typedef struct { diff --git a/services/hilogd/log_buffer.cpp b/services/hilogd/log_buffer.cpp index 7fd532709a65a4149ae1ac8ff56456a9cfb77b5f..70c694f156f8a3edf3a591b07a10a5555e9e9674 100644 --- a/services/hilogd/log_buffer.cpp +++ b/services/hilogd/log_buffer.cpp @@ -236,7 +236,7 @@ bool HilogBuffer::Query(LogReader* reader) size_t HilogBuffer::GetBuffLen(uint16_t logType) { if (logType >= LOG_TYPE_MAX) { - return 0; + return -1; } uint64_t buffSize = g_maxBufferSizeByType[logType]; return buffSize; diff --git a/services/hilogd/log_querier.cpp b/services/hilogd/log_querier.cpp index e08ed10171e9888430dae2f120426f7eadeea3fa..8ef90acff30ad9f63f7d8c1ffbb8f2fffc9f60e4 100644 --- a/services/hilogd/log_querier.cpp +++ b/services/hilogd/log_querier.cpp @@ -135,7 +135,7 @@ void HandlePersistStartRequest(char* reqMsg, std::shared_ptr logReade pLogPersistStartRst->result = persister->Init(); persister->queryCondition.types = pLogPersistStartMsg->logType; persister->queryCondition.levels = DEFAULT_LOG_LEVEL; - if (pLogPersistStartRst->result == RET_FAIL) { + if (pLogPersistStartRst->result == RET_FAIL) { persister.reset(); } else { persister->Start(); @@ -284,7 +284,7 @@ void HandleBufferSizeRequest(char* reqMsg, std::shared_ptr logReader, uint32_t msgNum = 0; uint16_t msgLen = pBufferSizeReq->msgHeader.msgLen; uint16_t sendMsgLen = 0; - uint64_t buffLen; + int64_t buffLen; if (msgLen > sizeof(BuffSizeMsg) * LOG_TYPE_MAX) { return; diff --git a/services/hilogtool/log_controller.cpp b/services/hilogtool/log_controller.cpp index d8284f21275c04503b03f7441c5edc7da8a2ac10..7cc1d50bddec1cdb8857ea3f8470d2239a179e1a 100644 --- a/services/hilogtool/log_controller.cpp +++ b/services/hilogtool/log_controller.cpp @@ -366,7 +366,7 @@ int32_t LogPersistOp(SeqPacketSocketClient& controller, uint8_t msgCmd, LogPersi } pLogPersistStartMsg->logType = (0b01 << tmpType) | pLogPersistStartMsg->logType; } - pLogPersistStartMsg->jobId = (logPersistParam->jobIdStr == "") ? time(nullptr) + pLogPersistStartMsg->jobId = (logPersistParam->jobIdStr == "") ? 1 : stoi(logPersistParam->jobIdStr); pLogPersistStartMsg->compressType = (logPersistParam->compressTypeStr == "") ? STREAM : stoi(logPersistParam ->compressTypeStr); @@ -376,13 +376,15 @@ int32_t LogPersistOp(SeqPacketSocketClient& controller, uint8_t msgCmd, LogPersi logPersistParam->fileSizeStr); pLogPersistStartMsg->fileNum = (logPersistParam->fileNumStr == "") ? fileNumDefault : stoi(logPersistParam->fileNumStr); - if (logPersistParam->filePathStr == "") { - logPersistParam->filePathStr = "/data/misc/logd/log_" + to_string(time(nullptr)); + if (logPersistParam->fileNameStr == "") { + logPersistParam->fileNameStr = "/data/misc/logd/log_" + to_string(time(nullptr)); + } else { + logPersistParam->fileNameStr = "/data/misc/logd/" + logPersistParam->fileNameStr; } - if (logPersistParam->filePathStr.size() > FILE_PATH_MAX_LEN) { + if (logPersistParam->fileNameStr.size() > FILE_PATH_MAX_LEN) { return RET_FAIL; } - ret += strcpy_s(pLogPersistStartMsg->filePath, FILE_PATH_MAX_LEN, logPersistParam->filePathStr.c_str()); + ret += strcpy_s(pLogPersistStartMsg->filePath, FILE_PATH_MAX_LEN, logPersistParam->fileNameStr.c_str()); SetMsgHead(&pLogPersistStartReq->msgHeader, msgCmd, sizeof(LogPersistStartRequest)); controller.WriteAll(msgToSend, sizeof(LogPersistStartRequest)); break; diff --git a/services/hilogtool/main.cpp b/services/hilogtool/main.cpp index 8645f806a98b36c870901a27c7b9e1b8e6006dc7..4d5bf13b53ba8109b73fe802f02e389a1db68e80 100644 --- a/services/hilogtool/main.cpp +++ b/services/hilogtool/main.cpp @@ -78,8 +78,8 @@ static void Helper() " -e , --regex=\n" " show the logs which match the regular expression,\n" " is a regular expression.\n" - " -F , --path=\n" - " set log file path.\n" + " -F , --filename=\n" + " set log file name.\n" " -l , --length=\n" " set single log file size.\n" " -n , --number\n" @@ -103,6 +103,8 @@ static void Helper() " nsec display time by nano sec.\n" " year display the year.\n" " zone display the time zone.\n" + " -b , --baselevel=\n" + " set loggable level.\n" ); } @@ -195,7 +197,7 @@ int HilogEntry(int argc, char* argv[]) { "compress", required_argument, nullptr, 'c' }, { "stream", required_argument, nullptr, 'm' }, { "number", required_argument, nullptr, 'n' }, - { "path", required_argument, nullptr, 'F' }, + { "filename", required_argument, nullptr, 'F' }, { "private", required_argument, nullptr, 'p' }, { "domain", required_argument, nullptr, 'D' }, { "tag", required_argument, nullptr, 'T' }, @@ -314,7 +316,7 @@ int HilogEntry(int argc, char* argv[]) context.fileNumArgs = optarg; break; case 'F': - context.filePathArgs = optarg; + context.fileNameArgs = optarg; break; case 'j': context.jobIdArgs = optarg; @@ -393,7 +395,7 @@ int HilogEntry(int argc, char* argv[]) logPersistParam.compressAlgStr = context.algorithmArgs; logPersistParam.fileSizeStr = context.fileSizeArgs; logPersistParam.fileNumStr = context.fileNumArgs; - logPersistParam.filePathStr = context.filePathArgs; + logPersistParam.fileNameStr = context.fileNameArgs; logPersistParam.jobIdStr = context.jobIdArgs; if (context.logFileCtrlArgs == "start") { ret = LogPersistOp(controller, MC_REQ_LOG_PERSIST_START, &logPersistParam);