diff --git a/platform/BUILD.gn b/platform/BUILD.gn index e9228feef3eab7c951de6b7ad5591a2f5e39f7a1..e26afe7457781da82390825e5339c944cb97259b 100644 --- a/platform/BUILD.gn +++ b/platform/BUILD.gn @@ -22,12 +22,11 @@ template("libhilog_platform_source") { include_dirs = [ "${PLATFORM_HILOG_PATH}/frameworks/libhilog/param/include", "${PLATFORM_HILOG_PATH}/interfaces/native/innerkits/include", + "${PLATFORM_ACE_ENGINE_ROOT}/frameworks", ] if (target_os == "android") { defines += [ "ANDROID_PLATFORM" ] - libs = [ "log" ] } else if (target_os == "ios") { - include_dirs += [ "//third_party/bounds_checking_function/include" ] defines += [ "IOS_PLATFORM" ] } sources = [ diff --git a/platform/hilog_printf.cpp b/platform/hilog_printf.cpp index eab43d483f8f3e0b40d068d2e5a1083798f47f88..d5652f3c940c0bfe08f2136eef35929614b64b60 100644 --- a/platform/hilog_printf.cpp +++ b/platform/hilog_printf.cpp @@ -16,21 +16,22 @@ #include "hilog/log.h" #include "interface/native/log.h" -static OHOS::HiviewDFX::Hilog::Platform::LogLevel ConvertLogLevel(LogLevel level) +static OHOS::Ace::LogLevel ConvertLogLevel(LogLevel level) { - if (level == LogLevel::LOG_DEBUG) { - return OHOS::HiviewDFX::Hilog::Platform::LogLevel::Debug; - } else if (level == LogLevel::LOG_INFO) { - return OHOS::HiviewDFX::Hilog::Platform::LogLevel::Info; - } else if (level == LogLevel::LOG_WARN) { - return OHOS::HiviewDFX::Hilog::Platform::LogLevel::Warn; - } else if (level == LogLevel::LOG_ERROR) { - return OHOS::HiviewDFX::Hilog::Platform::LogLevel::Error; - } else if (level == LogLevel::LOG_FATAL) { - return OHOS::HiviewDFX::Hilog::Platform::LogLevel::Fatal; + switch (level) { + case LogLevel::LOG_DEBUG: + return OHOS::Ace::LogLevel::DEBUG; + case LogLevel::LOG_INFO: + return OHOS::Ace::LogLevel::INFO; + case LogLevel::LOG_WARN: + return OHOS::Ace::LogLevel::WARN; + case LogLevel::LOG_ERROR: + return OHOS::Ace::LogLevel::ERROR; + case LogLevel::LOG_FATAL: + return OHOS::Ace::LogLevel::FATAL; + default: + return OHOS::Ace::LogLevel::DEBUG; } - - return OHOS::HiviewDFX::Hilog::Platform::LogLevel::Debug; } int HiLogPrintArgs(const LogType type, const LogLevel level, const unsigned int domain, const char *tag, diff --git a/platform/interface/native/log.cpp b/platform/interface/native/log.cpp index 470a9d3bc0c2cf1d1abd5f75a316f37686ee8777..71821c35d3e128088799d00e13dd49698493056a 100644 --- a/platform/interface/native/log.cpp +++ b/platform/interface/native/log.cpp @@ -13,25 +13,11 @@ * limitations under the License. */ +#include "base/log/log.h" #include "log.h" -#if defined(ANDROID_PLATFORM) -#include -#endif - -#if defined(IOS_PLATFORM) -#include -#import -#endif namespace OHOS::HiviewDFX::Hilog::Platform { -[[maybe_unused]] static void StripFormatString(const std::string& prefix, std::string& str) -{ - for (auto pos = str.find(prefix, 0); pos != std::string::npos; pos = str.find(prefix, pos)) { - str.erase(pos, prefix.size()); - } -} - -void LogPrint(LogLevel level, const char* fmt, ...) +void LogPrint(OHOS::Ace::LogLevel level, const char* fmt, ...) { va_list args; va_start(args, fmt); @@ -39,39 +25,9 @@ void LogPrint(LogLevel level, const char* fmt, ...) va_end(args); } -#if defined(ANDROID_PLATFORM) -constexpr int32_t LOG_LEVEL[] = { ANDROID_LOG_DEBUG, ANDROID_LOG_INFO, ANDROID_LOG_WARN, ANDROID_LOG_ERROR, - ANDROID_LOG_FATAL }; - -void LogPrint(LogLevel level, const char* fmt, va_list args) -{ - std::string newFmt(fmt); - StripFormatString("{public}", newFmt); - StripFormatString("{private}", newFmt); - __android_log_vprint(LOG_LEVEL[static_cast(level)], DFX_PLATFORM_LOG_TAG, newFmt.c_str(), args); -} -#endif - -#if defined(IOS_PLATFORM) -constexpr uint32_t MAX_BUFFER_SIZE = 4096; -constexpr os_log_type_t LOG_TYPE[] = {OS_LOG_TYPE_DEBUG, OS_LOG_TYPE_INFO, OS_LOG_TYPE_DEFAULT, OS_LOG_TYPE_ERROR, - OS_LOG_TYPE_FAULT}; -constexpr const char* LOG_TYPE_NAME[] = { "DEBUG", "INFO", "WARNING", "ERROR", "FATAL" }; - -void LogPrint(LogLevel level, const char* fmt, va_list args) +void LogPrint(OHOS::Ace::LogLevel level, const char* fmt, va_list args) { - std::string newFmt(fmt); - StripFormatString("{public}", newFmt); - StripFormatString("{private}", newFmt); - char buf[MAX_BUFFER_SIZE] = { '\0' }; - int ret = vsnprintf_s(buf, sizeof(buf), sizeof(buf) - 1, newFmt.c_str(), args); - if (ret < 0) { - return; - } - os_log_type_t logType = LOG_TYPE[static_cast(level)]; - const char* levelName = LOG_TYPE_NAME[static_cast(level)]; - os_log_t log = os_log_create(DFX_PLATFORM_LOG_TAG, levelName); - os_log(log, "[%{public}s] %{public}s", levelName, buf); + OHOS::Ace::LogWrapper::PrintLog(OHOS::Ace::LogDomain::JS_APP, level, + OHOS::Ace::AceLogTag::DEFAULT, fmt, args); } -#endif } // namespace OHOS::HiviewDFX::Hilog::Platform \ No newline at end of file diff --git a/platform/interface/native/log.h b/platform/interface/native/log.h index b59d07c96f88d8b1193444873a6c6fbd9e742da8..62137183ce72cd7a0c5871f057ca095eeeb302b5 100644 --- a/platform/interface/native/log.h +++ b/platform/interface/native/log.h @@ -18,6 +18,7 @@ #include #include +#include "base/log/log.h" #define __FILENAME__ strrchr(__FILE__, '/') + 1 @@ -31,18 +32,12 @@ enum class LogLevel : uint32_t { Fatal, }; -void LogPrint(LogLevel level, const char* fmt, ...); -void LogPrint(LogLevel level, const char* fmt, va_list args); +void LogPrint(OHOS::Ace::LogLevel level, const char* fmt, ...); +void LogPrint(OHOS::Ace::LogLevel level, const char* fmt, va_list args); #define LOG_PRINT(Level, fmt, ...) \ - OHOS::HiviewDFX::Hilog::Platform::LogPrint(OHOS::HiviewDFX::Hilog::Platform::LogLevel::Level, \ + OHOS::Ace::Platform::LogPrint(OHOS::HiviewDFX::Hilog::Platform::LogLevel::Level, \ "[%-20s(%s)] " fmt, __FILENAME__, __FUNCTION__, ##__VA_ARGS__) - -#define LOGF(fmt, ...) LOG_PRINT(Fatal, fmt, ##__VA_ARGS__) -#define LOGE(fmt, ...) LOG_PRINT(Error, fmt, ##__VA_ARGS__) -#define LOGW(fmt, ...) LOG_PRINT(Warn, fmt, ##__VA_ARGS__) -#define LOGI(fmt, ...) LOG_PRINT(Info, fmt, ##__VA_ARGS__) -#define LOGD(fmt, ...) LOG_PRINT(Debug, fmt, ##__VA_ARGS__) } // namespace OHOS::HiviewDFX::Hilog::Platform #endif // PLATFORM_INTERFACE_NATIVE_LOG_H diff --git a/platformlog.gni b/platformlog.gni index d4e272f0b58666f1487b2f8adef12fc3b72aa699..a494dd430337dd3639d2a7a95a0de3f2b924b2f9 100644 --- a/platformlog.gni +++ b/platformlog.gni @@ -12,3 +12,5 @@ # limitations under the License. PLATFORM_HILOG_PATH = "//base/hiviewdfx/hilog" + +PLATFORM_ACE_ENGINE_ROOT = "//foundation/arkui/ace_engine"