提交 67baf759 编写于 作者: X xionglei6

fix log

Signed-off-by: Nxionglei6 <xionglei6@huawei.com>
上级 779e1987
...@@ -28,7 +28,6 @@ ohos_shared_library("deviceinfoservice") { ...@@ -28,7 +28,6 @@ ohos_shared_library("deviceinfoservice") {
sources = [ "device_info_stub.cpp" ] sources = [ "device_info_stub.cpp" ]
defines = [ defines = [
"INIT_AGENT",
"DINFO_LABEL=\"DeviceInfoService\"", "DINFO_LABEL=\"DeviceInfoService\"",
] ]
include_dirs = [ include_dirs = [
......
...@@ -27,7 +27,7 @@ shared_library("libinitsync_shared") { ...@@ -27,7 +27,7 @@ shared_library("libinitsync_shared") {
"//base/startup/init_lite/interfaces/innerkits/include", "//base/startup/init_lite/interfaces/innerkits/include",
] ]
public_deps = [ 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", "//third_party/bounds_checking_function:libsec_shared",
] ]
} }
......
...@@ -27,6 +27,7 @@ fs_manager_sources = [ ...@@ -27,6 +27,7 @@ fs_manager_sources = [
ohos_shared_library("libbegetutil") { ohos_shared_library("libbegetutil") {
sources = [ sources = [
"fd_holder/fd_holder.c", "fd_holder/fd_holder.c",
"fd_holder/fd_holder_internal.c",
"file/init_file.c", "file/init_file.c",
"reboot/init_reboot_innerkits.c", "reboot/init_reboot_innerkits.c",
"service_control/service_control.c", "service_control/service_control.c",
...@@ -42,18 +43,17 @@ ohos_shared_library("libbegetutil") { ...@@ -42,18 +43,17 @@ ohos_shared_library("libbegetutil") {
"//base/startup/init_lite/services/include/param", "//base/startup/init_lite/services/include/param",
"//base/startup/init_lite/interfaces/innerkits/fd_holder", "//base/startup/init_lite/interfaces/innerkits/fd_holder",
] ]
defines = [ "INIT_AGENT" ]
deps = [ 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/param:param_client",
"//base/startup/init_lite/services/utils:libinit_tools",
"//base/startup/init_lite/services/utils:libinit_utils", "//base/startup/init_lite/services/utils:libinit_utils",
"//third_party/bounds_checking_function:libsec_shared", "//third_party/bounds_checking_function:libsec_shared",
"//third_party/openssl:libcrypto_static", "//third_party/openssl:libcrypto_static",
"//utils/native/base:utils", "//utils/native/base:utils",
] ]
deps += [ "//base/startup/init_lite/services/log:init_log" ]
public_configs = [ ":exported_header_files" ] public_configs = [ ":exported_header_files" ]
part_name = "init" part_name = "init"
install_images = [ install_images = [
...@@ -106,6 +106,6 @@ ohos_static_library("libfsmanager_static") { ...@@ -106,6 +106,6 @@ ohos_static_library("libfsmanager_static") {
"//base/startup/init_lite/services/log", "//base/startup/init_lite/services/log",
"//base/startup/init_lite/services/include", "//base/startup/init_lite/services/include",
] ]
deps = [ "//base/startup/init_lite/services/log:init_log" ]
part_name = "init" part_name = "init"
} }
...@@ -21,9 +21,5 @@ ohos_static_library("libfdholder_internal_static") { ...@@ -21,9 +21,5 @@ ohos_static_library("libfdholder_internal_static") {
"//base/startup/init_lite/services/log", "//base/startup/init_lite/services/log",
"//base/startup/init_lite/interfaces/innerkits/include", "//base/startup/init_lite/interfaces/innerkits/include",
] ]
deps = [ "//base/startup/init_lite/services/log:init_log" ]
defines = [ "INIT_AGENT" ]
part_name = "init" part_name = "init"
} }
...@@ -20,7 +20,7 @@ service_file_include = [ ...@@ -20,7 +20,7 @@ service_file_include = [
"//third_party/bounds_checking_function/include", "//third_party/bounds_checking_function/include",
] ]
service_file_deps = [ 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", "//base/startup/init_lite/services/utils:libinit_utils",
"//third_party/bounds_checking_function:libsec_static", "//third_party/bounds_checking_function:libsec_static",
] ]
......
...@@ -22,12 +22,6 @@ extern "C" { ...@@ -22,12 +22,6 @@ extern "C" {
#endif #endif
#endif #endif
#if defined(ENABLE_HILOG) || defined(OHOS_LITE)
#include "hilog/log.h"
#undef LOG_DOMAIN
#define LOG_DOMAIN 0xD000719
#endif
typedef enum InitLogLevel { typedef enum InitLogLevel {
INIT_DEBUG = 0, INIT_DEBUG = 0,
INIT_INFO, INIT_INFO,
...@@ -36,88 +30,21 @@ typedef enum InitLogLevel { ...@@ -36,88 +30,21 @@ typedef enum InitLogLevel {
INIT_FATAL INIT_FATAL
} InitLogLevel; } InitLogLevel;
#ifndef INIT_LOG_PATH
#define INIT_LOG_PATH "/data/init_agent/"
#endif
#define FILE_NAME (strrchr((__FILE__), '/') ? strrchr((__FILE__), '/') + 1 : (__FILE__)) #define FILE_NAME (strrchr((__FILE__), '/') ? strrchr((__FILE__), '/') + 1 : (__FILE__))
void InitLogInit(const char *outFileName, InitLogLevel logLevel, const char *kLevel, const char *fmt, ...); void SetInitLogLevel(InitLogLevel logLevel);
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, ...);
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)
#define STARTUP_LOGW(logFile, LABEL, fmt, ...) \ #define STARTUP_LOGV(domain, fmt, ...) InitLog(INIT_DEBUG, domain, (FILE_NAME), (__LINE__), fmt, ##__VA_ARGS__)
do { \ #define STARTUP_LOGI(domain, fmt, ...) InitLog(INIT_INFO, domain, (FILE_NAME), (__LINE__), fmt, ##__VA_ARGS__)
InitLogPrint(INIT_LOG_PATH logFile, INIT_WARN, LABEL, "[%s:%d)] " fmt "\n", \ #define STARTUP_LOGW(domain, fmt, ...) InitLog(INIT_WARN, domain, (FILE_NAME), (__LINE__), fmt, ##__VA_ARGS__)
(FILE_NAME), (__LINE__), ##__VA_ARGS__); \ #define STARTUP_LOGE(domain, fmt, ...) InitLog(INIT_ERROR, domain, (FILE_NAME), (__LINE__), fmt, ##__VA_ARGS__)
} while (0) #define STARTUP_LOGF(domain, fmt, ...) InitLog(INIT_FATAL, domain, (FILE_NAME), (__LINE__), fmt, ##__VA_ARGS__)
#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 BEGET_LOG_FILE "begetctrl.log"
#define BEGET_LABEL "BEGET" #define BEGET_LABEL "BEGET"
#define BEGET_LOGI(fmt, ...) STARTUP_LOGI(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_LOG_FILE, BEGET_LABEL, fmt, ##__VA_ARGS__) #define BEGET_LOGE(fmt, ...) STARTUP_LOGE(BEGET_LABEL, fmt, ##__VA_ARGS__)
#define BEGET_LOGV(fmt, ...) STARTUP_LOGV(BEGET_LOG_FILE, BEGET_LABEL, fmt, ##__VA_ARGS__) #define BEGET_LOGV(fmt, ...) STARTUP_LOGV(BEGET_LABEL, fmt, ##__VA_ARGS__)
#define BEGET_LOGW(fmt, ...) STARTUP_LOGW(BEGET_LOG_FILE, BEGET_LABEL, fmt, ##__VA_ARGS__) #define BEGET_LOGW(fmt, ...) STARTUP_LOGW(BEGET_LABEL, fmt, ##__VA_ARGS__)
#define BEGET_ERROR_CHECK(ret, statement, format, ...) \ #define BEGET_ERROR_CHECK(ret, statement, format, ...) \
if (!(ret)) { \ if (!(ret)) { \
......
...@@ -22,7 +22,6 @@ ohos_shared_library("libplugin") { ...@@ -22,7 +22,6 @@ ohos_shared_library("libplugin") {
] ]
deps = [ deps = [
"//base/startup/init_lite/services/log:init_log",
"//third_party/bounds_checking_function:libsec_static", "//third_party/bounds_checking_function:libsec_static",
] ]
install_enable = true install_enable = true
......
...@@ -31,14 +31,13 @@ ohos_shared_library("libsandbox") { ...@@ -31,14 +31,13 @@ ohos_shared_library("libsandbox") {
"//base/startup/init_lite/interfaces/innerkits/include", "//base/startup/init_lite/interfaces/innerkits/include",
"//third_party/cJSON", "//third_party/cJSON",
] ]
defines = [ "INIT_AGENT" ]
deps = [ deps = [
"//base/startup/init_lite/services/utils:libinit_utils", "//base/startup/init_lite/services/utils:libinit_utils",
"//third_party/bounds_checking_function:libsec_shared", "//third_party/bounds_checking_function:libsec_shared",
"//third_party/cJSON:cjson_static", "//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" part_name = "init"
install_images = [ "system" ] install_images = [ "system" ]
...@@ -62,6 +61,5 @@ ohos_static_library("libsandbox_static") { ...@@ -62,6 +61,5 @@ ohos_static_library("libsandbox_static") {
"//third_party/bounds_checking_function:libsec_static", "//third_party/bounds_checking_function:libsec_static",
"//third_party/cJSON:cjson_static", "//third_party/cJSON:cjson_static",
] ]
deps += [ "//base/startup/init_lite/services/log:init_log" ]
part_name = "init" part_name = "init"
} }
...@@ -19,7 +19,7 @@ service_socket_include = [ ...@@ -19,7 +19,7 @@ service_socket_include = [
"//third_party/bounds_checking_function/include", "//third_party/bounds_checking_function/include",
] ]
service_socket_deps = [ 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", "//third_party/bounds_checking_function:libsec_static",
] ]
......
...@@ -60,6 +60,8 @@ ohos_executable("begetctl") { ...@@ -60,6 +60,8 @@ ohos_executable("begetctl") {
"//base/startup/init_lite/interfaces/innerkits:libbeget_proxy", "//base/startup/init_lite/interfaces/innerkits:libbeget_proxy",
"//base/startup/init_lite/services/loopevent:loopevent", "//base/startup/init_lite/services/loopevent:loopevent",
"//base/startup/init_lite/services/param/watcher:param_watcheragent", "//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", "//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara",
] ]
defines += [ defines += [
...@@ -129,6 +131,8 @@ ohos_executable("paramshell") { ...@@ -129,6 +131,8 @@ ohos_executable("paramshell") {
"//base/startup/init_lite/interfaces/innerkits:libbeget_proxy", "//base/startup/init_lite/interfaces/innerkits:libbeget_proxy",
"//base/startup/init_lite/services/loopevent:loopevent", "//base/startup/init_lite/services/loopevent:loopevent",
"//base/startup/init_lite/services/param/watcher:param_watcheragent", "//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", "//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara",
] ]
defines += [ defines += [
......
...@@ -24,9 +24,9 @@ ...@@ -24,9 +24,9 @@
#define BSH_LOG_FILE "begetctrl.log" #define BSH_LOG_FILE "begetctrl.log"
#define BSH_LABEL "SHELL" #define BSH_LABEL "SHELL"
#define BSH_LOGI(fmt, ...) STARTUP_LOGI(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_LOG_FILE, BSH_LABEL, fmt, ##__VA_ARGS__) #define BSH_LOGE(fmt, ...) STARTUP_LOGE(BSH_LABEL, fmt, ##__VA_ARGS__)
#define BSH_LOGV(fmt, ...) STARTUP_LOGV(BSH_LOG_FILE, BSH_LABEL, fmt, ##__VA_ARGS__) #define BSH_LOGV(fmt, ...) STARTUP_LOGV(BSH_LABEL, fmt, ##__VA_ARGS__)
#define BSH_CHECK(ret, exper, ...) \ #define BSH_CHECK(ret, exper, ...) \
if (!(ret)) { \ if (!(ret)) { \
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
if (defined(ohos_lite)) { if (defined(ohos_lite)) {
static_library("init_log") { static_library("init_log") {
sources = [ "init_log.c" ] sources = [ "init_log.c" ]
defines = [ "OHOS_LITE" ]
public_deps = [ "//third_party/bounds_checking_function:libsec_static" ] public_deps = [ "//third_party/bounds_checking_function:libsec_static" ]
include_dirs = [ include_dirs = [
"//base/hiviewdfx/hilog_lite/interfaces/native/kits", "//base/hiviewdfx/hilog_lite/interfaces/native/kits",
...@@ -24,6 +25,7 @@ if (defined(ohos_lite)) { ...@@ -24,6 +25,7 @@ if (defined(ohos_lite)) {
import("//build/ohos.gni") import("//build/ohos.gni")
ohos_static_library("init_log") { ohos_static_library("init_log") {
sources = [ "init_log.c" ] sources = [ "init_log.c" ]
defines = [ "INIT_DMESG" ]
deps = [ "//third_party/bounds_checking_function:libsec_static" ] deps = [ "//third_party/bounds_checking_function:libsec_static" ]
include_dirs = [ "//base/startup/init_lite/interfaces/innerkits/include" ] include_dirs = [ "//base/startup/init_lite/interfaces/innerkits/include" ]
part_name = "startup" part_name = "startup"
...@@ -40,6 +42,7 @@ if (defined(ohos_lite)) { ...@@ -40,6 +42,7 @@ if (defined(ohos_lite)) {
"system", "system",
"updater", "updater",
] ]
external_deps = [ "hilog_native:libhilog_base" ]
relative_install_dir = "platform-vndk" relative_install_dir = "platform-vndk"
install_enable = true install_enable = true
part_name = "init" part_name = "init"
......
...@@ -22,61 +22,45 @@ ...@@ -22,61 +22,45 @@
#include <time.h> #include <time.h>
#include "securec.h" #include "securec.h"
#define UNUSED(x) \ #ifdef OHOS_LITE
do { \ #include "hilog/log.h"
(void)(x) \ #endif
} while (0) #ifdef INIT_AGENT
#include "hilog_base/log_base.h"
#endif
#define MAX_LOG_SIZE 1024 #define MAX_LOG_SIZE 1024
#define BASE_YEAR 1900 #define BASE_YEAR 1900
static InitLogLevel g_logLevel = INIT_INFO; static InitLogLevel g_logLevel = INIT_INFO;
static const char *LOG_LEVEL_STR[] = { "DEBUG", "INFO", "WARNING", "ERROR", "FATAL" };
void SetInitLogLevel(InitLogLevel logLevel) void SetInitLogLevel(InitLogLevel logLevel)
{ {
g_logLevel = logLevel; g_logLevel = logLevel;
} }
#ifdef OHOS_LITE #ifdef INIT_FILE
static LogLevel ConvertToHiLog(InitLogLevel level) static void LogToFile(const char *logFile, const char *fileName, int line, const char *info)
{ {
switch (level) { time_t second = time(0);
case INIT_DEBUG: if (second <= 0) {
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) {
return; return;
} }
struct tm *t = localtime(&second);
va_list list; FILE *outfile = fopen(logFile, "a+");
va_start(list, fmt); if (t == NULL || outfile == NULL) {
char tmpFmt[MAX_LOG_SIZE];
if (vsnprintf_s(tmpFmt, MAX_LOG_SIZE, MAX_LOG_SIZE - 1, fmt, list) == -1) {
va_end(list);
return; return;
} }
(void)HiLogPrint(LOG_CORE, ConvertToHiLog(logLevel), LOG_DOMAIN, INIT_LOG_TAG, "%{public}s", tmpFmt); (void)fprintf(outfile, "[%d-%d-%d %d:%d:%d][pid=%d][%s:%d]%s \n",
va_end(list); (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; return;
} }
#endif #endif
#ifdef INIT_DMESG
#ifndef OHOS_LITE
static int g_fd = -1; static int g_fd = -1;
void OpenLogDevice(void) void OpenLogDevice(void)
{ {
...@@ -87,11 +71,10 @@ void OpenLogDevice(void) ...@@ -87,11 +71,10 @@ void OpenLogDevice(void)
return; 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) { static const char *LOG_LEVEL_STR[] = { "DEBUG", "INFO", "WARNING", "ERROR", "FATAL" };
return; static const char *LOG_KLEVEL_STR[] = { "<7>", "<6>", "<4>", "<3>", "<3>" };
}
if (UNLIKELY(g_fd < 0)) { if (UNLIKELY(g_fd < 0)) {
OpenLogDevice(); OpenLogDevice();
...@@ -99,52 +82,48 @@ void InitLogInit(const char *outFileName, InitLogLevel logLevel, const char *kLe ...@@ -99,52 +82,48 @@ void InitLogInit(const char *outFileName, InitLogLevel logLevel, const char *kLe
return; 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]; char logInfo[MAX_LOG_SIZE];
if (snprintf_s(logInfo, MAX_LOG_SIZE, MAX_LOG_SIZE - 1, "%s[pid=%d][%s][%s] %s", if (snprintf_s(logInfo, MAX_LOG_SIZE, MAX_LOG_SIZE - 1, "%s[pid=%d %d][%s][%s][%s:%d]%s",
kLevel, getpid(), "INIT", LOG_LEVEL_STR[logLevel], tmpFmt) == -1) { LOG_KLEVEL_STR[logLevel], getpid(), getppid(), domain, LOG_LEVEL_STR[logLevel], fileName, line, info) == -1) {
close(g_fd); close(g_fd);
g_fd = -1; g_fd = -1;
va_end(vargs);
return; return;
} }
va_end(vargs);
if (write(g_fd, logInfo, strlen(logInfo)) < 0) { if (write(g_fd, logInfo, strlen(logInfo)) < 0) {
close(g_fd); close(g_fd);
g_fd = -1; g_fd = -1;
} }
return; 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; return;
} }
time_t second = time(0); va_end(vargs);
INIT_CHECK_ONLY_RETURN(second >= 0 && outFileName != NULL); #ifdef OHOS_LITE
struct tm *t = localtime(&second); static LogLevel LOG_LEVEL[] = { LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR, LOG_FATAL };
INIT_CHECK_ONLY_RETURN(t != NULL); (void)HiLogPrint(LOG_CORE, LOG_LEVEL[logLevel],
FILE *outfile = fopen(outFileName, "a+"); domain, INIT_LOG_TAG, "[%{public}s:%{public}d]%{public}s", fileName, line, tmpFmt);
INIT_CHECK_ONLY_RETURN(outfile != NULL); #else
(void)fprintf(outfile, "[%d-%d-%d %d:%d:%d][pid=%d][%s][%s] ", #ifdef INIT_DMESG
(t->tm_year + BASE_YEAR), (t->tm_mon + 1), t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, LogToDmesg(logLevel, domain, fileName, line, tmpFmt);
getpid(), kLevel, LOG_LEVEL_STR[logLevel]); #endif
va_list list; #endif
va_start(list, fmt);
(void)vfprintf(outfile, fmt, list); #ifdef INIT_AGENT
va_end(list); static LogLevel LOG_LEVEL[] = { LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR, LOG_FATAL };
(void)fflush(outfile); HiLogBasePrint(LOG_CORE, LOG_LEVEL[logLevel],
fclose(outfile); 0, domain, "[%{public}s:%d]%{public}s", fileName, line, tmpFmt);
return; #ifdef INIT_FILE
LogToFile("/data/init_agent/begetctl.log", fileName, line, tmpFmt);
#endif
#endif
} }
...@@ -28,58 +28,21 @@ extern "C" { ...@@ -28,58 +28,21 @@ extern "C" {
#endif #endif
#endif #endif
void SetInitLogLevel(InitLogLevel logLevel);
#ifndef INIT_LOG_TAG #ifndef INIT_LOG_TAG
#define INIT_LOG_TAG "Init" #define INIT_LOG_TAG "Init"
#endif #endif
#ifdef OHOS_LITE #ifndef INIT_DOMAIN
#define INIT_LOGV(fmt, ...) InitToHiLog(INIT_DEBUG, "%s : "fmt, (__FUNCTION__), ##__VA_ARGS__) #define INIT_DOMAIN "Init"
#define INIT_LOGI(fmt, ...) InitToHiLog(INIT_INFO, "%s : "fmt, (__FUNCTION__), ##__VA_ARGS__) #endif
#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)
#define INIT_LOGF(fmt, ...) \ void OpenLogDevice(void);
do { \
InitLogPrint(INIT_LOG_PATH "init_agent.log", INIT_FATAL, "<3>", "[%s:%d)] " fmt "\n", \
(FILE_NAME), (__LINE__), ##__VA_ARGS__); \
} while (0)
#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 #ifndef UNLIKELY
#define UNLIKELY(x) __builtin_expect(!!(x), 0) #define UNLIKELY(x) __builtin_expect(!!(x), 0)
......
...@@ -43,11 +43,7 @@ if (defined(ohos_lite)) { ...@@ -43,11 +43,7 @@ if (defined(ohos_lite)) {
include_dirs = common_include include_dirs = common_include
defines = [ "_GNU_SOURCE" ] defines = [ "_GNU_SOURCE" ]
deps = [ deps = [ "//third_party/bounds_checking_function:libsec_static" ]
"//base/startup/init_lite/services/log:init_log",
"//base/startup/init_lite/services/utils:libinit_tools",
"//third_party/bounds_checking_function:libsec_static",
]
} }
} else { } else {
import("//build/ohos.gni") import("//build/ohos.gni")
...@@ -57,11 +53,7 @@ if (defined(ohos_lite)) { ...@@ -57,11 +53,7 @@ if (defined(ohos_lite)) {
include_dirs = common_include include_dirs = common_include
defines = [ "_GNU_SOURCE" ] defines = [ "_GNU_SOURCE" ]
deps = [ deps = [ "//third_party/bounds_checking_function:libsec_static" ]
"//base/startup/init_lite/services/log:init_log",
"//base/startup/init_lite/services/utils:libinit_tools",
"//third_party/bounds_checking_function:libsec_static",
]
part_name = "init" part_name = "init"
subsystem_name = "startup" subsystem_name = "startup"
} }
......
...@@ -27,11 +27,10 @@ ...@@ -27,11 +27,10 @@
#define LE_SET_FLAGS(flags, flag) ((flags) |= (flag)) #define LE_SET_FLAGS(flags, flag) ((flags) |= (flag))
#define LE_CLEAR_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_LABEL "LoopEvent"
#define LE_LOGI(fmt, ...) STARTUP_LOGI(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_LOG_FILE, LE_LABEL, fmt, ##__VA_ARGS__) #define LE_LOGE(fmt, ...) STARTUP_LOGE(LE_LABEL, fmt, ##__VA_ARGS__)
#define LE_LOGV(fmt, ...) STARTUP_LOGV(LE_LOG_FILE, LE_LABEL, fmt, ##__VA_ARGS__) #define LE_LOGV(fmt, ...) STARTUP_LOGV(LE_LABEL, fmt, ##__VA_ARGS__)
#define LE_CHECK(ret, exper, ...) \ #define LE_CHECK(ret, exper, ...) \
if (!(ret)) { \ if (!(ret)) { \
......
...@@ -98,8 +98,7 @@ ohos_shared_library("param_client") { ...@@ -98,8 +98,7 @@ ohos_shared_library("param_client") {
"//base/startup/init_lite/services/loopevent/include", "//base/startup/init_lite/services/loopevent/include",
] ]
defines = [ "INIT_AGENT" ] defines = [ "_GNU_SOURCE" ]
defines += [ "_GNU_SOURCE" ]
if (build_selinux) { if (build_selinux) {
defines += [ "WITH_SELINUX" ] defines += [ "WITH_SELINUX" ]
......
...@@ -80,11 +80,10 @@ typedef enum { ...@@ -80,11 +80,10 @@ typedef enum {
#define PARAM_CLEAR_FLAG(node, flag) ((node) &= ~(flag)) #define PARAM_CLEAR_FLAG(node, flag) ((node) &= ~(flag))
#define PARAM_TEST_FLAG(node, flag) (((node) & (flag)) == (flag)) #define PARAM_TEST_FLAG(node, flag) (((node) & (flag)) == (flag))
#define PARAN_LOG_FILE "param.log"
#define PARAN_LABEL "PARAM" #define PARAN_LABEL "PARAM"
#define PARAM_LOGI(fmt, ...) STARTUP_LOGI(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_LOG_FILE, PARAN_LABEL, fmt, ##__VA_ARGS__) #define PARAM_LOGE(fmt, ...) STARTUP_LOGE(PARAN_LABEL, fmt, ##__VA_ARGS__)
#define PARAM_LOGV(fmt, ...) STARTUP_LOGV(PARAN_LOG_FILE, PARAN_LABEL, fmt, ##__VA_ARGS__) #define PARAM_LOGV(fmt, ...) STARTUP_LOGV(PARAN_LABEL, fmt, ##__VA_ARGS__)
#define PARAM_CHECK(retCode, exper, ...) \ #define PARAM_CHECK(retCode, exper, ...) \
if (!(retCode)) { \ if (!(retCode)) { \
......
...@@ -37,8 +37,6 @@ ohos_shared_library("param_watcheragent") { ...@@ -37,8 +37,6 @@ ohos_shared_library("param_watcheragent") {
"//base/startup/init_lite/services/loopevent/include", "//base/startup/init_lite/services/loopevent/include",
] ]
defines = [ "INIT_AGENT" ]
deps = [ deps = [
"//base/startup/init_lite/services/log:agent_log", "//base/startup/init_lite/services/log:agent_log",
"//base/startup/init_lite/services/param:param_client", "//base/startup/init_lite/services/param:param_client",
...@@ -83,8 +81,6 @@ ohos_shared_library("param_watcher") { ...@@ -83,8 +81,6 @@ ohos_shared_library("param_watcher") {
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include",
] ]
defines = [ "INIT_AGENT" ]
deps = [ deps = [
"//base/startup/init_lite/services/log:agent_log", "//base/startup/init_lite/services/log:agent_log",
"//base/startup/init_lite/services/param:param_client", "//base/startup/init_lite/services/param:param_client",
......
...@@ -26,11 +26,10 @@ ...@@ -26,11 +26,10 @@
namespace OHOS { namespace OHOS {
namespace init_param { namespace init_param {
#define UNUSED(x) (void)(x) #define UNUSED(x) (void)(x)
#define WATCHER_LOG_FILE "param_watcher.log"
#define WATCHER_LABEL "PARAM_WATCHER" #define WATCHER_LABEL "PARAM_WATCHER"
#define WATCHER_LOGI(fmt, ...) STARTUP_LOGI(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_LOG_FILE, WATCHER_LABEL, fmt, ##__VA_ARGS__) #define WATCHER_LOGE(fmt, ...) STARTUP_LOGE(WATCHER_LABEL, fmt, ##__VA_ARGS__)
#define WATCHER_LOGV(fmt, ...) STARTUP_LOGV(WATCHER_LOG_FILE, WATCHER_LABEL, fmt, ##__VA_ARGS__) #define WATCHER_LOGV(fmt, ...) STARTUP_LOGV(WATCHER_LABEL, fmt, ##__VA_ARGS__)
#define WATCHER_CHECK(retCode, exper, ...) \ #define WATCHER_CHECK(retCode, exper, ...) \
if (!(retCode)) { \ if (!(retCode)) { \
......
...@@ -29,11 +29,10 @@ typedef struct { ...@@ -29,11 +29,10 @@ typedef struct {
} PluginCmd; } PluginCmd;
#define READ_DURATION 100000 #define READ_DURATION 100000
#define PLUGIN_LOG_FILE "plugintest.log"
#define PLUGIN_LABEL "PLUGIN" #define PLUGIN_LABEL "PLUGIN"
#define PLUGIN_LOGI(fmt, ...) STARTUP_LOGI(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_LOG_FILE, PLUGIN_LABEL, fmt, ##__VA_ARGS__) #define PLUGIN_LOGE(fmt, ...) STARTUP_LOGE(PLUGIN_LABEL, fmt, ##__VA_ARGS__)
#define PLUGIN_LOGV(fmt, ...) STARTUP_LOGV(PLUGIN_LOG_FILE, PLUGIN_LABEL, fmt, ##__VA_ARGS__) #define PLUGIN_LOGV(fmt, ...) STARTUP_LOGV(PLUGIN_LABEL, fmt, ##__VA_ARGS__)
#define PLUGIN_CHECK(ret, exper, ...) \ #define PLUGIN_CHECK(ret, exper, ...) \
if (!(ret)) { \ if (!(ret)) { \
......
...@@ -26,7 +26,6 @@ if (defined(ohos_lite)) { ...@@ -26,7 +26,6 @@ if (defined(ohos_lite)) {
] ]
deps = [ deps = [
"//base/startup/init_lite/services/log:init_log",
"//third_party/bounds_checking_function:libsec_static", "//third_party/bounds_checking_function:libsec_static",
] ]
defines = [ "_GNU_SOURCE" ] defines = [ "_GNU_SOURCE" ]
...@@ -47,10 +46,7 @@ if (defined(ohos_lite)) { ...@@ -47,10 +46,7 @@ if (defined(ohos_lite)) {
"//base/startup/init_lite/services/include", "//base/startup/init_lite/services/include",
] ]
deps = [ deps = [ "//third_party/bounds_checking_function:libsec_static" ]
"//base/startup/init_lite/services/log:init_log",
"//third_party/bounds_checking_function:libsec_static",
]
defines = [ "_GNU_SOURCE" ] defines = [ "_GNU_SOURCE" ]
part_name = "init" part_name = "init"
} }
...@@ -65,10 +61,7 @@ if (defined(ohos_lite)) { ...@@ -65,10 +61,7 @@ if (defined(ohos_lite)) {
"//base/startup/init_lite/services/include", "//base/startup/init_lite/services/include",
] ]
deps = [ deps = [ "//third_party/bounds_checking_function:libsec_static" ]
"//base/startup/init_lite/services/log:init_log",
"//third_party/bounds_checking_function:libsec_static",
]
defines = [ "_GNU_SOURCE" ] defines = [ "_GNU_SOURCE" ]
part_name = "init" part_name = "init"
} }
......
...@@ -24,6 +24,7 @@ if (defined(ohos_lite)) { ...@@ -24,6 +24,7 @@ if (defined(ohos_lite)) {
"//base/startup/init_lite/ueventd/ueventd_main.c", "//base/startup/init_lite/ueventd/ueventd_main.c",
"//base/startup/init_lite/ueventd/ueventd_read_cfg.c", "//base/startup/init_lite/ueventd/ueventd_read_cfg.c",
"//base/startup/init_lite/ueventd/ueventd_socket.c", "//base/startup/init_lite/ueventd/ueventd_socket.c",
"//base/startup/init_lite/interfaces/innerkits/socket/init_socket.c"
] ]
defines = [ "__MUSL__" ] defines = [ "__MUSL__" ]
...@@ -39,7 +40,6 @@ if (defined(ohos_lite)) { ...@@ -39,7 +40,6 @@ if (defined(ohos_lite)) {
] ]
deps = [ deps = [
"//base/startup/init_lite/interfaces/innerkits/socket:libsocket_static",
"//base/startup/init_lite/services/log:init_log", "//base/startup/init_lite/services/log:init_log",
"//third_party/bounds_checking_function:libsec_static", "//third_party/bounds_checking_function:libsec_static",
] ]
...@@ -69,6 +69,7 @@ if (defined(ohos_lite)) { ...@@ -69,6 +69,7 @@ if (defined(ohos_lite)) {
"//base/startup/init_lite/ueventd/ueventd_firmware_handler.c", "//base/startup/init_lite/ueventd/ueventd_firmware_handler.c",
"//base/startup/init_lite/ueventd/ueventd_read_cfg.c", "//base/startup/init_lite/ueventd/ueventd_read_cfg.c",
"//base/startup/init_lite/ueventd/ueventd_socket.c", "//base/startup/init_lite/ueventd/ueventd_socket.c",
"//base/startup/init_lite/interfaces/innerkits/socket/init_socket.c"
] ]
service_ueventd_include = [ service_ueventd_include = [
...@@ -81,7 +82,6 @@ if (defined(ohos_lite)) { ...@@ -81,7 +82,6 @@ if (defined(ohos_lite)) {
] ]
service_ueventd_deps = [ 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/log:init_log",
"//base/startup/init_lite/services/utils:libinit_utils", "//base/startup/init_lite/services/utils:libinit_utils",
"//third_party/bounds_checking_function:libsec_static", "//third_party/bounds_checking_function:libsec_static",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册