1 /*
2  * Copyright (C) 2024 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_RINGTONE_LOG_H
17 #define OHOS_RINGTONE_LOG_H
18 
19 #ifndef MLOG_TAG
20 #define MLOG_TAG "Common"
21 #endif
22 
23 #undef LOG_DOMAIN
24 #define LOG_DOMAIN 0xD002B76
25 
26 #undef LOG_TAG
27 #define LOG_TAG "RingtoneLibrary"
28 
29 #ifndef LOG_LABEL
30 #define LOG_LABEL { LOG_CORE, LOG_DOMAIN, LOG_TAG }
31 #endif
32 
33 #include "hilog/log.h"
34 
35 #define RINGTONE_HILOG(op, fmt, args...) \
36     do {                                  \
37         op(LOG_LABEL, MLOG_TAG ":{%{public}s:%{public}d} " fmt, __FUNCTION__, __LINE__, ##args);  \
38     } while (0)
39 
40 #define RINGTONE_DEBUG_LOG(fmt, ...) HILOG_IMPL(LOG_CORE, LOG_DEBUG, LOG_DOMAIN, LOG_TAG, fmt, ##__VA_ARGS__)
41 #define RINGTONE_ERR_LOG(fmt, ...) HILOG_IMPL(LOG_CORE, LOG_ERROR, LOG_DOMAIN, LOG_TAG, fmt, ##__VA_ARGS__)
42 #define RINGTONE_WARN_LOG(fmt, ...) HILOG_IMPL(LOG_CORE, LOG_WARN, LOG_DOMAIN, LOG_TAG, fmt, ##__VA_ARGS__)
43 #define RINGTONE_INFO_LOG(fmt, ...) HILOG_IMPL(LOG_CORE, LOG_INFO, LOG_DOMAIN, LOG_TAG, fmt, ##__VA_ARGS__)
44 #define RINGTONE_FATAL_LOG(fmt, ...) HILOG_IMPL(LOG_CORE, LOG_FATAL, LOG_DOMAIN, LOG_TAG, fmt, ##__VA_ARGS__)
45 
46 #define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...)  \
47     do {                                               \
48         if (!(cond)) {                                 \
49             RINGTONE_ERR_LOG(fmt, ##__VA_ARGS__);         \
50             return ret;                                \
51         }                                              \
52     } while (0)
53 
54 #define CHECK_AND_RETURN_LOG(cond, fmt, ...)           \
55     do {                                               \
56         if (!(cond)) {                                 \
57             RINGTONE_ERR_LOG(fmt, ##__VA_ARGS__);         \
58             return;                                    \
59         }                                              \
60     } while (0)
61 
62 #define CHECK_AND_PRINT_LOG(cond, fmt, ...)            \
63     do {                                               \
64         if (!(cond)) {                                 \
65             RINGTONE_ERR_LOG(fmt, ##__VA_ARGS__);         \
66         }                                              \
67     } while (0)
68 
69 #define CHECK_AND_RETURN_RET(cond, ret)  \
70     do {                                               \
71         if (!(cond)) {                                 \
72             return ret;                                \
73         }                                              \
74     } while (0)
75 
76 #endif // OHOS_RINGTONE_LOG_H
77