1e509ee18Sopenharmony_ci/* 2e509ee18Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3e509ee18Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e509ee18Sopenharmony_ci * you may not use this file except in compliance with the License. 5e509ee18Sopenharmony_ci * You may obtain a copy of the License at 6e509ee18Sopenharmony_ci * 7e509ee18Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e509ee18Sopenharmony_ci * 9e509ee18Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e509ee18Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e509ee18Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e509ee18Sopenharmony_ci * See the License for the specific language governing permissions and 13e509ee18Sopenharmony_ci * limitations under the License. 14e509ee18Sopenharmony_ci */ 15e509ee18Sopenharmony_ci 16e509ee18Sopenharmony_ci#ifndef ARKCOMPILER_TOOLCHAIN_COMMON_LOG_WRAPPER_H 17e509ee18Sopenharmony_ci#define ARKCOMPILER_TOOLCHAIN_COMMON_LOG_WRAPPER_H 18e509ee18Sopenharmony_ci 19e509ee18Sopenharmony_ci#include "common/macros.h" 20e509ee18Sopenharmony_ci 21e509ee18Sopenharmony_ci#if defined(ENABLE_HILOG) 22e509ee18Sopenharmony_ci#if defined(__clang__) 23e509ee18Sopenharmony_ci#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" 24e509ee18Sopenharmony_ci#elif defined(__GNUC__) 25e509ee18Sopenharmony_ci#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" 26e509ee18Sopenharmony_ci#endif 27e509ee18Sopenharmony_ci#include "hilog/log.h" 28e509ee18Sopenharmony_ci#endif 29e509ee18Sopenharmony_ci#undef LOG_DOMAIN 30e509ee18Sopenharmony_ci#define LOG_DOMAIN 0xD003F00 31e509ee18Sopenharmony_ci#undef LOG_TAG 32e509ee18Sopenharmony_ci#define LOG_TAG "ArkCompiler" 33e509ee18Sopenharmony_ci 34e509ee18Sopenharmony_cinamespace OHOS::ArkCompiler::Toolchain { 35e509ee18Sopenharmony_ci#ifdef LOGF 36e509ee18Sopenharmony_ci#undef LOGF 37e509ee18Sopenharmony_ci#endif 38e509ee18Sopenharmony_ci#ifdef LOGE 39e509ee18Sopenharmony_ci#undef LOGE 40e509ee18Sopenharmony_ci#endif 41e509ee18Sopenharmony_ci#ifdef LOGW 42e509ee18Sopenharmony_ci#undef LOGW 43e509ee18Sopenharmony_ci#endif 44e509ee18Sopenharmony_ci#ifdef LOGI 45e509ee18Sopenharmony_ci#undef LOGI 46e509ee18Sopenharmony_ci#endif 47e509ee18Sopenharmony_ci#ifdef LOGD 48e509ee18Sopenharmony_ci#undef LOGD 49e509ee18Sopenharmony_ci#endif 50e509ee18Sopenharmony_ci 51e509ee18Sopenharmony_ci#if !defined(ENABLE_HILOG) 52e509ee18Sopenharmony_cienum class LogLevel { 53e509ee18Sopenharmony_ci UNKNOWN, 54e509ee18Sopenharmony_ci DEFAULT, 55e509ee18Sopenharmony_ci VERBOSE, 56e509ee18Sopenharmony_ci DEBUG, 57e509ee18Sopenharmony_ci INFO, 58e509ee18Sopenharmony_ci WARN, 59e509ee18Sopenharmony_ci ERROR, 60e509ee18Sopenharmony_ci FATAL 61e509ee18Sopenharmony_ci}; 62e509ee18Sopenharmony_ciclass TOOLCHAIN_EXPORT StdLog { 63e509ee18Sopenharmony_cipublic: 64e509ee18Sopenharmony_ci StdLog() = default; 65e509ee18Sopenharmony_ci ~StdLog() = default; 66e509ee18Sopenharmony_ci 67e509ee18Sopenharmony_ci static void PrintLog(LogLevel level, const char* fmt, ...); 68e509ee18Sopenharmony_ci}; 69e509ee18Sopenharmony_ci#endif 70e509ee18Sopenharmony_ci 71e509ee18Sopenharmony_ci#pragma clang diagnostic push 72e509ee18Sopenharmony_ci#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" 73e509ee18Sopenharmony_ci#if !defined(ENABLE_HILOG) 74e509ee18Sopenharmony_ci#define LOGF(fmt, ...) StdLog::PrintLog(LogLevel::FATAL, fmt, ##__VA_ARGS__) 75e509ee18Sopenharmony_ci#define LOGE(fmt, ...) StdLog::PrintLog(LogLevel::ERROR, fmt, ##__VA_ARGS__) 76e509ee18Sopenharmony_ci#define LOGW(fmt, ...) StdLog::PrintLog(LogLevel::WARN, fmt, ##__VA_ARGS__) 77e509ee18Sopenharmony_ci#define LOGI(fmt, ...) StdLog::PrintLog(LogLevel::INFO, fmt, ##__VA_ARGS__) 78e509ee18Sopenharmony_ci#define LOGD(fmt, ...) StdLog::PrintLog(LogLevel::DEBUG, fmt, ##__VA_ARGS__) 79e509ee18Sopenharmony_ci#else 80e509ee18Sopenharmony_ci#define LOGF(fmt, ...) HILOG_FATAL(LOG_CORE, fmt, ##__VA_ARGS__) 81e509ee18Sopenharmony_ci#define LOGE(fmt, ...) HILOG_ERROR(LOG_CORE, fmt, ##__VA_ARGS__) 82e509ee18Sopenharmony_ci#define LOGW(fmt, ...) HILOG_WARN(LOG_CORE, fmt, ##__VA_ARGS__) 83e509ee18Sopenharmony_ci#define LOGI(fmt, ...) HILOG_INFO(LOG_CORE, fmt, ##__VA_ARGS__) 84e509ee18Sopenharmony_ci#define LOGD(fmt, ...) HILOG_DEBUG(LOG_CORE, fmt, ##__VA_ARGS__) 85e509ee18Sopenharmony_ci#endif 86e509ee18Sopenharmony_ci#pragma clang diagnostic pop 87e509ee18Sopenharmony_ci} // namespace OHOS::ArkCompiler::Toolchain 88e509ee18Sopenharmony_ci#endif // ARKCOMPILER_TOOLCHAIN_COMMON_LOG_WRAPPER_H 89