diff --git a/BUILD.gn b/BUILD.gn index d238ab396a6699d93b0e92bc52e3d6e24f89c175..d21817be32723a6d0a1527d0dc729f15b3f3608c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -192,6 +192,10 @@ if (defined(ohos_lite)) { cflags += [ "-Wno-frame-address" ] # for use of __builtin_return_address } + + if (use_ohos_dfx && is_ohos) { + defines += [ "USE_OHOS_DFX" ] + } } else if (is_mingw || is_win) { cflags += [ "-Wno-missing-braces", @@ -292,10 +296,7 @@ if (defined(ohos_lite)) { external_deps += [ "ffrt:libffrt" ] } if (is_ohos) { - sources += [ - "src/unix/ohos/log_ohos.c", - "src/unix/ohos/trace_ohos.c", - ] + sources += [ "src/unix/ohos/trace_ohos.c" ] external_deps += [ "hilog:libhilog", "hitrace:hitrace_meter", @@ -345,6 +346,7 @@ if (defined(ohos_lite)) { } ohos_shared_library("uv") { deps = [ ":libuv_source" ] + external_deps = [ "hilog:libhilog" ] public_configs = [ ":libuv_config" ] subsystem_name = "thirdparty" innerapi_tags = [ "platformsdk" ] diff --git a/libuv.gni b/libuv.gni index bb909a47151aa7b496afd867e14dae3137665ad0..9fed6ba309c09c6e405906dbfe8ca5023e50f175 100644 --- a/libuv.gni +++ b/libuv.gni @@ -16,4 +16,5 @@ declare_args() { enable_async_stack = true enable_uv_statisic = false enable_print_errno_abort = true + use_ohos_dfx = true } diff --git a/src/unix/ohos/log_ohos.c b/src/unix/ohos/log_ohos.c deleted file mode 100644 index 6c6872e6b7c4d85b4da586f591306dcf0826829c..0000000000000000000000000000000000000000 --- a/src/unix/ohos/log_ohos.c +++ /dev/null @@ -1,53 +0,0 @@ -/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -#include "uv_log.h" -#include "hilog/log.h" - -#include - -extern int HiLogPrintArgs(const LogType type, const LogLevel level, const unsigned int domain, const char *tag, - const char *fmt, va_list ap); - -LogLevel convert_uv_log_level(enum uv__log_level level) { - switch (level) - { - case UV_DEBUG: - return LOG_DEBUG; - case UV_INFO: - return LOG_INFO; - case UV_WARN: - return LOG_WARN; - case UV_ERROR: - return LOG_ERROR; - case UV_FATAL: - return LOG_FATAL; - default: - return LOG_LEVEL_MIN; - } -} - -int uv__log_impl(enum uv__log_level level, const char *fmt, ...) { - va_list args; - va_start(args, fmt); - int ret = HiLogPrintArgs(LOG_CORE, convert_uv_log_level(level), 0xD003900, "UV", fmt, args); - va_end(args); - return ret; -} diff --git a/src/uv_log.h b/src/uv_log.h index edf6b477eb72b82e054e41cb799272c4166fa8c9..3ba54091cb089f78b614584f0ef4bcb0385cbb56 100644 --- a/src/uv_log.h +++ b/src/uv_log.h @@ -21,6 +21,14 @@ #ifndef UV_LOG_H #define UV_LOG_H +#ifdef USE_OHOS_DFX +#include "hilog/log.h" +#define UV_LOGI(fmt, ...) HILOG_IMPL(LOG_CORE, LOG_INFO, 0xD00394F, "UV", fmt, ##__VA_ARGS__) +#define UV_LOGD(fmt, ...) HILOG_IMPL(LOG_CORE, LOG_DEBUG, 0xD00394F, "UV", fmt, ##__VA_ARGS__) +#define UV_LOGW(fmt, ...) HILOG_IMPL(LOG_CORE, LOG_WARN, 0xD00394F, "UV", fmt, ##__VA_ARGS__) +#define UV_LOGE(fmt, ...) HILOG_IMPL(LOG_CORE, LOG_ERROR, 0xD00394F, "UV", fmt, ##__VA_ARGS__) +#define UV_LOGF(fmt, ...) HILOG_IMPL(LOG_CORE, LOG_FATAL, 0xD00394F, "UV", fmt, ##__VA_ARGS__) +#else enum uv__log_level { UV_MIN = 0, UV_DEBUG = 3, @@ -40,5 +48,6 @@ extern int uv__log_impl(enum uv__log_level level, const char* fmt, ...); #define UV_LOGF(...) LOGI_IMPL(UV_FATAL, ##__VA_ARGS__) #define LOGI_IMPL(level, ...) uv__log_impl(level, ##__VA_ARGS__) +#endif #endif