1 /*
2  * Copyright (C) 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_MEDIALIBRARY_COMMON_LOG_H
17 #define OHOS_MEDIALIBRARY_COMMON_LOG_H
18 
19 #include "hilog/log.h"
20 
21 #ifndef C_MLOG_TAG
22 #define C_MLOG_TAG "Common"
23 #endif
24 
25 #undef C_LOG_DOMAIN
26 #define C_LOG_DOMAIN 0xD002B70
27 
28 #undef C_LOG_TAG
29 #define C_LOG_TAG "MediaLibraryCommon"
30 
31 #ifndef C_LOG_LABEL
32 #define C_LOG_LABEL { LOG_CORE, C_LOG_DOMAIN, C_LOG_TAG }
33 #endif
34 
35 #define COMMON_HILOG(op, type, fmt, args...) \
36     do {                                  \
37         op(LOG_CORE, type, C_LOG_DOMAIN, C_LOG_TAG, C_MLOG_TAG ":{%{public}s:%{public}d} " fmt, __FUNCTION__, \
38             __LINE__, ##args);  \
39     } while (0)
40 
41 #define COMMON_DEBUG_LOG(fmt, ...) COMMON_HILOG(HILOG_IMPL, LOG_DEBUG, fmt, ##__VA_ARGS__)
42 #define COMMON_ERR_LOG(fmt, ...) COMMON_HILOG(HILOG_IMPL, LOG_ERROR, fmt, ##__VA_ARGS__)
43 #define COMMON_WARN_LOG(fmt, ...) COMMON_HILOG(HILOG_IMPL, LOG_WARN, fmt, ##__VA_ARGS__)
44 #define COMMON_INFO_LOG(fmt, ...) COMMON_HILOG(HILOG_IMPL, LOG_INFO, fmt, ##__VA_ARGS__)
45 #define COMMON_FATAL_LOG(fmt, ...) COMMON_HILOG(HILOG_IMPL, LOG_FATAL, fmt, ##__VA_ARGS__)
46 
47 #define CHECK_AND_ERR_LOG(cond, fmt, ...) \
48     do { \
49         if (!(cond)) { \
50             COMMON_ERR_LOG(fmt, ##__VA_ARGS__); \
51         } \
52     } while (0)
53 
54 #endif // OHOS_MEDIALIBRARY_COMMON_LOG_H
55