1 /* 2 * Copyright (C) 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 #ifndef LOG_HELPER_H 16 #define LOG_HELPER_H 17 18 #ifdef DEBUG 19 #include "hilog/log.h" 20 21 #ifdef FatalLog 22 #undef FatalLog 23 #endif 24 25 #ifdef ErrorLog 26 #undef ErrorLog 27 #endif 28 29 #ifdef WarnLog 30 #undef WarnLog 31 #endif 32 33 #ifdef InfoLog 34 #undef InfoLog 35 #endif 36 37 #ifdef DebugLog 38 #undef DebugLog 39 #endif 40 41 #ifndef NFC_LOG_DOMAIN 42 #define NFC_LOG_DOMAIN 0xD000301 43 #endif 44 45 #ifndef NFC_LOG_TAG 46 #define NFC_LOG_TAG "Nfc_Core" 47 #endif 48 49 #ifdef LOG_LABEL 50 #undef LOG_LABEL 51 #endif 52 53 static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = {LOG_CORE, NFC_LOG_DOMAIN, NFC_LOG_TAG}; 54 55 #define FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) 56 57 #define FatalLog(fmt, ...) \ 58 (void)OHOS::HiviewDFX::HiLog::Fatal( \ 59 LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, FILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__) 60 #define ErrorLog(fmt, ...) \ 61 (void)OHOS::HiviewDFX::HiLog::Error( \ 62 LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, FILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__) 63 #define WarnLog(fmt, ...) \ 64 (void)OHOS::HiviewDFX::HiLog::Warn( \ 65 LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, FILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__) 66 #define InfoLog(fmt, ...) \ 67 (void)OHOS::HiviewDFX::HiLog::Info( \ 68 LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, FILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__) 69 #define DebugLog(fmt, ...) \ 70 (void)OHOS::HiviewDFX::HiLog::Debug( \ 71 LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, FILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__) 72 #else 73 74 #define FatalLog(...) 75 #define ErrorLog(...) 76 #define WarnLog(...) 77 #define InfoLog(...) 78 #define DebugLog(...) 79 #endif // DEBUG 80 81 #endif // LOG_HELPER_H 82