1 /* 2 * Copyright (C) 2021-2022 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 #ifndef OHOS_DHCP_LOGGER_H 17 #define OHOS_DHCP_LOGGER_H 18 19 #include <stdint.h> 20 #ifdef OHOS_ARCH_LITE 21 #include "hilog/log.h" 22 #else 23 #include "hilog/log_c.h" 24 #include "hilog/log_cpp.h" 25 #endif 26 27 namespace OHOS { 28 namespace DHCP { 29 const unsigned int LOG_ID_DHCP = 0xD001560; 30 const unsigned int LOG_ID_DHCP_DHCP = LOG_ID_DHCP | 0x05; 31 32 #ifdef OHOS_ARCH_LITE 33 34 #define DEFINE_DHCPLOG_DHCP_LABEL(name) \ 35 static constexpr OHOS::HiviewDFX::HiLogLabel DHCP_LOG_LABEL = {LOG_CORE, OHOS::DHCP::LOG_ID_DHCP_DHCP, name} 36 37 #define DHCP_LOGF(...) (void)OHOS::HiviewDFX::HiLog::Fatal(DHCP_LOG_LABEL, ##__VA_ARGS__) 38 #define DHCP_LOGE(...) (void)OHOS::HiviewDFX::HiLog::Error(DHCP_LOG_LABEL, ##__VA_ARGS__) 39 #define DHCP_LOGW(...) (void)OHOS::HiviewDFX::HiLog::Warn(DHCP_LOG_LABEL, ##__VA_ARGS__) 40 #define DHCP_LOGI(...) (void)OHOS::HiviewDFX::HiLog::Info(DHCP_LOG_LABEL, ##__VA_ARGS__) 41 #define DHCP_LOGD(...) (void)OHOS::HiviewDFX::HiLog::Debug(DHCP_LOG_LABEL, ##__VA_ARGS__) 42 43 #else 44 45 struct LogLable { 46 uint32_t dominId; 47 const char* tag; 48 }; 49 50 #define DEFINE_DHCPLOG_DHCP_LABEL(name) \ 51 static constexpr OHOS::DHCP::LogLable DHCP_LOG_LABEL = {OHOS::DHCP::LOG_ID_DHCP_DHCP, name}; 52 53 #define DHCP_LOGF(...) HILOG_IMPL(LOG_CORE, LOG_FATAL, DHCP_LOG_LABEL.dominId, DHCP_LOG_LABEL.tag, __VA_ARGS__) 54 #define DHCP_LOGE(...) HILOG_IMPL(LOG_CORE, LOG_ERROR, DHCP_LOG_LABEL.dominId, DHCP_LOG_LABEL.tag, __VA_ARGS__) 55 #define DHCP_LOGW(...) HILOG_IMPL(LOG_CORE, LOG_WARN, DHCP_LOG_LABEL.dominId, DHCP_LOG_LABEL.tag, __VA_ARGS__) 56 #define DHCP_LOGI(...) HILOG_IMPL(LOG_CORE, LOG_INFO, DHCP_LOG_LABEL.dominId, DHCP_LOG_LABEL.tag, __VA_ARGS__) 57 #define DHCP_LOGD(...) HILOG_IMPL(LOG_CORE, LOG_DEBUG, DHCP_LOG_LABEL.dominId, DHCP_LOG_LABEL.tag, __VA_ARGS__) 58 59 #endif 60 61 #ifndef CHECK_NULL_AND_RETURN 62 #define CHECK_NULL_AND_RETURN(ptr, retValue) \ 63 if (!(ptr)) { \ 64 DHCP_LOGI("Pointer %{public}s in %{public}s is NULL!", #ptr, __func__); \ 65 return retValue; \ 66 } 67 #endif 68 } // namespace DHCP 69 } // namespace OHOS 70 #endif