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 DLP_LOG_H 17 #define DLP_LOG_H 18 19 #ifdef HILOG_ENABLE 20 21 #include "hilog/log.h" 22 23 #ifndef __cplusplus 24 25 #undef LOG_DOMAIN 26 #define LOG_DOMAIN 0xD005A04 27 28 #define DLP_LOG_DEBUG(fmt, ...) HILOG_DEBUG(LOG_CORE, "[%{public}s:%{public}d]:" fmt, \ 29 __func__, __LINE__, ##__VA_ARGS__) 30 #define DLP_LOG_INFO(fmt, ...) HILOG_INFO(LOG_CORE, "[%{public}s:%{public}d]:" fmt, \ 31 __func__, __LINE__, ##__VA_ARGS__) 32 #define DLP_LOG_WARN(fmt, ...) HILOG_WARN(LOG_CORE, "[%{public}s:%{public}d]:" fmt, \ 33 __func__, __LINE__, ##__VA_ARGS__) 34 #define DLP_LOG_ERROR(fmt, ...) HILOG_ERROR(LOG_CORE, "[%{public}s:%{public}d]:" fmt, \ 35 __func__, __LINE__, ##__VA_ARGS__) 36 #define DLP_LOG_FATAL(fmt, ...) HILOG_FATAL(LOG_CORE, "[%{public}s:%{public}d]:" fmt, \ 37 __func__, __LINE__, ##__VA_ARGS__) 38 39 #else 40 41 static constexpr unsigned int SECURITY_DOMAIN_DLP_PERMISSION = 0xD005A04; 42 43 #define DLP_LOG_FATAL(label, fmt, ...) \ 44 ((void)HILOG_IMPL(label.type, LOG_FATAL, label.domain, label.tag, \ 45 "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)) 46 #define DLP_LOG_ERROR(label, fmt, ...) \ 47 ((void)HILOG_IMPL(label.type, LOG_ERROR, label.domain, label.tag, \ 48 "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)) 49 #define DLP_LOG_WARN(label, fmt, ...) \ 50 ((void)HILOG_IMPL(label.type, LOG_WARN, label.domain, label.tag, \ 51 "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)) 52 #define DLP_LOG_INFO(label, fmt, ...) \ 53 ((void)HILOG_IMPL(label.type, LOG_INFO, label.domain, label.tag, \ 54 "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)) 55 #define DLP_LOG_DEBUG(label, fmt, ...) \ 56 ((void)HILOG_IMPL(label.type, LOG_DEBUG, label.domain, label.tag, \ 57 "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)) 58 #endif // __cplusplus 59 60 #else 61 62 #include <cstdio> 63 64 #undef LOG_TAG 65 66 #define DLP_LOG_DEBUG(fmt, ...) printf("[%s] debug: %s: " fmt "\n", LOG_TAG, __func__, ##__VA_ARGS__) 67 #define DLP_LOG_INFO(fmt, ...) printf("[%s] info: %s: " fmt "\n", LOG_TAG, __func__, ##__VA_ARGS__) 68 #define DLP_LOG_WARN(fmt, ...) printf("[%s] warn: %s: " fmt "\n", LOG_TAG, __func__, ##__VA_ARGS__) 69 #define DLP_LOG_ERROR(fmt, ...) printf("[%s] error: %s: " fmt "\n", LOG_TAG, __func__, ##__VA_ARGS__) 70 #define DLP_LOG_FATAL(fmt, ...) printf("[%s] fatal: %s: " fmt "\n", LOG_TAG, __func__, ##__VA_ARGS__) 71 72 #endif // HILOG_ENABLE 73 74 #endif // DLP_LOG_H 75