1 /* 2 * Copyright (c) 2021 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 HKS_LOG_H 17 #define HKS_LOG_H 18 19 #include "hks_type.h" 20 21 #ifdef L2_STANDARD 22 #include "hks_error_msg.h" 23 #endif 24 25 #ifdef HKS_CONFIG_FILE 26 #include HKS_CONFIG_FILE 27 #else 28 #include "hks_config.h" 29 #endif 30 31 // On non-L0 devices, log will be enabled if _HUKS_LOG_ENABLE_ is defined. 32 // On L0 devices, log will be disabled if HUKS_DISABLE_LOG_AT_FILE_TO_REDUCE_ROM_SIZE is defined, 33 // even if _HUKS_LOG_ENABLE_ is defined. 34 #if (!defined(__LITEOS_M__) && defined(_HUKS_LOG_ENABLE_)) || \ 35 (defined(__LITEOS_M__) && defined(_HUKS_LOG_ENABLE_) && !defined(HUKS_DISABLE_LOG_AT_FILE_TO_REDUCE_ROM_SIZE)) 36 #ifdef HKS_ENABLE_LOG_PUBLIC 37 #define LOG_PUBLIC "{public}" 38 #else 39 #define LOG_PUBLIC 40 #endif 41 42 #undef LOG_TAG 43 #define LOG_TAG "HUKS" 44 #undef LOG_DOMAIN 45 #define LOG_DOMAIN 0xD002F06 /* Security subsystem huks domain id */ 46 47 #ifdef HKS_LOG_ENGINE_LOG_CORE 48 #include "hilog/log.h" 49 #define LOG_ENGINE LOG_CORE 50 #else 51 #ifdef HKS_LOG_ENGINE_HILOG_MODULE_SCY 52 #include "log.h" 53 #define LOG_ENGINE HILOG_MODULE_SCY 54 #endif 55 #endif 56 57 #ifdef L2_STANDARD 58 enum HksLogLevel { 59 HKS_LOG_LEVEL_I, 60 HKS_LOG_LEVEL_E, 61 HKS_LOG_LEVEL_E_IMPORTANT, 62 HKS_LOG_LEVEL_W, 63 HKS_LOG_LEVEL_D, 64 }; 65 #define HKS_LOG_I(fmt, arg...) \ 66 HILOG_INFO(LOG_ENGINE, "%" LOG_PUBLIC "s[%" LOG_PUBLIC "u]: " fmt "\n", __func__, __LINE__, ##arg) 67 #define HKS_LOG_W(fmt, arg...) \ 68 HILOG_WARN(LOG_ENGINE, "%" LOG_PUBLIC "s[%" LOG_PUBLIC "u]: " fmt "\n", __func__, __LINE__, ##arg) 69 #define HKS_LOG_E(fmt, arg...) \ 70 do { \ 71 HILOG_ERROR(LOG_ENGINE, "%" LOG_PUBLIC "s[%" LOG_PUBLIC "u]: " fmt "\n", __func__, __LINE__, ##arg); \ 72 HksLog(HKS_LOG_LEVEL_E, "%" LOG_PUBLIC "s[%" LOG_PUBLIC "u]: " fmt, __func__, __LINE__, ##arg); \ 73 } while (0) 74 #define HKS_LOG_E_IMPORTANT(fmt, arg...) \ 75 do { \ 76 HILOG_ERROR(LOG_ENGINE, "%" LOG_PUBLIC "s[%" LOG_PUBLIC "u]: " fmt "\n", __func__, __LINE__, ##arg); \ 77 HksLog(HKS_LOG_LEVEL_E_IMPORTANT, \ 78 "%" LOG_PUBLIC "s[%" LOG_PUBLIC "u]: " fmt, __func__, __LINE__, ##arg); \ 79 } while (0) 80 #define HKS_LOG_D(fmt, arg...) \ 81 HILOG_DEBUG(LOG_ENGINE, "%" LOG_PUBLIC "s[%" LOG_PUBLIC "u]: " fmt "\n", __func__, __LINE__, ##arg) 82 #else // L2_STANDARD 83 #define HKS_LOG_I(fmt, arg...) \ 84 HILOG_INFO(LOG_ENGINE, "%" LOG_PUBLIC "s[%" LOG_PUBLIC "u]: " fmt "\n", __func__, __LINE__, ##arg) 85 #define HKS_LOG_W(fmt, arg...) \ 86 HILOG_WARN(LOG_ENGINE, "%" LOG_PUBLIC "s[%" LOG_PUBLIC "u]: " fmt "\n", __func__, __LINE__, ##arg) 87 #define HKS_LOG_E(fmt, arg...) \ 88 HILOG_ERROR(LOG_ENGINE, "%" LOG_PUBLIC "s[%" LOG_PUBLIC "u]: " fmt "\n", __func__, __LINE__, ##arg) 89 #define HKS_LOG_E_IMPORTANT(fmt, arg...) \ 90 HILOG_ERROR(LOG_ENGINE, "%" LOG_PUBLIC "s[%" LOG_PUBLIC "u]: " fmt "\n", __func__, __LINE__, ##arg) 91 #define HKS_LOG_D(fmt, arg...) \ 92 HILOG_DEBUG(LOG_ENGINE, "%" LOG_PUBLIC "s[%" LOG_PUBLIC "u]: " fmt "\n", __func__, __LINE__, ##arg) 93 #endif // L2_STANDARD 94 95 #else // _HUKS_LOG_ENABLE_ 96 #define HKS_LOG_I(...) 97 #define HKS_LOG_W(...) 98 #define HKS_LOG_E(...) 99 #define HKS_LOG_E_IMPORTANT(...) 100 #define HKS_LOG_D(...) 101 #endif //_HUKS_LOG_ENABLE_ 102 103 #ifdef __cplusplus 104 extern "C" { 105 #endif 106 107 extern uint32_t g_sessionId; 108 109 #ifdef __cplusplus 110 } 111 #endif 112 113 #endif /* HKS_LOG_H */ 114