• 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 OHOS_WM_INCLUDE_WINDOW_MANAGER_HILOG_H
17 #define OHOS_WM_INCLUDE_WINDOW_MANAGER_HILOG_H
18 
19 #include <cstdint>
20 #include <unordered_map>
21 #include "hilog/log.h"
22 
23 namespace OHOS {
24 namespace Rosen {
25 static constexpr unsigned int HILOG_DOMAIN_WINDOW = 0xD004200;
26 static constexpr unsigned int HILOG_DOMAIN_DISPLAY = 0xD004201;
27 
28 #define PRINT_WLOG(level, ...) HILOG_IMPL(LABEL.type, level, LABEL.domain, LABEL.tag, ##__VA_ARGS__)
29 
30 #define WLOGD(fmt, ...) PRINT_WLOG(LOG_DEBUG, "(%{public}d)" fmt, __LINE__, ##__VA_ARGS__)
31 #define WLOGI(fmt, ...) PRINT_WLOG(LOG_INFO, "(%{public}d)" fmt, __LINE__, ##__VA_ARGS__)
32 #define WLOGW(fmt, ...) PRINT_WLOG(LOG_WARN, "(%{public}d)" fmt, __LINE__, ##__VA_ARGS__)
33 #define WLOGE(fmt, ...) PRINT_WLOG(LOG_ERROR, "(%{public}d)" fmt, __LINE__, ##__VA_ARGS__)
34 
35 #define C_W_FUNC __func__
36 
37 #define WLOGFD(fmt, ...) WLOGD("%{public}s: " fmt, C_W_FUNC, ##__VA_ARGS__)
38 #define WLOGFI(fmt, ...) WLOGI("%{public}s: " fmt, C_W_FUNC, ##__VA_ARGS__)
39 #define WLOGFW(fmt, ...) WLOGW("%{public}s: " fmt, C_W_FUNC, ##__VA_ARGS__)
40 #define WLOGFE(fmt, ...) WLOGE("%{public}s: " fmt, C_W_FUNC, ##__VA_ARGS__)
41 
42 enum class WmsLogTag : uint8_t {
43     DEFAULT = 0,               // C04200
44     DMS,                       // C04201
45     WMS_MAIN,                  // C04202
46     WMS_SUB,                   // C04203
47     WMS_SCB,                   // C04204
48     WMS_DIALOG,                // C04205
49     WMS_SYSTEM,                // C04206
50     WMS_FOCUS,                 // C04207
51     WMS_LAYOUT,                // C04208
52     WMS_IMMS,                  // C04209
53     WMS_LIFE,                  // C0420A
54     WMS_KEYBOARD,              // C0420B
55     WMS_EVENT,                 // C0420C
56     WMS_UIEXT,                 // C0420D
57     WMS_PIP,                   // C0420E
58     WMS_RECOVER,               // C0420F
59     WMS_MULTI_USER,            // C04210
60     WMS_TOAST,                 // C04211
61     WMS_MULTI_WINDOW,          // C04212
62     WMS_INPUT_KEY_FLOW,        // C04213
63     WMS_PIPELINE,              // C04214
64     WMS_HIERARCHY,             // C04215
65     WMS_PATTERN,               // C04216
66     WMS_ATTRIBUTE,             // C04217
67     WMS_PC,                    // C04218
68     WMS_DECOR,                 // C04219
69     WMS_LAYOUT_PC,             // C0421A
70     WMS_STARTUP_PAGE,          // C0421B
71     WMS_COMPAT,                // C0421C
72     WMS_ROTATION,              // C0421D
73     WMS_ANIMATION,             // C0421E
74     END = 256,                 // Last one, do not use
75 };
76 
77 extern const std::unordered_map<WmsLogTag, const char *> DOMAIN_CONTENTS_MAP;
78 #ifdef IS_RELEASE_VERSION
79 #define WMS_FILE_NAME ""
80 #else
81 #define WMS_FILE_NAME (__builtin_strrchr(__FILE_NAME__, '/') ?   \
82                        __builtin_strrchr(__FILE_NAME__, '/') + 1 : __FILE_NAME__)
83 #endif
84 
85 #define FMT_PREFIX "[%{public}s] %{public}s: "
86 
87 #define FMT_PREFIX_NO_FUNC "[%{public}s]: "
88 
89 #define PRINT_TLOG(level, tag, ...)                                                                     \
90     do {                                                                                                \
91         uint32_t hilogDomain = HILOG_DOMAIN_WINDOW + static_cast<uint32_t>(tag);                        \
92         const char *domainContent = DOMAIN_CONTENTS_MAP.count(tag) ? DOMAIN_CONTENTS_MAP.at(tag) : "";  \
93         HILOG_IMPL(LOG_CORE, level, hilogDomain, domainContent, ##__VA_ARGS__);                         \
94     } while (0)
95 
96 #define TLOGD(tag, fmt, ...) \
97 PRINT_TLOG(LOG_DEBUG, tag, FMT_PREFIX fmt, WMS_FILE_NAME, C_W_FUNC, ##__VA_ARGS__)
98 #define TLOGI(tag, fmt, ...) \
99 PRINT_TLOG(LOG_INFO, tag, FMT_PREFIX fmt, WMS_FILE_NAME, C_W_FUNC, ##__VA_ARGS__)
100 #define TLOGW(tag, fmt, ...) \
101 PRINT_TLOG(LOG_WARN, tag, FMT_PREFIX fmt, WMS_FILE_NAME, C_W_FUNC, ##__VA_ARGS__)
102 #define TLOGE(tag, fmt, ...) \
103 PRINT_TLOG(LOG_ERROR, tag, FMT_PREFIX fmt, WMS_FILE_NAME, C_W_FUNC, ##__VA_ARGS__)
104 
105 /*
106  * There is no function name built in TLOGN log micros. Choose suitable log micros when needed.
107  */
108 #define TLOGND(tag, fmt, ...) \
109 PRINT_TLOG(LOG_DEBUG, tag, FMT_PREFIX_NO_FUNC fmt, WMS_FILE_NAME, ##__VA_ARGS__)
110 #define TLOGNI(tag, fmt, ...) \
111 PRINT_TLOG(LOG_INFO, tag, FMT_PREFIX_NO_FUNC fmt, WMS_FILE_NAME, ##__VA_ARGS__)
112 #define TLOGNW(tag, fmt, ...) \
113 PRINT_TLOG(LOG_WARN, tag, FMT_PREFIX_NO_FUNC fmt, WMS_FILE_NAME, ##__VA_ARGS__)
114 #define TLOGNE(tag, fmt, ...) \
115 PRINT_TLOG(LOG_ERROR, tag, FMT_PREFIX_NO_FUNC fmt, WMS_FILE_NAME, ##__VA_ARGS__)
116 
117 } // namespace OHOS
118 }
119 #endif // FRAMEWORKS_WM_INCLUDE_WINDOW_MANAGER_HILOG_H
120