diff --git a/frameworks/libhilog/BUILD.gn b/frameworks/libhilog/BUILD.gn index 274c3f18a93f174e24fb02d1dca097fb363d497e..fe1a6623f28b1293597e14f5cd228e2a27a2cf48 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 eb8be9db05ed7b3d7016221f37e45485cb4a2b1d..c3c0362ee18dbd87163a93ea56b77aa26299f6ce 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 81f77202cc2fd7d49bce5737450177f0e7c51d96..367638ca892368e48dd535d1b79e118955860ed8 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 e46e0e066ca02c195db67c7e30cff88f9dc2dd0d..acd6746b6b425d69f7284fa70a328722204c7766 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 f4307e09091ed52db476129b2d98de8716c6edc0..d4605788f8c68af67e89a445776425e88f4a669c 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 b3faa93171d001773f21661c74f101e964100308..50b85be0ba33115b0c06f413c5bcd0169bc68257 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 86ca871238beb84b06a5a6b121b0f6ec9799b6e0..a3ba8693ef0fe84da42943baafe7b318981772b6 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 }