• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-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 GRAPHIC_LITE_GRAPHIC_LOG_H
17 #define GRAPHIC_LITE_GRAPHIC_LOG_H
18 
19 #include "graphic_config.h"
20 #if ENABLE_GRAPHIC_LOG
21 #if defined(__LITEOS__) || defined(__LITEOS_M__) || defined(__linux__)
22 #include "log.h"
23 #include <cstring>
24 #else
25 #include <stdio.h>
26 #endif
27 #endif
28 
29 namespace OHOS {
30 #if ENABLE_GRAPHIC_LOG
31 #if (defined __LITEOS_A__) || (defined __linux__)
32 typedef enum {
33     LOG_LEVEL_FATAL = 0,
34     LOG_LEVEL_ERROR,
35     LOG_LEVEL_WARN,
36     LOG_LEVEL_INFO,
37     LOG_LEVEL_DEBUG,
38     LOG_LEVEL_MAX
39 } LOG_LEVEL;
40 
41 static constexpr HiviewDFX::HiLogLabel GRPHIC_LABEL = {LOG_CORE, 0xD001400, "Graphic"};
42 
43 #define FILE_NAME(x) (strrchr(x, '/') ? (strrchr(x, '/') + 1) : x)
44 
45 #define GRAPHIC_DECORATOR_HILOG(level, op, fmt, args...)                                                    \
46 do {                                                                                                        \
47     if ((level < GRAPHIC_LOG_LEVEL) && (level < LOG_LEVEL_MAX)) {                                           \
48         op(GRPHIC_LABEL, "{%s()-%s:%d} " fmt, __FUNCTION__, FILE_NAME(__FILE__), __LINE__, ##args);         \
49     }                                                                                                       \
50 } while (0)
51 
52 #define GRAPHIC_LOGF(fmt, args...) GRAPHIC_DECORATOR_HILOG(LOG_LEVEL_FATAL, HiviewDFX::HiLog::Fatal, fmt, ##args)
53 #define GRAPHIC_LOGE(fmt, args...) GRAPHIC_DECORATOR_HILOG(LOG_LEVEL_ERROR, HiviewDFX::HiLog::Error, fmt, ##args)
54 #define GRAPHIC_LOGW(fmt, args...) GRAPHIC_DECORATOR_HILOG(LOG_LEVEL_WARN, HiviewDFX::HiLog::Warn, fmt, ##args)
55 #define GRAPHIC_LOGI(fmt, args...) GRAPHIC_DECORATOR_HILOG(LOG_LEVEL_INFO, HiviewDFX::HiLog::Info, fmt, ##args)
56 #define GRAPHIC_LOGD(fmt, args...) GRAPHIC_DECORATOR_HILOG(LOG_LEVEL_DEBUG, HiviewDFX::HiLog::Debug, fmt, ##args)
57 
58 #elif defined(__LITEOS_M__)
59 #define GRAPHIC_LOGF(fmt, args...) HILOG_FATAL(HILOG_MODULE_UIKIT, fmt, ##args)
60 #define GRAPHIC_LOGE(fmt, args...) HILOG_ERROR(HILOG_MODULE_UIKIT, fmt, ##args)
61 #define GRAPHIC_LOGW(fmt, args...) HILOG_WARN(HILOG_MODULE_UIKIT, fmt, ##args)
62 #define GRAPHIC_LOGI(fmt, args...) HILOG_INFO(HILOG_MODULE_UIKIT, fmt, ##args)
63 #define GRAPHIC_LOGD(fmt, args...) HILOG_DEBUG(HILOG_MODULE_UIKIT, fmt, ##args)
64 
65 #else
66 #define GRAPHIC_LOGF(fmt, ...) printf("[%d]" fmt "\n", __LINE__, ##__VA_ARGS__)
67 #define GRAPHIC_LOGE(fmt, ...) GRAPHIC_LOGF(fmt, __VA_ARGS__)
68 #define GRAPHIC_LOGW(fmt, ...) GRAPHIC_LOGF(fmt, __VA_ARGS__)
69 #define GRAPHIC_LOGI(fmt, ...) GRAPHIC_LOGF(fmt, __VA_ARGS__)
70 #define GRAPHIC_LOGD(fmt, ...) GRAPHIC_LOGF(fmt, __VA_ARGS__)
71 #endif // __LITEOS__
72 
73 #else // ENABLE_GRAPHIC_LOG
74 #define GRAPHIC_LOGF(...)
75 #define GRAPHIC_LOGE(...)
76 #define GRAPHIC_LOGW(...)
77 #define GRAPHIC_LOGI(...)
78 #define GRAPHIC_LOGD(...)
79 
80 #endif // ENABLE_GRAPHIC_LOG
81 } // namespace OHOS
82 #endif // GRAPHIC_LITE_GRAPHIC_LOG_H
83