diff --git a/BUILD.gn b/BUILD.gn index d238ab396a6699d93b0e92bc52e3d6e24f89c175..bc17ca5c3acf4644cf03659e12455721d26b4469 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 (libuv_use_hilog_impl && is_ohos) { + defines += [ "USE_HILOG_IMPL" ] + } } else if (is_mingw || is_win) { cflags += [ "-Wno-missing-braces", @@ -345,6 +349,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..7096931c12e96f041d6b962241dfcc39289e98fa 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 + libuv_use_hilog_impl = 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..1c6d2e57101d2af21b5701e530bba9bfa8cdc034 100644 --- a/src/uv_log.h +++ b/src/uv_log.h @@ -18,9 +18,18 @@ * IN THE SOFTWARE. */ +#include "ilog/log.h" + #ifndef UV_LOG_H #define UV_LOG_H +#ifdef USE_HILOG_IMPL +#define UV_LOGI(fmt, ...) HIHLOG_IMPL(LOG_CORE, LOG_INFO, 0xD00394F, "UV", fmt, ##__VA_ARGS__) +#define UV_LOGD(fmt, ...) HIHLOG_IMPL(LOG_CORE, LOG_DEBUG, 0xD00394F, "UV", fmt, ##__VA_ARGS__) +#define UV_LOGW(fmt, ...) HIHLOG_IMPL(LOG_CORE, LOG_WARN, 0xD00394F, "UV", fmt, ##__VA_ARGS__) +#define UV_LOGE(fmt, ...) HIHLOG_IMPL(LOG_CORE, LOG_ERROR, 0xD00394F, "UV", fmt, ##__VA_ARGS__) +#define UV_LOGF(fmt, ...) HIHLOG_IMPL(LOG_CORE, LOG_FATAL, 0xD00394F, "UV", fmt, ##__VA_ARGS__) +#else enum uv__log_level { UV_MIN = 0, UV_DEBUG = 3, @@ -40,5 +49,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