From a438dd45684d1fa4bc90c39b8b69f773804ee8f0 Mon Sep 17 00:00:00 2001 From: lixuchuang Date: Fri, 19 Aug 2022 13:09:30 +0800 Subject: [PATCH] add preview Signed-off-by: lixuchuang --- frameworks/libhilog/BUILD.gn | 9 ++++++--- frameworks/libhilog/hilog_printf.cpp | 15 ++++++++++----- frameworks/libhilog/include/hilog_common.h | 1 + frameworks/libhilog/utils/log_utils.cpp | 1 + hilog.gni | 1 + interfaces/native/innerkits/BUILD.gn | 2 +- 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/frameworks/libhilog/BUILD.gn b/frameworks/libhilog/BUILD.gn index 274c3f1..fe1a662 100644 --- a/frameworks/libhilog/BUILD.gn +++ b/frameworks/libhilog/BUILD.gn @@ -42,7 +42,7 @@ config("libhilog_config") { template("libhilog_source") { forward_variables_from(invoker, "*") ohos_source_set(target_name) { - if (platform != "windows" && platform != "mac") { + if (platform != "windows" && platform != "mac" && platform != "linux") { param_sources = [ "$param_root/properties.cpp" ] ioctl_sources = [ "$ioctl_root/log_ioctl.cpp" ] @@ -70,7 +70,7 @@ template("libhilog_source") { "hilog.cpp", "hilog_printf.cpp", ] - if (platform != "windows" && platform != "mac") { + if (platform != "windows" && platform != "mac" && platform != "linux") { sources += param_sources sources += ioctl_sources sources += socket_sources @@ -84,6 +84,9 @@ template("libhilog_source") { defines += [ "__WINDOWS__" ] } else if (platform == "mac") { defines += [ "__MAC__" ] + } else if (platform == "linux") { + cflags_cc = [ "-std=c++17" ] + defines += [ "__LINUX__" ] } else { defines = [ "__RECV_MSG_WITH_UCRED_" ] if (use_musl) { @@ -95,7 +98,7 @@ template("libhilog_source") { deps = [ "//third_party/bounds_checking_function:libsec_shared" ] - if (platform != "windows" && platform != "mac") { + if (platform != "windows" && platform != "mac" && platform != "linux") { external_deps = [ "init:libbegetutil" ] } diff --git a/frameworks/libhilog/hilog_printf.cpp b/frameworks/libhilog/hilog_printf.cpp index eb8be9d..990d6ac 100644 --- a/frameworks/libhilog/hilog_printf.cpp +++ b/frameworks/libhilog/hilog_printf.cpp @@ -21,6 +21,11 @@ #include #include +#ifdef __LINUX__ +#include +#endif + + #ifndef __WINDOWS__ #include #else @@ -37,7 +42,7 @@ #include "vsnprintf_s_p.h" #include "log_utils.h" -#if not (defined( __WINDOWS__ ) || defined( __MAC__ )) +#if not (defined( __WINDOWS__ ) || defined( __MAC__ ) || defined( __LINUX__ )) #include "properties.h" #include "hilog_input_socket_client.h" #else @@ -84,7 +89,7 @@ static uint16_t GetFinalLevel(unsigned int domain, const std::string& tag) { // Priority: TagLevel > DomainLevel > GlobalLevel // LOG_LEVEL_MIN is default Level -#if not (defined( __WINDOWS__ ) || defined( __MAC__ )) +#if not (defined( __WINDOWS__ ) || defined( __MAC__ ) || defined( __LINUX__ )) uint16_t tagLevel = GetTagLevel(tag); if (tagLevel != LOG_LEVEL_MIN) { return tagLevel; @@ -99,7 +104,7 @@ static uint16_t GetFinalLevel(unsigned int domain, const std::string& tag) #endif } -#if not (defined( __WINDOWS__ ) || defined( __MAC__ )) +#if not (defined( __WINDOWS__ ) || defined( __MAC__ ) || defined( __LINUX__ )) static int HiLogFlowCtrlProcess(int len, const struct timespec &ts, bool debug) { static uint32_t processQuota = 0; @@ -206,7 +211,7 @@ int HiLogPrintArgs(const LogType type, const LogLevel level, const unsigned int } /* format log string */ -#if not (defined( __WINDOWS__ ) || defined( __MAC__ )) +#if not (defined( __WINDOWS__ ) || defined( __MAC__ ) || defined( __LINUX__ )) bool debug = IsDebugOn(); bool priv = (!debug) && IsPrivateSwitchOn(); #else @@ -258,7 +263,7 @@ int HiLogPrintArgs(const LogType type, const LogLevel level, const unsigned int (void)memcpy_s(g_hiLogLastFatalMessage, sizeof(g_hiLogLastFatalMessage), buf, sizeof(buf)); } -#if not (defined( __WINDOWS__ ) || defined( __MAC__ )) +#if not (defined( __WINDOWS__ ) || defined( __MAC__ ) || defined( __LINUX__ )) /* flow control */ if (IsProcessSwitchOn()) { ret = HiLogFlowCtrlProcess(tagLen + logLen - traceBufLen, ts_mono, debug); diff --git a/frameworks/libhilog/include/hilog_common.h b/frameworks/libhilog/include/hilog_common.h index 81f7720..e6cdd5e 100644 --- a/frameworks/libhilog/include/hilog_common.h +++ b/frameworks/libhilog/include/hilog_common.h @@ -17,6 +17,7 @@ #define HILOG_COMMON_H #include +#include #include #include #include diff --git a/frameworks/libhilog/utils/log_utils.cpp b/frameworks/libhilog/utils/log_utils.cpp index 47f6516..cc43f67 100644 --- a/frameworks/libhilog/utils/log_utils.cpp +++ b/frameworks/libhilog/utils/log_utils.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include diff --git a/hilog.gni b/hilog.gni index b3faa93..50b85be 100644 --- a/hilog.gni +++ b/hilog.gni @@ -15,4 +15,5 @@ platforms = [ "ohos", "windows", "mac", + "linux", ] diff --git a/interfaces/native/innerkits/BUILD.gn b/interfaces/native/innerkits/BUILD.gn index ecce4ed..c01daf4 100644 --- a/interfaces/native/innerkits/BUILD.gn +++ b/interfaces/native/innerkits/BUILD.gn @@ -49,7 +49,7 @@ foreach(item, platforms) { platform = item } } - if (item == "windows" || item == "mac") { + if (item == "windows" || item == "mac" || item == "linux") { libhilog("libhilog_" + item) { platform = item } -- Gitee