12498b56bSopenharmony_ci/* 22498b56bSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 32498b56bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 42498b56bSopenharmony_ci * you may not use this file except in compliance with the License. 52498b56bSopenharmony_ci * You may obtain a copy of the License at 62498b56bSopenharmony_ci * 72498b56bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 82498b56bSopenharmony_ci * 92498b56bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 102498b56bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 112498b56bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 122498b56bSopenharmony_ci * See the License for the specific language governing permissions and 132498b56bSopenharmony_ci * limitations under the License. 142498b56bSopenharmony_ci */ 152498b56bSopenharmony_ci 162498b56bSopenharmony_ci#include "hilog/log.h" 172498b56bSopenharmony_ci#include "interface/native/log.h" 182498b56bSopenharmony_ci 192498b56bSopenharmony_cistatic OHOS::Ace::LogLevel ConvertLogLevel(LogLevel level) 202498b56bSopenharmony_ci{ 212498b56bSopenharmony_ci switch (level) { 222498b56bSopenharmony_ci case LogLevel::LOG_DEBUG: 232498b56bSopenharmony_ci return OHOS::Ace::LogLevel::DEBUG; 242498b56bSopenharmony_ci case LogLevel::LOG_INFO: 252498b56bSopenharmony_ci return OHOS::Ace::LogLevel::INFO; 262498b56bSopenharmony_ci case LogLevel::LOG_WARN: 272498b56bSopenharmony_ci return OHOS::Ace::LogLevel::WARN; 282498b56bSopenharmony_ci case LogLevel::LOG_ERROR: 292498b56bSopenharmony_ci return OHOS::Ace::LogLevel::ERROR; 302498b56bSopenharmony_ci case LogLevel::LOG_FATAL: 312498b56bSopenharmony_ci return OHOS::Ace::LogLevel::FATAL; 322498b56bSopenharmony_ci default: 332498b56bSopenharmony_ci return OHOS::Ace::LogLevel::DEBUG; 342498b56bSopenharmony_ci } 352498b56bSopenharmony_ci} 362498b56bSopenharmony_ci 372498b56bSopenharmony_ciint HiLogPrintArgs(const LogType type, const LogLevel level, const unsigned int domain, const char *tag, 382498b56bSopenharmony_ci const char *fmt, va_list ap) 392498b56bSopenharmony_ci{ 402498b56bSopenharmony_ci OHOS::HiviewDFX::Hilog::Platform::LogPrint(ConvertLogLevel(level), fmt, ap); 412498b56bSopenharmony_ci return 0; 422498b56bSopenharmony_ci} 432498b56bSopenharmony_ci 442498b56bSopenharmony_ciint HiLogPrint(LogType type, LogLevel level, unsigned int domain, const char *tag, const char *fmt, ...) 452498b56bSopenharmony_ci{ 462498b56bSopenharmony_ci int ret; 472498b56bSopenharmony_ci va_list ap; 482498b56bSopenharmony_ci va_start(ap, fmt); 492498b56bSopenharmony_ci ret = HiLogPrintArgs(type, level, domain, tag, fmt, ap); 502498b56bSopenharmony_ci va_end(ap); 512498b56bSopenharmony_ci return ret; 522498b56bSopenharmony_ci} 532498b56bSopenharmony_ci 542498b56bSopenharmony_cibool HiLogIsLoggable(unsigned int domain, const char *tag, LogLevel level) 552498b56bSopenharmony_ci{ 562498b56bSopenharmony_ci if ((level <= LOG_LEVEL_MIN) || (level >= LOG_LEVEL_MAX) || tag == nullptr) { 572498b56bSopenharmony_ci return false; 582498b56bSopenharmony_ci } 592498b56bSopenharmony_ci 602498b56bSopenharmony_ci return true; 612498b56bSopenharmony_ci} 62