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 #ifndef SECURITY_COMPONENT_LOG_H 16 #define SECURITY_COMPONENT_LOG_H 17 18 #ifdef HILOG_ENABLE 19 20 #include "hilog/log.h" 21 22 #undef LOG_DOMAIN 23 #define LOG_DOMAIN 0xD005A05 24 25 static constexpr unsigned int SECURITY_DOMAIN_SECURITY_COMPONENT = 0xD005A05; 26 27 #define SC_LOG_FATAL(label, fmt, ...) \ 28 ((void)HILOG_IMPL(label.type, LOG_FATAL, label.domain, label.tag, \ 29 "[%{public}s]" fmt, __FUNCTION__, ##__VA_ARGS__)) 30 #define SC_LOG_ERROR(label, fmt, ...) \ 31 ((void)HILOG_IMPL(label.type, LOG_ERROR, label.domain, label.tag, \ 32 "[%{public}s]" fmt, __FUNCTION__, ##__VA_ARGS__)) 33 #define SC_LOG_WARN(label, fmt, ...) \ 34 ((void)HILOG_IMPL(label.type, LOG_WARN, label.domain, label.tag, \ 35 "[%{public}s]" fmt, __FUNCTION__, ##__VA_ARGS__)) 36 #define SC_LOG_INFO(label, fmt, ...) \ 37 ((void)HILOG_IMPL(label.type, LOG_INFO, label.domain, label.tag, \ 38 "[%{public}s]" fmt, __FUNCTION__, ##__VA_ARGS__)) 39 #define SC_LOG_DEBUG(label, fmt, ...) \ 40 ((void)HILOG_IMPL(label.type, LOG_DEBUG, label.domain, label.tag, \ 41 "[%{public}s]" fmt, __FUNCTION__, ##__VA_ARGS__)) 42 43 #else 44 45 #include <cstdio> 46 47 #undef LOG_TAG 48 49 #define SC_LOG_DEBUG(fmt, ...) printf("[%s] debug: %s: " fmt "\n", LOG_TAG, __func__, ##__VA_ARGS__) 50 #define SC_LOG_INFO(fmt, ...) printf("[%s] info: %s: " fmt "\n", LOG_TAG, __func__, ##__VA_ARGS__) 51 #define SC_LOG_WARN(fmt, ...) printf("[%s] warn: %s: " fmt "\n", LOG_TAG, __func__, ##__VA_ARGS__) 52 #define SC_LOG_ERROR(fmt, ...) printf("[%s] error: %s: " fmt "\n", LOG_TAG, __func__, ##__VA_ARGS__) 53 #define SC_LOG_FATAL(fmt, ...) printf("[%s] fatal: %s: " fmt "\n", LOG_TAG, __func__, ##__VA_ARGS__) 54 55 #endif // HILOG_ENABLE 56 57 #endif // SECURITY_COMPONENT_LOG_H 58