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