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 CF_LOG_H 17 #define CF_LOG_H 18 19 #include <stdint.h> 20 #include <stdlib.h> 21 22 #ifdef HILOG_ENABLE 23 24 enum CfLogLevel { 25 CF_LOG_LEVEL_I, 26 CF_LOG_LEVEL_E, 27 CF_LOG_LEVEL_W, 28 CF_LOG_LEVEL_D, 29 }; 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 void CfLog(uint32_t logLevel, const char *funcName, uint32_t lineNo, const char *format, ...); 36 37 #ifdef __cplusplus 38 } 39 #endif 40 41 #include "hilog/log.h" 42 43 #ifdef _CF_LOG_ENABLE_ 44 #undef LOG_TAG 45 #define LOG_TAG "CF" 46 #undef LOG_DOMAIN 47 #define LOG_DOMAIN 0xD002F00 /* Security subsystem's domain id */ 48 #endif 49 50 #define CF_LOG_I(...) CfLog(CF_LOG_LEVEL_I, __func__, __LINE__, __VA_ARGS__) 51 #define CF_LOG_W(...) CfLog(CF_LOG_LEVEL_W, __func__, __LINE__, __VA_ARGS__) 52 #define CF_LOG_E(...) CfLog(CF_LOG_LEVEL_E, __func__, __LINE__, __VA_ARGS__) 53 #define CF_LOG_D(...) CfLog(CF_LOG_LEVEL_D, __func__, __LINE__, __VA_ARGS__) 54 55 #else 56 57 #include <stdio.h> 58 59 #define CF_LOG_D(fmt, ...) printf("[CertificateFramework][D][%s]: " fmt "\n", __FUNCTION__, ##__VA_ARGS__) 60 #define CF_LOG_I(fmt, ...) printf("[CertificateFramework][I][%s]: " fmt "\n", __FUNCTION__, ##__VA_ARGS__) 61 #define CF_LOG_W(fmt, ...) printf("[CertificateFramework][W][%s]: " fmt "\n", __FUNCTION__, ##__VA_ARGS__) 62 #define CF_LOG_E(fmt, ...) printf("[CertificateFramework][E][%s]: " fmt "\n", __FUNCTION__, ##__VA_ARGS__) 63 64 #endif 65 66 #define LOGD CF_LOG_D 67 #define LOGI CF_LOG_I 68 #define LOGW CF_LOG_W 69 #define LOGE CF_LOG_E 70 71 #endif 72