• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 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_LOGGING_H
17 #define OHOS_LOGGING_H
18 
19 #include "log.h"
20 
21 namespace OHOS {
22 #undef LOG_TAG
23 #define LOG_TAG "abilityms"
24 #undef LOG_DOMAIN
25 #define LOG_DOMAIN 0xD001300
26 
27 #ifdef __LITEOS_M__
28 #ifndef HILOG_DEBUG
29 #define HILOG_DEBUG(mod, format, ...)
30 #endif
31 #ifndef HILOG_ERROR
32 #define HILOG_ERROR(mod, format, ...)
33 #endif
34 #ifndef HILOG_FATAL
35 #define HILOG_FATAL(mod, format, ...)
36 #endif
37 #ifndef HILOG_INFO
38 #define HILOG_INFO(mod, format, ...)
39 #endif
40 #ifndef HILOG_WARN
41 #define HILOG_WARN(mod, format, ...)
42 #endif
43 #ifndef HILOG_RACE
44 #define HILOG_RACE(mod, format, ...)
45 #endif
46 #define PRINTD(name, fmt, ...)
47 #define PRINTI(name, fmt, ...)
48 #define PRINTW(name, fmt, ...)
49 #define PRINTE(name, fmt, ...)
50 #else
51 #ifdef OHOS_DEBUG
52 #define PRINTD(name, fmt, ...) HILOG_DEBUG(LOG_DOMAIN, "%{public}s::%{public}s(%{public}d): " fmt,  \
53     name, __FUNCTION__, __LINE__, ##__VA_ARGS__)
54 #else
55 #define PRINTD(name, fmt, ...)
56 #endif
57 #define PRINTI(name, fmt, ...) HILOG_INFO(LOG_DOMAIN, "%{public}s::%{public}s(%{public}d): " fmt,   \
58     name, __FUNCTION__, __LINE__, ##__VA_ARGS__)
59 #define PRINTW(name, fmt, ...) HILOG_WARN(LOG_DOMAIN, "%{public}s::%{public}s(%{public}d): " fmt,   \
60     name, __FUNCTION__, __LINE__, ##__VA_ARGS__)
61 #define PRINTE(name, fmt, ...) HILOG_ERROR(LOG_DOMAIN, "%{public}s::%{public}s(%{public}d): " fmt,  \
62     name, __FUNCTION__, __LINE__, ##__VA_ARGS__)
63 #endif
64 
65 #define CHECK_NULLPTR_RETURN_PTR(point, name, fmt)            \
66     do {                                                      \
67         if ((point) == nullptr) {                               \
68             PRINTE(name, fmt);                                \
69             return nullptr;                                   \
70         }                                                     \
71     } while (0)
72 
73 #define CHECK_NULLPTR_RETURN(point, name, fmt)            \
74     do {                                                  \
75         if ((point) == nullptr) {                           \
76             PRINTE(name, fmt);                            \
77             return;                                       \
78         }                                                 \
79     } while (0)
80 
81 #define CHECK_NULLPTR_RETURN_CODE(point, name, fmt, code) \
82     do {                                                  \
83         if ((point) == nullptr) {                           \
84             PRINTE(name, fmt);                            \
85             return code;                                  \
86         }                                                 \
87     } while (0)
88 } // namespace OHOS
89 #endif // OHOS_LOGGING_H
90