diff --git a/device_info/BUILD.gn b/device_info/BUILD.gn index 02009f3cbb69ef7190b2d751364518e741b6d604..1cadeb3b55c2ae49ea41bf9c37e4c9b292017eb0 100755 --- a/device_info/BUILD.gn +++ b/device_info/BUILD.gn @@ -28,7 +28,6 @@ ohos_shared_library("deviceinfoservice") { sources = [ "device_info_stub.cpp" ] defines = [ - "INIT_AGENT", "DINFO_LABEL=\"DeviceInfoService\"", ] include_dirs = [ diff --git a/initsync/BUILD.gn b/initsync/BUILD.gn index 0b82490ee14d12e8a475de043796f652c3878cb5..98c0b49811e864fea9fa6fc8295fc004aff089ef 100644 --- a/initsync/BUILD.gn +++ b/initsync/BUILD.gn @@ -27,7 +27,7 @@ shared_library("libinitsync_shared") { "//base/startup/init_lite/interfaces/innerkits/include", ] public_deps = [ - "//base/startup/init_lite/services/log:init_log", + "//base/startup/init_lite/services/log:agent_log", "//third_party/bounds_checking_function:libsec_shared", ] } diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn index 21bd00537d205feed43e19f4f316d70aad7f1bb6..fe534d21951a757294d1d1ef2c944e45821c16c3 100755 --- a/interfaces/innerkits/BUILD.gn +++ b/interfaces/innerkits/BUILD.gn @@ -27,6 +27,7 @@ fs_manager_sources = [ ohos_shared_library("libbegetutil") { sources = [ "fd_holder/fd_holder.c", + "fd_holder/fd_holder_internal.c", "file/init_file.c", "reboot/init_reboot_innerkits.c", "service_control/service_control.c", @@ -42,18 +43,17 @@ ohos_shared_library("libbegetutil") { "//base/startup/init_lite/services/include/param", "//base/startup/init_lite/interfaces/innerkits/fd_holder", ] - defines = [ "INIT_AGENT" ] deps = [ - "//base/startup/init_lite/interfaces/innerkits/fd_holder:libfdholder_internal_static", + "//base/startup/init_lite/services/log:agent_log", + "//base/startup/init_lite/services/loopevent:loopevent", "//base/startup/init_lite/services/param:param_client", + "//base/startup/init_lite/services/utils:libinit_tools", "//base/startup/init_lite/services/utils:libinit_utils", "//third_party/bounds_checking_function:libsec_shared", "//third_party/openssl:libcrypto_static", "//utils/native/base:utils", ] - deps += [ "//base/startup/init_lite/services/log:init_log" ] - public_configs = [ ":exported_header_files" ] part_name = "init" install_images = [ @@ -106,6 +106,6 @@ ohos_static_library("libfsmanager_static") { "//base/startup/init_lite/services/log", "//base/startup/init_lite/services/include", ] - deps = [ "//base/startup/init_lite/services/log:init_log" ] + part_name = "init" } diff --git a/interfaces/innerkits/fd_holder/BUILD.gn b/interfaces/innerkits/fd_holder/BUILD.gn index 5ef7d4d6f7153a0765c950a37ecd1cb1ed9c999a..076084daf11b054a9b55a36fb19c4dc48d97b292 100644 --- a/interfaces/innerkits/fd_holder/BUILD.gn +++ b/interfaces/innerkits/fd_holder/BUILD.gn @@ -21,9 +21,5 @@ ohos_static_library("libfdholder_internal_static") { "//base/startup/init_lite/services/log", "//base/startup/init_lite/interfaces/innerkits/include", ] - - deps = [ "//base/startup/init_lite/services/log:init_log" ] - - defines = [ "INIT_AGENT" ] part_name = "init" } diff --git a/interfaces/innerkits/file/BUILD.gn b/interfaces/innerkits/file/BUILD.gn index 37e6d1763686354767edeb827feaa85b4fb84a20..66cb7413dc6b97452508e1c49d1ea949fdbbbd03 100644 --- a/interfaces/innerkits/file/BUILD.gn +++ b/interfaces/innerkits/file/BUILD.gn @@ -20,7 +20,7 @@ service_file_include = [ "//third_party/bounds_checking_function/include", ] service_file_deps = [ - "//base/startup/init_lite/services/log:init_log", + "//base/startup/init_lite/services/log:agent_log", "//base/startup/init_lite/services/utils:libinit_utils", "//third_party/bounds_checking_function:libsec_static", ] diff --git a/interfaces/innerkits/include/beget_ext.h b/interfaces/innerkits/include/beget_ext.h index 42d26da31abc7961fb1b295473363911607631bd..6c60cd4e7458b23b67c6b757438ac681f7d36a7a 100644 --- a/interfaces/innerkits/include/beget_ext.h +++ b/interfaces/innerkits/include/beget_ext.h @@ -22,12 +22,6 @@ extern "C" { #endif #endif -#if defined(ENABLE_HILOG) || defined(OHOS_LITE) -#include "hilog/log.h" -#undef LOG_DOMAIN -#define LOG_DOMAIN 0xD000719 -#endif - typedef enum InitLogLevel { INIT_DEBUG = 0, INIT_INFO, @@ -36,88 +30,21 @@ typedef enum InitLogLevel { INIT_FATAL } InitLogLevel; -#ifndef INIT_LOG_PATH -#define INIT_LOG_PATH "/data/init_agent/" -#endif - #define FILE_NAME (strrchr((__FILE__), '/') ? strrchr((__FILE__), '/') + 1 : (__FILE__)) -void InitLogInit(const char *outFileName, InitLogLevel logLevel, const char *kLevel, const char *fmt, ...); -void InitLogAgent(const char *outFileName, InitLogLevel logLevel, const char *kLevel, const char *fmt, ...); -void OpenLogDevice(void); - -#ifndef INIT_AGENT -#define InitLogPrint InitLogInit -#else -#define InitLogPrint InitLogAgent -#endif - -#ifndef OHOS_LITE -#ifndef ENABLE_HILOG -#define STARTUP_LOGV(logFile, LABEL, fmt, ...) \ - do { \ - InitLogPrint(INIT_LOG_PATH logFile, INIT_DEBUG, LABEL, "[%s:%d)] " fmt "\n", \ - (FILE_NAME), (__LINE__), ##__VA_ARGS__); \ - } while (0) - -#define STARTUP_LOGI(logFile, LABEL, fmt, ...) \ - do { \ - InitLogPrint(INIT_LOG_PATH logFile, INIT_INFO, LABEL, "[%s:%d)] " fmt "\n", \ - (FILE_NAME), (__LINE__), ##__VA_ARGS__); \ - } while (0) - -#define STARTUP_LOGE(logFile, LABEL, fmt, ...) \ - do { \ - InitLogPrint(INIT_LOG_PATH logFile, INIT_ERROR, LABEL, "[%s:%d)] " fmt "\n", \ - (FILE_NAME), (__LINE__), ##__VA_ARGS__); \ - } while (0) +void SetInitLogLevel(InitLogLevel logLevel); +void InitLog(InitLogLevel logLevel, const char *domain, const char *fileName, int line, const char *fmt, ...); -#define STARTUP_LOGW(logFile, LABEL, fmt, ...) \ - do { \ - InitLogPrint(INIT_LOG_PATH logFile, INIT_WARN, LABEL, "[%s:%d)] " fmt "\n", \ - (FILE_NAME), (__LINE__), ##__VA_ARGS__); \ - } while (0) - -#else -#define STARTUP_LOGV(logFile, LABEL, fmt, ...) \ - do { \ - InitLogPrint(INIT_LOG_PATH logFile, INIT_DEBUG, LABEL, "[%s:%d)] " fmt "\n", \ - (FILE_NAME), (__LINE__), ##__VA_ARGS__); \ - (void)HiLogPrint(LOG_APP, LOG_DEBUG, LOG_DOMAIN, LABEL, "[%{public}s(%{public}d)] " fmt, \ - (FILE_NAME), (__LINE__), ##__VA_ARGS__); \ - } while (0) - -#define STARTUP_LOGI(logFile, LABEL, fmt, ...) \ - do { \ - InitLogPrint(INIT_LOG_PATH logFile, INIT_INFO, LABEL, "[%s:%d)] " fmt "\n", \ - (FILE_NAME), (__LINE__), ##__VA_ARGS__); \ - (void)HiLogPrint(LOG_APP, LOG_INFO, LOG_DOMAIN, LABEL, "[%{public}s(%{public}d)] " fmt, \ - (FILE_NAME), (__LINE__), ##__VA_ARGS__); \ - } while (0) - -#define STARTUP_LOGE(logFile, LABEL, fmt, ...) \ - do { \ - InitLogPrint(INIT_LOG_PATH logFile, INIT_ERROR, LABEL, "[%s:%d)] " fmt "\n", \ - (FILE_NAME), (__LINE__), ##__VA_ARGS__); \ - (void)HiLogPrint(LOG_APP, LOG_ERROR, LOG_DOMAIN, LABEL, "[%{public}s(%{public}d)] " fmt, \ - (FILE_NAME), (__LINE__), ##__VA_ARGS__); \ - } while (0) - -#define STARTUP_LOGW(logFile, LABEL, fmt, ...) \ - do { \ - InitLogPrint(INIT_LOG_PATH logFile, INIT_WARN, LABEL, "[%s:%d)] " fmt "\n", \ - (FILE_NAME), (__LINE__), ##__VA_ARGS__); \ - (void)HiLogPrint(LOG_APP, LOG_WARN, LOG_DOMAIN, LABEL, "[%{public}s(%{public}d)] " fmt, \ - (FILE_NAME), (__LINE__), ##__VA_ARGS__); \ - } while (0) -#endif -#endif +#define STARTUP_LOGV(domain, fmt, ...) InitLog(INIT_DEBUG, domain, (FILE_NAME), (__LINE__), fmt, ##__VA_ARGS__) +#define STARTUP_LOGI(domain, fmt, ...) InitLog(INIT_INFO, domain, (FILE_NAME), (__LINE__), fmt, ##__VA_ARGS__) +#define STARTUP_LOGW(domain, fmt, ...) InitLog(INIT_WARN, domain, (FILE_NAME), (__LINE__), fmt, ##__VA_ARGS__) +#define STARTUP_LOGE(domain, fmt, ...) InitLog(INIT_ERROR, domain, (FILE_NAME), (__LINE__), fmt, ##__VA_ARGS__) +#define STARTUP_LOGF(domain, fmt, ...) InitLog(INIT_FATAL, domain, (FILE_NAME), (__LINE__), fmt, ##__VA_ARGS__) -#define BEGET_LOG_FILE "begetctrl.log" #define BEGET_LABEL "BEGET" -#define BEGET_LOGI(fmt, ...) STARTUP_LOGI(BEGET_LOG_FILE, BEGET_LABEL, fmt, ##__VA_ARGS__) -#define BEGET_LOGE(fmt, ...) STARTUP_LOGE(BEGET_LOG_FILE, BEGET_LABEL, fmt, ##__VA_ARGS__) -#define BEGET_LOGV(fmt, ...) STARTUP_LOGV(BEGET_LOG_FILE, BEGET_LABEL, fmt, ##__VA_ARGS__) -#define BEGET_LOGW(fmt, ...) STARTUP_LOGW(BEGET_LOG_FILE, BEGET_LABEL, fmt, ##__VA_ARGS__) +#define BEGET_LOGI(fmt, ...) STARTUP_LOGI(BEGET_LABEL, fmt, ##__VA_ARGS__) +#define BEGET_LOGE(fmt, ...) STARTUP_LOGE(BEGET_LABEL, fmt, ##__VA_ARGS__) +#define BEGET_LOGV(fmt, ...) STARTUP_LOGV(BEGET_LABEL, fmt, ##__VA_ARGS__) +#define BEGET_LOGW(fmt, ...) STARTUP_LOGW(BEGET_LABEL, fmt, ##__VA_ARGS__) #define BEGET_ERROR_CHECK(ret, statement, format, ...) \ if (!(ret)) { \ diff --git a/interfaces/innerkits/plugin/BUILD.gn b/interfaces/innerkits/plugin/BUILD.gn index 19c4cba39a5ae976df7b1d9a830c3553b5bb1236..c8edb9b981d9ecea08bd9155f38498b7d47f8948 100755 --- a/interfaces/innerkits/plugin/BUILD.gn +++ b/interfaces/innerkits/plugin/BUILD.gn @@ -22,7 +22,6 @@ ohos_shared_library("libplugin") { ] deps = [ - "//base/startup/init_lite/services/log:init_log", "//third_party/bounds_checking_function:libsec_static", ] install_enable = true diff --git a/interfaces/innerkits/sandbox/BUILD.gn b/interfaces/innerkits/sandbox/BUILD.gn index cf8c2fc9e10e1b52717ac4fe8d25fae520c85c40..96cfb3014ad4047b5a4c2408a07e962c68053ab8 100755 --- a/interfaces/innerkits/sandbox/BUILD.gn +++ b/interfaces/innerkits/sandbox/BUILD.gn @@ -31,14 +31,13 @@ ohos_shared_library("libsandbox") { "//base/startup/init_lite/interfaces/innerkits/include", "//third_party/cJSON", ] - defines = [ "INIT_AGENT" ] deps = [ "//base/startup/init_lite/services/utils:libinit_utils", "//third_party/bounds_checking_function:libsec_shared", "//third_party/cJSON:cjson_static", ] - deps += [ "//base/startup/init_lite/services/log:init_log" ] + deps += [ "//base/startup/init_lite/services/log:agent_log" ] part_name = "init" install_images = [ "system" ] @@ -62,6 +61,5 @@ ohos_static_library("libsandbox_static") { "//third_party/bounds_checking_function:libsec_static", "//third_party/cJSON:cjson_static", ] - deps += [ "//base/startup/init_lite/services/log:init_log" ] part_name = "init" } diff --git a/interfaces/innerkits/socket/BUILD.gn b/interfaces/innerkits/socket/BUILD.gn index 9273eaf616f707085dd6b9f45d1f0c7a9a31e326..9ce3ffde150390eaf4a3a7316aafd033ab5cda21 100644 --- a/interfaces/innerkits/socket/BUILD.gn +++ b/interfaces/innerkits/socket/BUILD.gn @@ -19,7 +19,7 @@ service_socket_include = [ "//third_party/bounds_checking_function/include", ] service_socket_deps = [ - "//base/startup/init_lite/services/log:init_log", + "//base/startup/init_lite/services/log:agent_log", "//third_party/bounds_checking_function:libsec_static", ] diff --git a/services/begetctl/BUILD.gn b/services/begetctl/BUILD.gn index 24f2cc11a0dc79a474eaed92072cf6ebcc0cddaa..bc0a565d4bb51dcb94b285e0973c20e50cda7983 100755 --- a/services/begetctl/BUILD.gn +++ b/services/begetctl/BUILD.gn @@ -60,6 +60,8 @@ ohos_executable("begetctl") { "//base/startup/init_lite/interfaces/innerkits:libbeget_proxy", "//base/startup/init_lite/services/loopevent:loopevent", "//base/startup/init_lite/services/param/watcher:param_watcheragent", + "//base/startup/init_lite/services/utils:libinit_tools", + "//base/startup/init_lite/services/utils:libinit_utils", "//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara", ] defines += [ @@ -129,6 +131,8 @@ ohos_executable("paramshell") { "//base/startup/init_lite/interfaces/innerkits:libbeget_proxy", "//base/startup/init_lite/services/loopevent:loopevent", "//base/startup/init_lite/services/param/watcher:param_watcheragent", + "//base/startup/init_lite/services/utils:libinit_tools", + "//base/startup/init_lite/services/utils:libinit_utils", "//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara", ] defines += [ diff --git a/services/begetctl/shell/shell_utils.h b/services/begetctl/shell/shell_utils.h index 896d7754aff390bf8cdb6ececa5cd2f8a648adb5..f36a834a2c818714593b04b9d8223377b38bb809 100755 --- a/services/begetctl/shell/shell_utils.h +++ b/services/begetctl/shell/shell_utils.h @@ -24,9 +24,9 @@ #define BSH_LOG_FILE "begetctrl.log" #define BSH_LABEL "SHELL" -#define BSH_LOGI(fmt, ...) STARTUP_LOGI(BSH_LOG_FILE, BSH_LABEL, fmt, ##__VA_ARGS__) -#define BSH_LOGE(fmt, ...) STARTUP_LOGE(BSH_LOG_FILE, BSH_LABEL, fmt, ##__VA_ARGS__) -#define BSH_LOGV(fmt, ...) STARTUP_LOGV(BSH_LOG_FILE, BSH_LABEL, fmt, ##__VA_ARGS__) +#define BSH_LOGI(fmt, ...) STARTUP_LOGI(BSH_LABEL, fmt, ##__VA_ARGS__) +#define BSH_LOGE(fmt, ...) STARTUP_LOGE(BSH_LABEL, fmt, ##__VA_ARGS__) +#define BSH_LOGV(fmt, ...) STARTUP_LOGV(BSH_LABEL, fmt, ##__VA_ARGS__) #define BSH_CHECK(ret, exper, ...) \ if (!(ret)) { \ diff --git a/services/log/BUILD.gn b/services/log/BUILD.gn index b8e404afe33435247fd46fba8df6f5a7b1344ffc..6e12f3d262ade8578da9eccf2510160ce35d8017 100755 --- a/services/log/BUILD.gn +++ b/services/log/BUILD.gn @@ -13,6 +13,7 @@ if (defined(ohos_lite)) { static_library("init_log") { sources = [ "init_log.c" ] + defines = [ "OHOS_LITE" ] public_deps = [ "//third_party/bounds_checking_function:libsec_static" ] include_dirs = [ "//base/hiviewdfx/hilog_lite/interfaces/native/kits", @@ -24,6 +25,7 @@ if (defined(ohos_lite)) { import("//build/ohos.gni") ohos_static_library("init_log") { sources = [ "init_log.c" ] + defines = [ "INIT_DMESG" ] deps = [ "//third_party/bounds_checking_function:libsec_static" ] include_dirs = [ "//base/startup/init_lite/interfaces/innerkits/include" ] part_name = "startup" @@ -40,6 +42,7 @@ if (defined(ohos_lite)) { "system", "updater", ] + external_deps = [ "hilog_native:libhilog_base" ] relative_install_dir = "platform-vndk" install_enable = true part_name = "init" diff --git a/services/log/init_log.c b/services/log/init_log.c index 37958c57bd7bf82cc6871546ac23ff3bdc1b567e..e2ca21eafb15fdfa96ecb2638e607bcfe0e425a2 100755 --- a/services/log/init_log.c +++ b/services/log/init_log.c @@ -22,61 +22,45 @@ #include #include "securec.h" -#define UNUSED(x) \ - do { \ - (void)(x) \ - } while (0) +#ifdef OHOS_LITE +#include "hilog/log.h" +#endif +#ifdef INIT_AGENT +#include "hilog_base/log_base.h" +#endif #define MAX_LOG_SIZE 1024 #define BASE_YEAR 1900 static InitLogLevel g_logLevel = INIT_INFO; -static const char *LOG_LEVEL_STR[] = { "DEBUG", "INFO", "WARNING", "ERROR", "FATAL" }; - void SetInitLogLevel(InitLogLevel logLevel) { g_logLevel = logLevel; } -#ifdef OHOS_LITE -static LogLevel ConvertToHiLog(InitLogLevel level) +#ifdef INIT_FILE +static void LogToFile(const char *logFile, const char *fileName, int line, const char *info) { - switch (level) { - case INIT_DEBUG: - return LOG_DEBUG; - case INIT_INFO: - return LOG_INFO; - case INIT_WARN: - return LOG_WARN; - case INIT_ERROR: - return LOG_ERROR; - case INIT_FATAL: - return LOG_FATAL; - // Unexpected log level, set level as lowest - default: - return LOG_DEBUG; - } -} - -void InitToHiLog(InitLogLevel logLevel, const char *fmt, ...) -{ - if (logLevel < g_logLevel) { + time_t second = time(0); + if (second <= 0) { return; } - - va_list list; - va_start(list, fmt); - char tmpFmt[MAX_LOG_SIZE]; - if (vsnprintf_s(tmpFmt, MAX_LOG_SIZE, MAX_LOG_SIZE - 1, fmt, list) == -1) { - va_end(list); + struct tm *t = localtime(&second); + FILE *outfile = fopen(logFile, "a+"); + if (t == NULL || outfile == NULL) { return; } - (void)HiLogPrint(LOG_CORE, ConvertToHiLog(logLevel), LOG_DOMAIN, INIT_LOG_TAG, "%{public}s", tmpFmt); - va_end(list); + (void)fprintf(outfile, "[%d-%d-%d %d:%d:%d][pid=%d][%s:%d]%s \n", + (t->tm_year + BASE_YEAR), (t->tm_mon + 1), t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, + getpid(), fileName, line, info); + (void)fflush(outfile); + fclose(outfile); return; } #endif +#ifdef INIT_DMESG +#ifndef OHOS_LITE static int g_fd = -1; void OpenLogDevice(void) { @@ -87,11 +71,10 @@ void OpenLogDevice(void) return; } -void InitLogInit(const char *outFileName, InitLogLevel logLevel, const char *kLevel, const char *fmt, ...) + void LogToDmesg(InitLogLevel logLevel, const char *domain, const char *fileName, int line, const char *info) { - if (logLevel < g_logLevel) { - return; - } + static const char *LOG_LEVEL_STR[] = { "DEBUG", "INFO", "WARNING", "ERROR", "FATAL" }; + static const char *LOG_KLEVEL_STR[] = { "<7>", "<6>", "<4>", "<3>", "<3>" }; if (UNLIKELY(g_fd < 0)) { OpenLogDevice(); @@ -99,52 +82,48 @@ void InitLogInit(const char *outFileName, InitLogLevel logLevel, const char *kLe return; } } - va_list vargs; - va_start(vargs, fmt); - char tmpFmt[MAX_LOG_SIZE]; - if (vsnprintf_s(tmpFmt, MAX_LOG_SIZE, MAX_LOG_SIZE - 1, fmt, vargs) == -1) { - close(g_fd); - g_fd = -1; - va_end(vargs); - return; - } - char logInfo[MAX_LOG_SIZE]; - if (snprintf_s(logInfo, MAX_LOG_SIZE, MAX_LOG_SIZE - 1, "%s[pid=%d][%s][%s] %s", - kLevel, getpid(), "INIT", LOG_LEVEL_STR[logLevel], tmpFmt) == -1) { + if (snprintf_s(logInfo, MAX_LOG_SIZE, MAX_LOG_SIZE - 1, "%s[pid=%d %d][%s][%s][%s:%d]%s", + LOG_KLEVEL_STR[logLevel], getpid(), getppid(), domain, LOG_LEVEL_STR[logLevel], fileName, line, info) == -1) { close(g_fd); g_fd = -1; - va_end(vargs); return; } - va_end(vargs); - if (write(g_fd, logInfo, strlen(logInfo)) < 0) { close(g_fd); g_fd = -1; } return; } +#endif +#endif -void InitLogAgent(const char *outFileName, InitLogLevel logLevel, const char *kLevel, const char *fmt, ...) +void InitLog(InitLogLevel logLevel, const char *domain, const char *fileName, int line, const char *fmt, ...) { - if (logLevel < g_logLevel) { + va_list vargs; + va_start(vargs, fmt); + char tmpFmt[MAX_LOG_SIZE]; + if (vsnprintf_s(tmpFmt, MAX_LOG_SIZE, MAX_LOG_SIZE - 1, fmt, vargs) == -1) { + va_end(vargs); return; } - time_t second = time(0); - INIT_CHECK_ONLY_RETURN(second >= 0 && outFileName != NULL); - struct tm *t = localtime(&second); - INIT_CHECK_ONLY_RETURN(t != NULL); - FILE *outfile = fopen(outFileName, "a+"); - INIT_CHECK_ONLY_RETURN(outfile != NULL); - (void)fprintf(outfile, "[%d-%d-%d %d:%d:%d][pid=%d][%s][%s] ", - (t->tm_year + BASE_YEAR), (t->tm_mon + 1), t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, - getpid(), kLevel, LOG_LEVEL_STR[logLevel]); - va_list list; - va_start(list, fmt); - (void)vfprintf(outfile, fmt, list); - va_end(list); - (void)fflush(outfile); - fclose(outfile); - return; + va_end(vargs); +#ifdef OHOS_LITE + static LogLevel LOG_LEVEL[] = { LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR, LOG_FATAL }; + (void)HiLogPrint(LOG_CORE, LOG_LEVEL[logLevel], + domain, INIT_LOG_TAG, "[%{public}s:%{public}d]%{public}s", fileName, line, tmpFmt); +#else +#ifdef INIT_DMESG + LogToDmesg(logLevel, domain, fileName, line, tmpFmt); +#endif +#endif + +#ifdef INIT_AGENT + static LogLevel LOG_LEVEL[] = { LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR, LOG_FATAL }; + HiLogBasePrint(LOG_CORE, LOG_LEVEL[logLevel], + 0, domain, "[%{public}s:%d]%{public}s", fileName, line, tmpFmt); +#ifdef INIT_FILE + LogToFile("/data/init_agent/begetctl.log", fileName, line, tmpFmt); +#endif +#endif } diff --git a/services/log/init_log.h b/services/log/init_log.h index d2c57bfbbcda374d305fc190861f95f8b09ac97a..c2aa7bd2b020e7a3b441ea820661cb8a81ede8f8 100755 --- a/services/log/init_log.h +++ b/services/log/init_log.h @@ -28,58 +28,21 @@ extern "C" { #endif #endif -void SetInitLogLevel(InitLogLevel logLevel); - #ifndef INIT_LOG_TAG #define INIT_LOG_TAG "Init" #endif -#ifdef OHOS_LITE -#define INIT_LOGV(fmt, ...) InitToHiLog(INIT_DEBUG, "%s : "fmt, (__FUNCTION__), ##__VA_ARGS__) -#define INIT_LOGI(fmt, ...) InitToHiLog(INIT_INFO, "%s : "fmt, (__FUNCTION__), ##__VA_ARGS__) -#define INIT_LOGW(fmt, ...) InitToHiLog(INIT_WARN, "%s : "fmt, (__FUNCTION__), ##__VA_ARGS__) -#define INIT_LOGE(fmt, ...) InitToHiLog(INIT_ERROR, "%s : "fmt, (__FUNCTION__), ##__VA_ARGS__) -#define INIT_LOGF(fmt, ...) InitToHiLog(INIT_FATAL, "%s : "fmt, (__FUNCTION__), ##__VA_ARGS__) - -#define STARTUP_LOGV(logFIle, LABEL, fmt, ...) InitToHiLog(LABEL, INIT_DEBUG, "%s : "fmt, (__FUNCTION__), ##__VA_ARGS__) -#define STARTUP_LOGI(logFIle, LABEL, fmt, ...) InitToHiLog(INIT_INFO, "%s : "fmt, (__FUNCTION__), ##__VA_ARGS__) -#define STARTUP_LOGE(logFIle, LABEL, fmt, ...) InitToHiLog(INIT_ERROR, "%s : "fmt, (__FUNCTION__), ##__VA_ARGS__) - -void InitToHiLog(InitLogLevel logLevel, const char *fmt, ...); - -#else - -#define INIT_LOGV(fmt, ...) \ - do { \ - InitLogPrint(INIT_LOG_PATH "init_agent.log", INIT_DEBUG, "<7>", "[%s:%d)] " fmt "\n", \ - (FILE_NAME), (__LINE__), ##__VA_ARGS__); \ - } while (0) - -#define INIT_LOGI(fmt, ...) \ - do { \ - InitLogPrint(INIT_LOG_PATH "init_agent.log", INIT_INFO, "<6>", "[%s:%d)] " fmt "\n", \ - (FILE_NAME), (__LINE__), ##__VA_ARGS__); \ - } while (0) - -#define INIT_LOGW(fmt, ...) \ - do { \ - InitLogPrint(INIT_LOG_PATH "init_agent.log", INIT_WARN, "<4>", "[%s:%d)] " fmt "\n", \ - (FILE_NAME), (__LINE__), ##__VA_ARGS__); \ - } while (0) - -#define INIT_LOGE(fmt, ...) \ - do { \ - InitLogPrint(INIT_LOG_PATH "init_agent.log", INIT_ERROR, "<3>", "[%s:%d)] " fmt "\n", \ - (FILE_NAME), (__LINE__), ##__VA_ARGS__); \ - } while (0) +#ifndef INIT_DOMAIN +#define INIT_DOMAIN "Init" +#endif -#define INIT_LOGF(fmt, ...) \ - do { \ - InitLogPrint(INIT_LOG_PATH "init_agent.log", INIT_FATAL, "<3>", "[%s:%d)] " fmt "\n", \ - (FILE_NAME), (__LINE__), ##__VA_ARGS__); \ - } while (0) +void OpenLogDevice(void); -#endif +#define INIT_LOGV(fmt, ...) InitLog(INIT_DEBUG, INIT_DOMAIN, (FILE_NAME), (__LINE__), fmt, ##__VA_ARGS__) +#define INIT_LOGI(fmt, ...) InitLog(INIT_INFO, INIT_DOMAIN, (FILE_NAME), (__LINE__), fmt, ##__VA_ARGS__) +#define INIT_LOGW(fmt, ...) InitLog(INIT_WARN, INIT_DOMAIN, (FILE_NAME), (__LINE__), fmt, ##__VA_ARGS__) +#define INIT_LOGE(fmt, ...) InitLog(INIT_ERROR, INIT_DOMAIN, (FILE_NAME), (__LINE__), fmt, ##__VA_ARGS__) +#define INIT_LOGF(fmt, ...) InitLog(INIT_FATAL, INIT_DOMAIN, (FILE_NAME), (__LINE__), fmt, ##__VA_ARGS__) #ifndef UNLIKELY #define UNLIKELY(x) __builtin_expect(!!(x), 0) diff --git a/services/loopevent/BUILD.gn b/services/loopevent/BUILD.gn index 78f2e1c55a3b6684ad587b3f7da6e618d0cf5dbc..ecdb5d223dabef24ead8cf78e5df0e1f602c1e71 100755 --- a/services/loopevent/BUILD.gn +++ b/services/loopevent/BUILD.gn @@ -43,11 +43,7 @@ if (defined(ohos_lite)) { include_dirs = common_include defines = [ "_GNU_SOURCE" ] - deps = [ - "//base/startup/init_lite/services/log:init_log", - "//base/startup/init_lite/services/utils:libinit_tools", - "//third_party/bounds_checking_function:libsec_static", - ] + deps = [ "//third_party/bounds_checking_function:libsec_static" ] } } else { import("//build/ohos.gni") @@ -57,11 +53,7 @@ if (defined(ohos_lite)) { include_dirs = common_include defines = [ "_GNU_SOURCE" ] - deps = [ - "//base/startup/init_lite/services/log:init_log", - "//base/startup/init_lite/services/utils:libinit_tools", - "//third_party/bounds_checking_function:libsec_static", - ] + deps = [ "//third_party/bounds_checking_function:libsec_static" ] part_name = "init" subsystem_name = "startup" } diff --git a/services/loopevent/utils/le_utils.h b/services/loopevent/utils/le_utils.h index 7326677d720b79d0d62cc9e4415e8c2766083df1..ff19c21b64886e3c8cd133d908ac8dfeeb86a204 100755 --- a/services/loopevent/utils/le_utils.h +++ b/services/loopevent/utils/le_utils.h @@ -27,11 +27,10 @@ #define LE_SET_FLAGS(flags, flag) ((flags) |= (flag)) #define LE_CLEAR_FLAGS(flags, flag) ((flags) &= ~(flag)) -#define LE_LOG_FILE "loopevent.log" #define LE_LABEL "LoopEvent" -#define LE_LOGI(fmt, ...) STARTUP_LOGI(LE_LOG_FILE, LE_LABEL, fmt, ##__VA_ARGS__) -#define LE_LOGE(fmt, ...) STARTUP_LOGE(LE_LOG_FILE, LE_LABEL, fmt, ##__VA_ARGS__) -#define LE_LOGV(fmt, ...) STARTUP_LOGV(LE_LOG_FILE, LE_LABEL, fmt, ##__VA_ARGS__) +#define LE_LOGI(fmt, ...) STARTUP_LOGI(LE_LABEL, fmt, ##__VA_ARGS__) +#define LE_LOGE(fmt, ...) STARTUP_LOGE(LE_LABEL, fmt, ##__VA_ARGS__) +#define LE_LOGV(fmt, ...) STARTUP_LOGV(LE_LABEL, fmt, ##__VA_ARGS__) #define LE_CHECK(ret, exper, ...) \ if (!(ret)) { \ diff --git a/services/param/BUILD.gn b/services/param/BUILD.gn index 6c39476ef1e104df90f3cf4f551892307524ae31..dd2edbfa7e72aa7a282d1057409a296e8af52ff8 100755 --- a/services/param/BUILD.gn +++ b/services/param/BUILD.gn @@ -98,8 +98,7 @@ ohos_shared_library("param_client") { "//base/startup/init_lite/services/loopevent/include", ] - defines = [ "INIT_AGENT" ] - defines += [ "_GNU_SOURCE" ] + defines = [ "_GNU_SOURCE" ] if (build_selinux) { defines += [ "WITH_SELINUX" ] diff --git a/services/param/include/param_utils.h b/services/param/include/param_utils.h index b887332d583125b6ef51925e6316c719a93a955a..76f111af38856ef853b11cdad3942cfc20fb88bd 100755 --- a/services/param/include/param_utils.h +++ b/services/param/include/param_utils.h @@ -80,11 +80,10 @@ typedef enum { #define PARAM_CLEAR_FLAG(node, flag) ((node) &= ~(flag)) #define PARAM_TEST_FLAG(node, flag) (((node) & (flag)) == (flag)) -#define PARAN_LOG_FILE "param.log" #define PARAN_LABEL "PARAM" -#define PARAM_LOGI(fmt, ...) STARTUP_LOGI(PARAN_LOG_FILE, PARAN_LABEL, fmt, ##__VA_ARGS__) -#define PARAM_LOGE(fmt, ...) STARTUP_LOGE(PARAN_LOG_FILE, PARAN_LABEL, fmt, ##__VA_ARGS__) -#define PARAM_LOGV(fmt, ...) STARTUP_LOGV(PARAN_LOG_FILE, PARAN_LABEL, fmt, ##__VA_ARGS__) +#define PARAM_LOGI(fmt, ...) STARTUP_LOGI(PARAN_LABEL, fmt, ##__VA_ARGS__) +#define PARAM_LOGE(fmt, ...) STARTUP_LOGE(PARAN_LABEL, fmt, ##__VA_ARGS__) +#define PARAM_LOGV(fmt, ...) STARTUP_LOGV(PARAN_LABEL, fmt, ##__VA_ARGS__) #define PARAM_CHECK(retCode, exper, ...) \ if (!(retCode)) { \ diff --git a/services/param/watcher/BUILD.gn b/services/param/watcher/BUILD.gn index bcb3451e871a25424508bce1801fb879aef07cbc..720f6374f1ebd3c30c94e0a4019739a194ca1edd 100644 --- a/services/param/watcher/BUILD.gn +++ b/services/param/watcher/BUILD.gn @@ -37,8 +37,6 @@ ohos_shared_library("param_watcheragent") { "//base/startup/init_lite/services/loopevent/include", ] - defines = [ "INIT_AGENT" ] - deps = [ "//base/startup/init_lite/services/log:agent_log", "//base/startup/init_lite/services/param:param_client", @@ -83,8 +81,6 @@ ohos_shared_library("param_watcher") { "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include", ] - defines = [ "INIT_AGENT" ] - deps = [ "//base/startup/init_lite/services/log:agent_log", "//base/startup/init_lite/services/param:param_client", diff --git a/services/param/watcher/include/watcher_utils.h b/services/param/watcher/include/watcher_utils.h index e8570196fafee01721e8cd4580bc57963a628a8a..9d5f78e46395e36ca3652cc1ffd0140a9262d335 100755 --- a/services/param/watcher/include/watcher_utils.h +++ b/services/param/watcher/include/watcher_utils.h @@ -26,11 +26,10 @@ namespace OHOS { namespace init_param { #define UNUSED(x) (void)(x) -#define WATCHER_LOG_FILE "param_watcher.log" #define WATCHER_LABEL "PARAM_WATCHER" -#define WATCHER_LOGI(fmt, ...) STARTUP_LOGI(WATCHER_LOG_FILE, WATCHER_LABEL, fmt, ##__VA_ARGS__) -#define WATCHER_LOGE(fmt, ...) STARTUP_LOGE(WATCHER_LOG_FILE, WATCHER_LABEL, fmt, ##__VA_ARGS__) -#define WATCHER_LOGV(fmt, ...) STARTUP_LOGV(WATCHER_LOG_FILE, WATCHER_LABEL, fmt, ##__VA_ARGS__) +#define WATCHER_LOGI(fmt, ...) STARTUP_LOGI(WATCHER_LABEL, fmt, ##__VA_ARGS__) +#define WATCHER_LOGE(fmt, ...) STARTUP_LOGE(WATCHER_LABEL, fmt, ##__VA_ARGS__) +#define WATCHER_LOGV(fmt, ...) STARTUP_LOGV(WATCHER_LABEL, fmt, ##__VA_ARGS__) #define WATCHER_CHECK(retCode, exper, ...) \ if (!(retCode)) { \ diff --git a/services/plugin/plugin_adapter.h b/services/plugin/plugin_adapter.h index 01ff3c7f510282ecb1ae9fc45bfda069262f58d2..bafa07b13be05004f86695a19df1e520301931d4 100755 --- a/services/plugin/plugin_adapter.h +++ b/services/plugin/plugin_adapter.h @@ -29,11 +29,10 @@ typedef struct { } PluginCmd; #define READ_DURATION 100000 -#define PLUGIN_LOG_FILE "plugintest.log" #define PLUGIN_LABEL "PLUGIN" -#define PLUGIN_LOGI(fmt, ...) STARTUP_LOGI(PLUGIN_LOG_FILE, PLUGIN_LABEL, fmt, ##__VA_ARGS__) -#define PLUGIN_LOGE(fmt, ...) STARTUP_LOGE(PLUGIN_LOG_FILE, PLUGIN_LABEL, fmt, ##__VA_ARGS__) -#define PLUGIN_LOGV(fmt, ...) STARTUP_LOGV(PLUGIN_LOG_FILE, PLUGIN_LABEL, fmt, ##__VA_ARGS__) +#define PLUGIN_LOGI(fmt, ...) STARTUP_LOGI(PLUGIN_LABEL, fmt, ##__VA_ARGS__) +#define PLUGIN_LOGE(fmt, ...) STARTUP_LOGE(PLUGIN_LABEL, fmt, ##__VA_ARGS__) +#define PLUGIN_LOGV(fmt, ...) STARTUP_LOGV(PLUGIN_LABEL, fmt, ##__VA_ARGS__) #define PLUGIN_CHECK(ret, exper, ...) \ if (!(ret)) { \ diff --git a/services/utils/BUILD.gn b/services/utils/BUILD.gn index f79f26b899f198d0cbe9e1deb385a71b0a2bd78a..4869f62a3a380aaed874f7f9ea8d78b2301edcf0 100755 --- a/services/utils/BUILD.gn +++ b/services/utils/BUILD.gn @@ -26,7 +26,6 @@ if (defined(ohos_lite)) { ] deps = [ - "//base/startup/init_lite/services/log:init_log", "//third_party/bounds_checking_function:libsec_static", ] defines = [ "_GNU_SOURCE" ] @@ -47,10 +46,7 @@ if (defined(ohos_lite)) { "//base/startup/init_lite/services/include", ] - deps = [ - "//base/startup/init_lite/services/log:init_log", - "//third_party/bounds_checking_function:libsec_static", - ] + deps = [ "//third_party/bounds_checking_function:libsec_static" ] defines = [ "_GNU_SOURCE" ] part_name = "init" } @@ -65,10 +61,7 @@ if (defined(ohos_lite)) { "//base/startup/init_lite/services/include", ] - deps = [ - "//base/startup/init_lite/services/log:init_log", - "//third_party/bounds_checking_function:libsec_static", - ] + deps = [ "//third_party/bounds_checking_function:libsec_static" ] defines = [ "_GNU_SOURCE" ] part_name = "init" } diff --git a/ueventd/BUILD.gn b/ueventd/BUILD.gn index f8f0878947adfb0fa3f77bb00b6ebbd3d03fb81d..fe10f5ac246b8a75c336edb3ea11b1ea61bebb92 100755 --- a/ueventd/BUILD.gn +++ b/ueventd/BUILD.gn @@ -24,6 +24,7 @@ if (defined(ohos_lite)) { "//base/startup/init_lite/ueventd/ueventd_main.c", "//base/startup/init_lite/ueventd/ueventd_read_cfg.c", "//base/startup/init_lite/ueventd/ueventd_socket.c", + "//base/startup/init_lite/interfaces/innerkits/socket/init_socket.c" ] defines = [ "__MUSL__" ] @@ -39,7 +40,6 @@ if (defined(ohos_lite)) { ] deps = [ - "//base/startup/init_lite/interfaces/innerkits/socket:libsocket_static", "//base/startup/init_lite/services/log:init_log", "//third_party/bounds_checking_function:libsec_static", ] @@ -69,6 +69,7 @@ if (defined(ohos_lite)) { "//base/startup/init_lite/ueventd/ueventd_firmware_handler.c", "//base/startup/init_lite/ueventd/ueventd_read_cfg.c", "//base/startup/init_lite/ueventd/ueventd_socket.c", + "//base/startup/init_lite/interfaces/innerkits/socket/init_socket.c" ] service_ueventd_include = [ @@ -81,7 +82,6 @@ if (defined(ohos_lite)) { ] service_ueventd_deps = [ - "//base/startup/init_lite/interfaces/innerkits/socket:libsocket_static", "//base/startup/init_lite/services/log:init_log", "//base/startup/init_lite/services/utils:libinit_utils", "//third_party/bounds_checking_function:libsec_static",