• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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::HiviewDFX::Hilog::Platform::LogLevel ConvertLogLevel(LogLevel level)
20 {
21     if (level == LogLevel::LOG_DEBUG) {
22         return OHOS::HiviewDFX::Hilog::Platform::LogLevel::Debug;
23     } else if (level == LogLevel::LOG_INFO) {
24         return OHOS::HiviewDFX::Hilog::Platform::LogLevel::Info;
25     } else if (level == LogLevel::LOG_WARN) {
26         return OHOS::HiviewDFX::Hilog::Platform::LogLevel::Warn;
27     } else if (level == LogLevel::LOG_ERROR) {
28         return OHOS::HiviewDFX::Hilog::Platform::LogLevel::Error;
29     } else if (level == LogLevel::LOG_FATAL) {
30         return OHOS::HiviewDFX::Hilog::Platform::LogLevel::Fatal;
31     }
32 
33     return OHOS::HiviewDFX::Hilog::Platform::LogLevel::Debug;
34 }
35 
HiLogPrintArgs(const LogType type,const LogLevel level,const unsigned int domain,const char * tag,const char * fmt,va_list ap)36 int HiLogPrintArgs(const LogType type, const LogLevel level, const unsigned int domain, const char *tag,
37     const char *fmt, va_list ap)
38 {
39     OHOS::HiviewDFX::Hilog::Platform::LogPrint(ConvertLogLevel(level), fmt, ap);
40     return 0;
41 }
42 
HiLogPrint(LogType type,LogLevel level,unsigned int domain,const char * tag,const char * fmt,...)43 int HiLogPrint(LogType type, LogLevel level, unsigned int domain, const char *tag, const char *fmt, ...)
44 {
45     int ret;
46     va_list ap;
47     va_start(ap, fmt);
48     ret = HiLogPrintArgs(type, level, domain, tag, fmt, ap);
49     va_end(ap);
50     return ret;
51 }
52 
HiLogIsLoggable(unsigned int domain,const char * tag,LogLevel level)53 bool HiLogIsLoggable(unsigned int domain, const char *tag, LogLevel level)
54 {
55     if ((level <= LOG_LEVEL_MIN) || (level >= LOG_LEVEL_MAX) || tag == nullptr) {
56         return false;
57     }
58 
59     return true;
60 }
61