1 /* 2 * Copyright (c) 2023 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_FORM_FWK_FMS_LOG_WRAPPER_H 17 #define OHOS_FORM_FWK_FMS_LOG_WRAPPER_H 18 19 #define CONFIG_HILOG 20 #ifdef CONFIG_HILOG 21 #include <cinttypes> 22 #include <functional> 23 24 #include "hilog/log.h" 25 26 #ifdef HILOG_FATAL 27 #undef HILOG_FATAL 28 #endif 29 30 #ifdef HILOG_ERROR 31 #undef HILOG_ERROR 32 #endif 33 34 #ifdef HILOG_WARN 35 #undef HILOG_WARN 36 #endif 37 38 #ifdef HILOG_INFO 39 #undef HILOG_INFO 40 #endif 41 42 #ifdef HILOG_DEBUG 43 #undef HILOG_DEBUG 44 #endif 45 46 #ifndef FMS_LOG_DOMAIN 47 #define FMS_LOG_DOMAIN 0xD001301 48 #endif 49 50 #ifndef FMS_LOG_TAG 51 #define FMS_LOG_TAG "FormManagerService" 52 #endif 53 54 #ifndef FMS_FUNC_FMT 55 #define FMS_FUNC_FMT "[%{public}s(%{public}s:%{public}d)]" 56 #endif 57 58 #ifndef FMS_FILE_NAME 59 #define FMS_FILE_NAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) 60 #endif 61 62 #ifndef FMS_FUNC_INFO 63 #define FMS_FUNC_INFO FMS_FILE_NAME, __FUNCTION__, __LINE__ 64 #endif 65 66 #define HILOG_ERROR(fmt, ...) do { \ 67 (void)HILOG_IMPL(LOG_CORE, LOG_ERROR, FMS_LOG_DOMAIN, FMS_LOG_TAG, \ 68 FMS_FUNC_FMT fmt, FMS_FUNC_INFO, ##__VA_ARGS__); \ 69 } while (0) 70 71 #define HILOG_WARN(fmt, ...) do { \ 72 (void)HILOG_IMPL(LOG_CORE, LOG_WARN, FMS_LOG_DOMAIN, FMS_LOG_TAG, \ 73 FMS_FUNC_FMT fmt, FMS_FUNC_INFO, ##__VA_ARGS__); \ 74 } while (0) 75 76 #define HILOG_INFO(fmt, ...) do { \ 77 (void)HILOG_IMPL(LOG_CORE, LOG_INFO, FMS_LOG_DOMAIN, FMS_LOG_TAG, \ 78 FMS_FUNC_FMT fmt, FMS_FUNC_INFO, ##__VA_ARGS__); \ 79 } while (0) 80 81 #define HILOG_DEBUG(fmt, ...) do { \ 82 (void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, FMS_LOG_DOMAIN, FMS_LOG_TAG, \ 83 FMS_FUNC_FMT fmt, FMS_FUNC_INFO, ##__VA_ARGS__); \ 84 } while (0) 85 86 #define HILOG_FATAL(fmt, ...) do { \ 87 (void)HILOG_IMPL(LOG_CORE, LOG_FATAL, FMS_LOG_DOMAIN, FMS_LOG_TAG, \ 88 FMS_FUNC_FMT fmt, FMS_FUNC_INFO, ##__VA_ARGS__); \ 89 } while (0) 90 91 #else 92 93 #define HILOG_FATAL(...) 94 #define HILOG_ERROR(...) 95 #define HILOG_WARN(...) 96 #define HILOG_INFO(...) 97 #define HILOG_DEBUG(...) 98 99 #endif // CONFIG_HILOG 100 #endif // OHOS_FORM_FWK_FMS_LOG_WRAPPER_H 101