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