1 /* 2 * Copyright (C) 2024 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 IMAGE_EFFECT_EFFECT_LOG_H 17 #define IMAGE_EFFECT_EFFECT_LOG_H 18 19 #include <hilog/log.h> 20 21 #ifdef __FILE_NAME__ 22 #define LOG_FILE_NAME __FILE_NAME__ 23 #else 24 #define LOG_FILE_NAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) 25 #endif 26 27 #undef LOG_DOMAIN 28 #define LOG_DOMAIN 0xD002B6A 29 30 #undef LOG_TAG 31 #define LOG_TAG "ImageEffect" 32 33 #ifndef LOG_LABEL 34 #define LOG_LABEL \ 35 { \ 36 LOG_CORE, LOG_DOMAIN, LOG_TAG \ 37 } 38 #endif 39 40 #define EFFECT_LOG(func, fmt, args...) \ 41 do { \ 42 (void)func(LOG_CORE, "[%{public}s()@%{public}s:%{public}d] " fmt, __FILE_NAME__, __FUNCTION__, __LINE__, \ 43 ##args); \ 44 } while (0) 45 46 #define EFFECT_LOGF(fmt, ...) HILOG_FATAL(LOG_CORE, fmt, ##__VA_ARGS__) 47 #define EFFECT_LOGE(fmt, ...) HILOG_ERROR(LOG_CORE, fmt, ##__VA_ARGS__) 48 #define EFFECT_LOGW(fmt, ...) HILOG_WARN(LOG_CORE, fmt, ##__VA_ARGS__) 49 #define EFFECT_LOGI(fmt, ...) HILOG_INFO(LOG_CORE, fmt, ##__VA_ARGS__) 50 #define EFFECT_LOGD(fmt, ...) EFFECT_LOG(HILOG_DEBUG, fmt, ##__VA_ARGS__) 51 52 #define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...) \ 53 do { \ 54 if (!(cond)) { \ 55 EFFECT_LOGE(fmt, ##__VA_ARGS__); \ 56 return ret; \ 57 } \ 58 } while (0) 59 60 #define CHECK_AND_RETURN_LOG(cond, fmt, ...) \ 61 do { \ 62 if (!(cond)) { \ 63 EFFECT_LOGE(fmt, ##__VA_ARGS__); \ 64 return; \ 65 } \ 66 } while (0) 67 68 #define CHECK_AND_CONTINUE_LOG(cond, fmt, ...) \ 69 if (!(cond)) { \ 70 EFFECT_LOGE(fmt, ##__VA_ARGS__); \ 71 continue; \ 72 } 73 74 #define CHECK_AND_PRINT_LOG(cond, fmt, ...) \ 75 if (!(cond)) { \ 76 EFFECT_LOGE(fmt, ##__VA_ARGS__); \ 77 } 78 79 #define CHECK_AND_RETURN_RET(cond, ret) \ 80 do { \ 81 if (!(cond)) { \ 82 return ret; \ 83 } \ 84 } while (0) 85 86 #ifndef CHECK_AND_RETURN 87 #define CHECK_AND_RETURN(exec) \ 88 do { \ 89 bool returnValue = (exec); \ 90 if (!returnValue) { \ 91 EFFECT_LOGE("CHECK_AND_RETURN " #exec); \ 92 return; \ 93 } \ 94 } while (0) 95 #endif 96 97 #define EFFECT_LOGI_WITH_STRATEGY(cond, fmt, ...) \ 98 if (cond == LOG_STRATEGY::NORMAL) { \ 99 EFFECT_LOGI(fmt, ##__VA_ARGS__); \ 100 } \ 101 102 #endif // IMAGE_EFFECT_EFFECT_LOG_H 103