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 OHOS_DATA_STORAGE_LOG_WRAPPER_H 17 #define OHOS_DATA_STORAGE_LOG_WRAPPER_H 18 19 #include <string> 20 #include "hilog/log.h" 21 22 namespace OHOS { 23 namespace Telephony { 24 enum class DataStorageLogLevel { 25 DEBUG = 0, 26 INFO, 27 WARN, 28 ERROR, 29 FATAL, 30 }; 31 32 class DataStorageLogWrapper { 33 public: 34 static bool JudgeLevel(const DataStorageLogLevel &level); 35 SetLogLevel(const DataStorageLogLevel & level)36 static void SetLogLevel(const DataStorageLogLevel &level) 37 { 38 level_ = level; 39 } 40 GetLogLevel()41 static const DataStorageLogLevel &GetLogLevel() 42 { 43 return level_; 44 } 45 46 static std::string GetBriefFileName(const std::string &file); 47 48 private: 49 static DataStorageLogLevel level_; 50 }; 51 52 #define CONFIG_HILOG 53 #ifdef CONFIG_HILOG 54 55 #ifndef DATA_DATA_STORAGE_LOG_TAG 56 #define DATA_DATA_STORAGE_LOG_TAG "DataStorage" 57 #endif 58 59 #ifndef DATA_LOG_DOMAIN 60 #define DATA_LOG_DOMAIN 0xD002B01 61 #endif 62 63 static constexpr OHOS::HiviewDFX::HiLogLabel DATA_STORAGE_LABEL = {LOG_CORE, DATA_LOG_DOMAIN, 64 DATA_DATA_STORAGE_LOG_TAG}; 65 66 #define DATA_STORAGE_FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) 67 68 #define OHOS_DEBUG 69 #ifndef OHOS_DEBUG 70 #define PRINT_DATASTORAGE_LOG(op, fmt, ...) (void)OHOS::HiviewDFX::HiLog::op(DATA_STORAGE_LABEL, fmt, ##__VA_ARGS__) 71 #else 72 #define PRINT_DATASTORAGE_LOG(op, fmt, ...) \ 73 (void)OHOS::HiviewDFX::HiLog::op(DATA_STORAGE_LABEL, "[%{public}s-(%{public}s:%{public}d)] " fmt, __FUNCTION__, \ 74 DATA_STORAGE_FILENAME, __LINE__, ##__VA_ARGS__) 75 #endif 76 77 #define DATA_STORAGE_LOGE(fmt, ...) PRINT_DATASTORAGE_LOG(Error, fmt, ##__VA_ARGS__) 78 #define DATA_STORAGE_LOGW(fmt, ...) PRINT_DATASTORAGE_LOG(Warn, fmt, ##__VA_ARGS__) 79 #define DATA_STORAGE_LOGI(fmt, ...) PRINT_DATASTORAGE_LOG(Info, fmt, ##__VA_ARGS__) 80 #define DATA_STORAGE_LOGF(fmt, ...) PRINT_DATASTORAGE_LOG(Fatal, fmt, ##__VA_ARGS__) 81 82 #else 83 #endif // CONFIG_HILOG 84 } // namespace Telephony 85 } // namespace OHOS 86 #endif // OHOS_DATA_STORAGE_LOG_WRAPPER_H