1 /*
2  * Copyright (c) 2023 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 "hilog/log.h"
17 #include "interface/native/log.h"
18 
ConvertLogLevel(LogLevel level)19 static OHOS::Ace::LogLevel ConvertLogLevel(LogLevel level)
20 {
21     switch (level) {
22         case LogLevel::LOG_DEBUG:
23             return OHOS::Ace::LogLevel::DEBUG;
24         case LogLevel::LOG_INFO:
25             return OHOS::Ace::LogLevel::INFO;
26         case LogLevel::LOG_WARN:
27             return OHOS::Ace::LogLevel::WARN;
28         case LogLevel::LOG_ERROR:
29             return OHOS::Ace::LogLevel::ERROR;
30         case LogLevel::LOG_FATAL:
31             return OHOS::Ace::LogLevel::FATAL;
32         default:
33             return OHOS::Ace::LogLevel::DEBUG;
34     }
35 }
36 
HiLogPrintArgs(const LogType type,const LogLevel level,const unsigned int domain,const char * tag,const char * fmt,va_list ap)37 int HiLogPrintArgs(const LogType type, const LogLevel level, const unsigned int domain, const char *tag,
38     const char *fmt, va_list ap)
39 {
40     OHOS::HiviewDFX::Hilog::Platform::LogPrint(ConvertLogLevel(level), fmt, ap);
41     return 0;
42 }
43 
HiLogPrint(LogType type,LogLevel level,unsigned int domain,const char * tag,const char * fmt,...)44 int HiLogPrint(LogType type, LogLevel level, unsigned int domain, const char *tag, const char *fmt, ...)
45 {
46     int ret;
47     va_list ap;
48     va_start(ap, fmt);
49     ret = HiLogPrintArgs(type, level, domain, tag, fmt, ap);
50     va_end(ap);
51     return ret;
52 }
53 
HiLogIsLoggable(unsigned int domain,const char * tag,LogLevel level)54 bool HiLogIsLoggable(unsigned int domain, const char *tag, LogLevel level)
55 {
56     if ((level <= LOG_LEVEL_MIN) || (level >= LOG_LEVEL_MAX) || tag == nullptr) {
57         return false;
58     }
59 
60     return true;
61 }
62