1 /* 2 * Copyright (c) 2022 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 FILEMGMT_LIBHILOG_H 17 #define FILEMGMT_LIBHILOG_H 18 19 #include "hilog/log.h" 20 21 #include <string> 22 23 namespace OHOS { 24 namespace FileManagement { 25 26 static constexpr int FILEFS_LOG_DOMAIN = 0xD004388; 27 static constexpr HiviewDFX::HiLogLabel FILEMGMT_LOG_LABEL = {LOG_CORE, FILEFS_LOG_DOMAIN, "file_api"}; 28 29 #if defined __FILE_NAME__ 30 #define FILEMGMT_FILE_NAME __FILE_NAME__ 31 #else 32 #include <cstring> 33 #define FILEMGMT_FILE_NAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) 34 #endif 35 36 #define FILEMGMT_PRINT_LOG(Level, fmt, ...) \ 37 HiviewDFX::HiLog::Level(FILEMGMT_LOG_LABEL, "[%{public}s:%{public}d->%{public}s] " fmt, FILEMGMT_FILE_NAME, \ 38 __LINE__, __FUNCTION__, ##__VA_ARGS__) 39 40 #ifdef HILOGD 41 #undef HILOGD 42 #endif 43 44 #ifdef HILOGF 45 #undef HILOGF 46 #endif 47 48 #ifdef HILOGE 49 #undef HILOGE 50 #endif 51 52 #ifdef HILOGW 53 #undef HILOGW 54 #endif 55 56 #ifdef HILOGI 57 #undef HILOGI 58 #endif 59 60 #define HILOGD(fmt, ...) FILEMGMT_PRINT_LOG(Debug, fmt, ##__VA_ARGS__) 61 #define HILOGI(fmt, ...) FILEMGMT_PRINT_LOG(Info, fmt, ##__VA_ARGS__) 62 #define HILOGW(fmt, ...) FILEMGMT_PRINT_LOG(Warn, fmt, ##__VA_ARGS__) 63 #define HILOGE(fmt, ...) FILEMGMT_PRINT_LOG(Error, fmt, ##__VA_ARGS__) 64 #define HILOGF(fmt, ...) FILEMGMT_PRINT_LOG(Fatal, fmt, ##__VA_ARGS__) 65 } // namespace FileManagement 66 } // namespace OHOS 67 68 #endif // FILEMGMT_LIBHILOG_H