1fc0b0055Sopenharmony_ci/* 2fc0b0055Sopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3fc0b0055Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fc0b0055Sopenharmony_ci * you may not use this file except in compliance with the License. 5fc0b0055Sopenharmony_ci * You may obtain a copy of the License at 6fc0b0055Sopenharmony_ci * 7fc0b0055Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fc0b0055Sopenharmony_ci * 9fc0b0055Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fc0b0055Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fc0b0055Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fc0b0055Sopenharmony_ci * See the License for the specific language governing permissions and 13fc0b0055Sopenharmony_ci * limitations under the License. 14fc0b0055Sopenharmony_ci */ 15fc0b0055Sopenharmony_ci 16fc0b0055Sopenharmony_ci#ifndef ACCESSTOKEN_LOG_H 17fc0b0055Sopenharmony_ci#define ACCESSTOKEN_LOG_H 18fc0b0055Sopenharmony_ci 19fc0b0055Sopenharmony_ci#ifdef HILOG_ENABLE 20fc0b0055Sopenharmony_ci 21fc0b0055Sopenharmony_ci#include "hilog/log.h" 22fc0b0055Sopenharmony_ci 23fc0b0055Sopenharmony_ci/* define LOG_TAG as "security_*" at your submodule, * means your submodule name such as "security_dac" */ 24fc0b0055Sopenharmony_ci#undef LOG_TAG 25fc0b0055Sopenharmony_ci#undef LOG_DOMAIN 26fc0b0055Sopenharmony_ci 27fc0b0055Sopenharmony_cistatic constexpr unsigned int SECURITY_DOMAIN_ACCESSTOKEN = 0xD005A01; 28fc0b0055Sopenharmony_cistatic constexpr unsigned int SECURITY_DOMAIN_PRIVACY = 0xD005A02; 29fc0b0055Sopenharmony_ci 30fc0b0055Sopenharmony_ci#define ACCESSTOKEN_LOG_FATAL(label, fmt, ...) \ 31fc0b0055Sopenharmony_ci ((void)HILOG_IMPL(label.type, LOG_FATAL, label.domain, label.tag, \ 32fc0b0055Sopenharmony_ci "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)) 33fc0b0055Sopenharmony_ci#define ACCESSTOKEN_LOG_ERROR(label, fmt, ...) \ 34fc0b0055Sopenharmony_ci ((void)HILOG_IMPL(label.type, LOG_ERROR, label.domain, label.tag, \ 35fc0b0055Sopenharmony_ci "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)) 36fc0b0055Sopenharmony_ci#define ACCESSTOKEN_LOG_WARN(label, fmt, ...) \ 37fc0b0055Sopenharmony_ci ((void)HILOG_IMPL(label.type, LOG_WARN, label.domain, label.tag, \ 38fc0b0055Sopenharmony_ci "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)) 39fc0b0055Sopenharmony_ci#define ACCESSTOKEN_LOG_INFO(label, fmt, ...) \ 40fc0b0055Sopenharmony_ci ((void)HILOG_IMPL(label.type, LOG_INFO, label.domain, label.tag, \ 41fc0b0055Sopenharmony_ci "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)) 42fc0b0055Sopenharmony_ci#define ACCESSTOKEN_LOG_DEBUG(label, fmt, ...) \ 43fc0b0055Sopenharmony_ci ((void)HILOG_IMPL(label.type, LOG_DEBUG, label.domain, label.tag, \ 44fc0b0055Sopenharmony_ci "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)) 45fc0b0055Sopenharmony_ci 46fc0b0055Sopenharmony_ci#define IF_FALSE_PRINT_LOG(label, cond, fmt, ...) \ 47fc0b0055Sopenharmony_ci do { \ 48fc0b0055Sopenharmony_ci if (!(cond)) { \ 49fc0b0055Sopenharmony_ci ACCESSTOKEN_LOG_ERROR(label, fmt, ##__VA_ARGS__); \ 50fc0b0055Sopenharmony_ci } \ 51fc0b0055Sopenharmony_ci } while (0) 52fc0b0055Sopenharmony_ci 53fc0b0055Sopenharmony_ci#define IF_FALSE_RETURN_LOG(label, cond, fmt, ...) \ 54fc0b0055Sopenharmony_ci do { \ 55fc0b0055Sopenharmony_ci if (!(cond)) { \ 56fc0b0055Sopenharmony_ci ACCESSTOKEN_LOG_ERROR(label, fmt, ##__VA_ARGS__); \ 57fc0b0055Sopenharmony_ci return; \ 58fc0b0055Sopenharmony_ci } \ 59fc0b0055Sopenharmony_ci } while (0) 60fc0b0055Sopenharmony_ci#else 61fc0b0055Sopenharmony_ci 62fc0b0055Sopenharmony_ci#include <stdarg.h> 63fc0b0055Sopenharmony_ci#include <stdio.h> 64fc0b0055Sopenharmony_ci 65fc0b0055Sopenharmony_ci/* define LOG_TAG as "security_*" at your submodule, * means your submodule name such as "security_dac" */ 66fc0b0055Sopenharmony_ci#undef LOG_TAG 67fc0b0055Sopenharmony_ci 68fc0b0055Sopenharmony_ci#define ACCESSTOKEN_LOG_DEBUG(fmt, ...) printf("[%s] debug: %s: " fmt "\n", LOG_TAG, __func__, ##__VA_ARGS__) 69fc0b0055Sopenharmony_ci#define ACCESSTOKEN_LOG_INFO(fmt, ...) printf("[%s] info: %s: " fmt "\n", LOG_TAG, __func__, ##__VA_ARGS__) 70fc0b0055Sopenharmony_ci#define ACCESSTOKEN_LOG_WARN(fmt, ...) printf("[%s] warn: %s: " fmt "\n", LOG_TAG, __func__, ##__VA_ARGS__) 71fc0b0055Sopenharmony_ci#define ACCESSTOKEN_LOG_ERROR(fmt, ...) printf("[%s] error: %s: " fmt "\n", LOG_TAG, __func__, ##__VA_ARGS__) 72fc0b0055Sopenharmony_ci#define ACCESSTOKEN_LOG_FATAL(fmt, ...) printf("[%s] fatal: %s: " fmt "\n", LOG_TAG, __func__, ##__VA_ARGS__) 73fc0b0055Sopenharmony_ci 74fc0b0055Sopenharmony_ci#define IF_FALSE_PRINT_LOG(cond, fmt, ...) \ 75fc0b0055Sopenharmony_ci do { \ 76fc0b0055Sopenharmony_ci if (!(cond)) { \ 77fc0b0055Sopenharmony_ci ACCESSTOKEN_LOG_ERROR(fmt, ##__VA_ARGS__); \ 78fc0b0055Sopenharmony_ci } \ 79fc0b0055Sopenharmony_ci } while (0) 80fc0b0055Sopenharmony_ci 81fc0b0055Sopenharmony_ci#define IF_FALSE_RETURN_LOG(cond, fmt, ...) \ 82fc0b0055Sopenharmony_ci do { \ 83fc0b0055Sopenharmony_ci if (!(cond)) { \ 84fc0b0055Sopenharmony_ci ACCESSTOKEN_LOG_ERROR(fmt, ##__VA_ARGS__); \ 85fc0b0055Sopenharmony_ci return; \ 86fc0b0055Sopenharmony_ci } \ 87fc0b0055Sopenharmony_ci } while (0) 88fc0b0055Sopenharmony_ci#endif // HILOG_ENABLE 89fc0b0055Sopenharmony_ci 90fc0b0055Sopenharmony_ci#endif // ACCESSTOKEN_LOG_H 91