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 ACCESSTOKEN_COMMON_LOG_H 17 #define ACCESSTOKEN_COMMON_LOG_H 18 19 #include <stdint.h> 20 #include "hilog/log.h" 21 #include "accesstoken_thread_msg.h" 22 23 #define ATM_DOMAIN 0xD005A01 24 #define ATM_TAG "ATM" 25 26 #define PRI_DOMAIN 0xD005A02 27 #define PRI_TAG "PRIVACY" 28 29 #define LOG_PUBLIC "{public}" 30 31 #define LOGF(domain, tag, fmt, ...) \ 32 ((void)HILOG_IMPL(LOG_CORE, LOG_FATAL, domain, tag, \ 33 "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)) 34 #define LOGE(domain, tag, fmt, ...) \ 35 ((void)HILOG_IMPL(LOG_CORE, LOG_ERROR, domain, tag, \ 36 "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)) 37 #define LOGW(domain, tag, fmt, ...) \ 38 ((void)HILOG_IMPL(LOG_CORE, LOG_WARN, domain, tag, \ 39 "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)) 40 #define LOGI(domain, tag, fmt, ...) \ 41 ((void)HILOG_IMPL(LOG_CORE, LOG_INFO, domain, tag, \ 42 "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)) 43 #define LOGD(domain, tag, fmt, ...) \ 44 ((void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, domain, tag, \ 45 "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)) 46 47 // LOGC is used for critical errors that should be logged and reported. 48 #define LOGC(domain, tag, fmt, ...) \ 49 do { \ 50 ((void)HILOG_IMPL(LOG_CORE, LOG_ERROR, domain, tag, \ 51 "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)); \ 52 AddEventMessage(domain, tag, \ 53 "%" LOG_PUBLIC "s[%" LOG_PUBLIC "u]: " fmt, __func__, __LINE__, ##__VA_ARGS__); \ 54 } while (0) 55 56 #define IF_FALSE_PRINT_LOG(domain, tag, cond, fmt, ...) \ 57 do { \ 58 if (!(cond)) { \ 59 LOGE(domain, tag, fmt, ##__VA_ARGS__); \ 60 } \ 61 } while (0) 62 63 #define IF_FALSE_RETURN_LOG(domain, tag, cond, fmt, ...) \ 64 do { \ 65 if (!(cond)) { \ 66 LOGE(domain, tag, fmt, ##__VA_ARGS__); \ 67 return; \ 68 } \ 69 } while (0) 70 71 #endif // ACCESSTOKEN_COMMON_LOG_H 72