• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 INTERFACES_KITS_JS_SRC_COMMON_LOG_H
17 #define INTERFACES_KITS_JS_SRC_COMMON_LOG_H
18 
19 #include <cstdio>
20 #include <string>
21 #include <vector>
22 
23 #ifndef FILE_SUBSYSTEM_DEBUG_LOCAL
24 #include "hilog/log.h"
25 #endif
26 
27 namespace OHOS {
28 namespace DistributedFS {
29 #ifndef FILE_SUBSYSTEM_DEBUG_LOCAL
30 static constexpr int FILEIO_DOMAIN_ID = 0xD004388;
31 static constexpr OHOS::HiviewDFX::HiLogLabel FILEIO_LABEL = { LOG_CORE, FILEIO_DOMAIN_ID, "file_api" };
32 
33 #ifdef HILOGD
34 #undef HILOGD
35 #endif
36 
37 #ifdef HILOGF
38 #undef HILOGF
39 #endif
40 
41 #ifdef HILOGE
42 #undef HILOGE
43 #endif
44 
45 #ifdef HILOGW
46 #undef HILOGW
47 #endif
48 
49 #ifdef HILOGI
50 #undef HILOGI
51 #endif
52 
53 #define HILOGD(fmt, ...) \
54     (void)OHOS::HiviewDFX::HiLog::Debug(OHOS::DistributedFS::FILEIO_LABEL, "%{public}s: " fmt, __func__, ##__VA_ARGS__)
55 #define HILOGI(fmt, ...) \
56     (void)OHOS::HiviewDFX::HiLog::Info(OHOS::DistributedFS::FILEIO_LABEL, "%{public}s: " fmt, __func__, ##__VA_ARGS__)
57 #define HILOGW(fmt, ...) \
58     (void)OHOS::HiviewDFX::HiLog::Warn(OHOS::DistributedFS::FILEIO_LABEL, "%{public}s: " fmt, __func__, ##__VA_ARGS__)
59 #define HILOGE(fmt, ...) \
60     (void)OHOS::HiviewDFX::HiLog::Error(OHOS::DistributedFS::FILEIO_LABEL, "%{public}s: " fmt, __func__, ##__VA_ARGS__)
61 #define HILOGF(fmt, ...) \
62     (void)OHOS::HiviewDFX::HiLog::Fatal(OHOS::DistributedFS::FILEIO_LABEL, "%{public}s: " fmt, __func__, ##__VA_ARGS__)
63 
64 #else
65 
66 #define PCLOG(fmt, ...)                                                  \
67     do {                                                                 \
68         const std::vector<std::string> filter = {                        \
69             "{public}",                                                  \
70             "{private}",                                                 \
71         };                                                               \
72         std::string str____(fmt);                                        \
73         for (auto &&pattern : filter) {                                  \
74             size_t pos = 0;                                              \
75             while (std::string::npos != (pos = str____.find(pattern))) { \
76                 str____.erase(pos, pattern.length());                    \
77             }                                                            \
78         }                                                                \
79         str____ += "\n";                                                 \
80         printf(str____.c_str(), ##__VA_ARGS__);                          \
81     } while (0)                                                          \
82 
83 #define HILOGD(fmt, ...) PCLOG("%{public}s: " fmt, __func__, ##__VA_ARGS__)
84 #define HILOGI(fmt, ...) PCLOG("%{public}s: " fmt, __func__, ##__VA_ARGS__)
85 #define HILOGW(fmt, ...) PCLOG("%{public}s: " fmt, __func__, ##__VA_ARGS__)
86 #define HILOGE(fmt, ...) PCLOG("%{public}s: " fmt, __func__, ##__VA_ARGS__)
87 #define HILOGF(fmt, ...) PCLOG("%{public}s: " fmt, __func__, ##__VA_ARGS__)
88 
89 #endif
90 } // namespace DistributedFS
91 } // namespace OHOS
92 #endif // INTERFACES_KITS_JS_SRC_COMMON_LOG_H