1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "uv_log.h"
17 #include "hilog/log.h"
18
19 #include <stdarg.h>
20
21 extern int HiLogPrintArgs(const LogType type, const LogLevel level, const unsigned int domain, const char *tag,
22 const char *fmt, va_list ap);
23
convert_uv_log_level(enum uv__log_level level)24 LogLevel convert_uv_log_level(enum uv__log_level level) {
25 switch (level)
26 {
27 case UV_DEBUG:
28 return LOG_DEBUG;
29 case UV_INFO:
30 return LOG_INFO;
31 case UV_WARN:
32 return LOG_WARN;
33 case UV_ERROR:
34 return LOG_ERROR;
35 case UV_FATAL:
36 return LOG_FATAL;
37 default:
38 return LOG_LEVEL_MIN;
39 }
40 }
41
uv__log_impl(enum uv__log_level level,const char * fmt,...)42 int uv__log_impl(enum uv__log_level level, const char *fmt, ...) {
43 va_list args;
44 va_start(args, fmt);
45 int ret = HiLogPrintArgs(LOG_CORE, convert_uv_log_level(level), 0xD003301, "LIBUV", fmt, args);
46 va_end(args);
47 return ret;
48 }