未验证 提交 92f4a2db 编写于 作者: O openharmony_ci 提交者: Gitee

!1342 回退 set log level 提交

Merge pull request !1342 from cheng_jinsong/init1007
......@@ -51,8 +51,7 @@ typedef void (*InitCommLog)(int logLevel, uint32_t domain, const char *tag, cons
#define FILE_NAME (strrchr((__FILE__), '/') ? strrchr((__FILE__), '/') + 1 : (__FILE__))
INIT_PUBLIC_API void StartupLog(InitLogLevel logLevel, uint32_t domain, const char *tag, const char *fmt, ...);
INIT_PUBLIC_API void EnableInitLog(void);
INIT_PUBLIC_API void SetInitLogLevel(InitLogLevel level);
INIT_PUBLIC_API void EnableInitLog(InitLogLevel level);
INIT_PUBLIC_API void SetInitCommLog(InitCommLog logFunc);
#define STARTUP_LOGV(domain, tag, fmt, ...) \
......
......@@ -30,7 +30,7 @@ int main(int argc, char * const argv[])
INIT_LOGE("Process id error %d!", getpid());
return 0;
}
EnableInitLog();
EnableInitLog(INIT_INFO);
if (isSecondStage == 0) {
SystemPrepare();
} else {
......
......@@ -17,7 +17,6 @@ config("exported_header_files") {
include_dirs = [
"//base/startup/init/interfaces/innerkits/include",
"//base/startup/init/services/log",
"//base/startup/init/services/include",
]
}
......
......@@ -22,7 +22,6 @@
#include <time.h>
#include <sys/time.h>
#include "param/init_param.h"
#include "securec.h"
#ifdef OHOS_LITE
#ifndef INIT_LOG_INIT
......@@ -132,26 +131,8 @@ INIT_LOCAL_API void InitLog(int logLevel, unsigned int domain, const char *tag,
PrintLog((InitLogLevel)logLevel, domain, tag, tmpFmt);
}
INIT_PUBLIC_API void SetInitLogLevel(InitLogLevel level)
INIT_PUBLIC_API void EnableInitLog(InitLogLevel level)
{
if ((level >= INIT_DEBUG) && (level <= INIT_FATAL)) {
g_logLevel = level;
}
return;
}
INIT_PUBLIC_API void EnableInitLog(void)
{
SetInitCommLog(InitLog);
char logLevel[2] = {0}; // 2 is set param "persist.init.debug.loglevel" value length.
uint32_t len = sizeof(logLevel);
int ret = SystemReadParam("persist.init.debug.loglevel", logLevel, &len);
INIT_INFO_CHECK(ret == 0, return, "Can not get log level from param, keep the original loglevel.");
errno = 0;
unsigned int level = (unsigned int)strtoul(logLevel, 0, 10); // 10 is decimal
INIT_INFO_CHECK(errno == 0, return, "Failed strtoul %s, err=%d", logLevel, errno);
if ((level >= INIT_DEBUG) && (level <= INIT_FATAL)) {
g_logLevel = level;
}
return;
}
......@@ -342,7 +342,7 @@ static void SetServiceBootEventFork(SERVICE_INFO_CTX *serviceCtx)
MODULE_CONSTRUCTOR(void)
{
EnableInitLog();
EnableInitLog(INIT_DEBUG);
InitAddServiceHook(SetServiceBootEventFork, INIT_SERVICE_FORK_BEFORE);
InitAddServiceHook(ClearServiceBootEvent, INIT_SERVICE_CLEAR);
InitAddServiceHook(DumpServiceBootEvent, INIT_SERVICE_DUMP);
......
......@@ -122,27 +122,9 @@ static int CmdClear(int id, const char *name, int argc, const char **argv)
return 0;
}
static int CmdSetLogLevel(int id, const char *name, int argc, const char **argv)
{
UNUSED(id);
if ((name == NULL) || (argv == NULL) || (argc < 1)) {
PLUGIN_LOGE("Failed get log level from parameter.");
return -1;
}
char *value = strrchr(argv[0], '.');
PLUGIN_CHECK(value != NULL, return -1, "Failed get \'.\' from string %s", argv[0]);
unsigned int level;
int ret = StringToUint(value + 1, &level);
PLUGIN_CHECK(ret == 0, return -1, "Failed make string to unsigned int");
PLUGIN_LOGI("level is %d", level);
SetInitLogLevel(level);
return 0;
}
static int ParamSetInitCmdHook(const HOOK_INFO *hookInfo, void *cookie)
static int ParamSetBootEventHook(const HOOK_INFO *hookInfo, void *cookie)
{
AddCmdExecutor("clear", CmdClear);
AddCmdExecutor("setinitloglevel", CmdSetLogLevel);
return 0;
}
......@@ -155,7 +137,7 @@ static int DumpTrigger(const char *fmt, ...)
return 0;
}
static void DumpServiceHook(void)
static int DumpServiceHook(const HOOK_INFO *info, void *cookie)
{
// check and dump all jobs
char dump[8] = {0}; // 8 len
......@@ -165,21 +147,12 @@ static void DumpServiceHook(void)
if (ret == 0 && strcmp(dump, "1") == 0) {
SystemDumpTriggers(1, DumpTrigger);
}
return;
}
static int InitDebugHook(const HOOK_INFO *info, void *cookie)
{
UNUSED(info);
UNUSED(cookie);
EnableInitLog();
DumpServiceHook();
return 0;
}
MODULE_CONSTRUCTOR(void)
{
InitAddGlobalInitHook(0, ParamSetInitCmdHook);
InitAddGlobalInitHook(0, ParamSetBootEventHook);
// Depends on parameter service
InitAddPostPersistParamLoadHook(0, InitDebugHook);
InitAddPostPersistParamLoadHook(0, DumpServiceHook);
}
......@@ -62,7 +62,6 @@ const ParamCmdInfo *GetOtherSpecial(size_t *size)
{
static const ParamCmdInfo other[] = {
{"bootevent.", "bootevent.", "bootevent"},
{"persist.init.debug.", "persist.init.debug.", "setinitloglevel"}
};
*size = ARRAY_LENGTH(other);
return other;
......
......@@ -41,6 +41,7 @@ __attribute__((constructor)) static void ParameterInit(void)
if (getpid() == 1) {
return;
}
EnableInitLog(INIT_ERROR);
PARAM_WORKSPACE_OPS ops = {0};
ops.updaterMode = 0;
#ifdef PARAM_BASE_LOG
......@@ -50,7 +51,6 @@ __attribute__((constructor)) static void ParameterInit(void)
ops.setfilecon = NULL;
#endif
InitParamWorkSpace(1, &ops);
EnableInitLog();
}
__attribute__((destructor)) static void ParameterDeinit(void)
......
......@@ -26,13 +26,13 @@ static int InitParamClient(void)
if (PARAM_TEST_FLAG(g_flags, WORKSPACE_FLAGS_INIT)) {
return 0;
}
EnableInitLog(INIT_INFO);
PARAM_LOGV("InitParamClient");
int ret = InitParamWorkSpace(1, NULL);
PARAM_CHECK(ret == 0, return -1, "Failed to init param workspace");
PARAM_SET_FLAG(g_flags, WORKSPACE_FLAGS_INIT);
// init persist to save
InitPersistParamWorkSpace();
EnableInitLog();
return 0;
}
......
......@@ -132,11 +132,11 @@ static void ParamServiceTask(int *arg)
void LiteParamService(void)
{
EnableInitLog(INIT_INFO);
PARAM_LOGI("LiteParamService");
InitParamService();
// get persist param
LoadPersistParams();
EnableInitLog();
osThreadAttr_t attr;
attr.name = "ParamServiceTask";
attr.attr_bits = 0U;
......
......@@ -124,7 +124,7 @@ public:
}
void SetUp()
{
EnableInitLog();
EnableInitLog(INIT_FATAL);
}
void TearDown() {}
};
......
......@@ -434,7 +434,7 @@ int TestFreeLocalSecurityLabel(ParamSecurityLabel *srcLabel)
static __attribute__((constructor(101))) void ParamTestStubInit(void)
{
EnableInitLog();
EnableInitLog(INIT_DEBUG);
PARAM_LOGI("ParamTestStubInit");
PrepareInitUnitTestEnv();
}
......
......@@ -50,7 +50,7 @@ static void PollUeventdSocketTimeout(int ueventSockFd, bool ondemand)
int main(int argc, char **argv)
{
// start log
EnableInitLog();
EnableInitLog(INIT_INFO);
char *ueventdConfigs[] = {"/etc/ueventd.config", "/vendor/etc/ueventd.config", NULL};
int i = 0;
while (ueventdConfigs[i] != NULL) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册