From 90818c92eec5f35e287632586772348b99147cf6 Mon Sep 17 00:00:00 2001 From: limeng1210 Date: Sat, 3 Sep 2022 18:54:30 +0800 Subject: [PATCH] Linux Preview Signed-off-by: limeng1210 --- frameworks/libhilog/BUILD.gn | 9 ++++++--- frameworks/libhilog/hilog_printf.cpp | 14 +++++++++----- frameworks/libhilog/include/hilog_common.h | 1 + frameworks/libhilog/utils/include/log_utils.h | 2 +- frameworks/libhilog/utils/log_utils.cpp | 4 ++-- hilog.gni | 1 + interfaces/native/innerkits/BUILD.gn | 2 +- 7 files changed, 21 insertions(+), 12 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..c3c0362 100644 --- a/frameworks/libhilog/hilog_printf.cpp +++ b/frameworks/libhilog/hilog_printf.cpp @@ -21,6 +21,10 @@ #include #include +#ifdef __LINUX__ +#include +#endif + #ifndef __WINDOWS__ #include #else @@ -37,7 +41,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 +88,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 +103,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 +210,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 +262,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..367638c 100644 --- a/frameworks/libhilog/include/hilog_common.h +++ b/frameworks/libhilog/include/hilog_common.h @@ -16,6 +16,7 @@ #ifndef HILOG_COMMON_H #define HILOG_COMMON_H +#include #include #include #include diff --git a/frameworks/libhilog/utils/include/log_utils.h b/frameworks/libhilog/utils/include/log_utils.h index e46e0e0..acd6746 100644 --- a/frameworks/libhilog/utils/include/log_utils.h +++ b/frameworks/libhilog/utils/include/log_utils.h @@ -97,7 +97,7 @@ uint32_t DecStr2Uint(const std::string& str); std::string Uint2HexStr(uint32_t i); uint32_t HexStr2Uint(const std::string& str); -#ifndef __WINDOWS__ +#if !defined(__WINDOWS__) and !defined(__LINUX__) std::string GetProgName(); #endif std::string GetNameByPid(uint32_t pid); diff --git a/frameworks/libhilog/utils/log_utils.cpp b/frameworks/libhilog/utils/log_utils.cpp index f4307e0..d460578 100644 --- a/frameworks/libhilog/utils/log_utils.cpp +++ b/frameworks/libhilog/utils/log_utils.cpp @@ -13,11 +13,11 @@ * limitations under the License. */ #include +#include #include #include #include #include - #include #include @@ -396,7 +396,7 @@ uint32_t HexStr2Uint(const string& str) return i; } -#ifndef __WINDOWS__ +#if !defined(__WINDOWS__) and !defined(__LINUX__) string GetProgName() { #ifdef HILOG_USE_MUSL 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 86ca871..a3ba869 100644 --- a/interfaces/native/innerkits/BUILD.gn +++ b/interfaces/native/innerkits/BUILD.gn @@ -48,7 +48,7 @@ foreach(item, platforms) { platform = item } } - if (item == "windows" || item == "mac") { + if (item == "windows" || item == "mac" || item == "linux") { libhilog("libhilog_" + item) { platform = item } -- Gitee