• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023-2023 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  * Description: Log format definitions.
15  * Author: zhangge
16  * Create: 2022-06-15
17  */
18 
19 #ifndef CAST_ENGINE_LOG_H
20 #define CAST_ENGINE_LOG_H
21 
22 #include "hilog/log_cpp.h"
23 #include "parameters.h"
24 
25 using OHOS::HiviewDFX::HiLog;
26 using OHOS::HiviewDFX::HiLogLabel;
27 
28 namespace OHOS {
29 namespace CastEngine {
30 inline constexpr unsigned int CASTPLUS_LOG_BEGIN = 0xD004600;
31 inline constexpr unsigned int CAST_ENGINE_LOG_ID = CASTPLUS_LOG_BEGIN + 0x01;
32 inline constexpr unsigned int CASTPLUS_LOG_END = CASTPLUS_LOG_BEGIN + 0x10;
33 
34 inline constexpr bool DEBUG = true;
35 
36 #define DEFINE_CAST_ENGINE_LABEL(name) \
37     static constexpr HiLogLabel CAST_ENGINE_LABEL = { LOG_CORE, OHOS::CastEngine::CAST_ENGINE_LOG_ID, name }
38 
39 #define CLOGV(format, ...)                                                                                \
40     do {                                                                                                  \
41         if (DEBUG) {                                                                                      \
42             (void)HiLog::Error(CAST_ENGINE_LABEL, "[%{public}s:%{public}d]: " format, __func__, __LINE__, \
43                 ##__VA_ARGS__);                                                                           \
44         }                                                                                                 \
45     } while (0)
46 #define CLOGD(format, ...) \
47     (void)HiLog::Error(CAST_ENGINE_LABEL, "[%{public}s:%{public}d]: " format, __func__, __LINE__, ##__VA_ARGS__)
48 #define CLOGI(format, ...) \
49     (void)HiLog::Error(CAST_ENGINE_LABEL, "[%{public}s:%{public}d]: " format, __func__, __LINE__, ##__VA_ARGS__)
50 #define CLOGW(format, ...) \
51     (void)HiLog::Error(CAST_ENGINE_LABEL, "[%{public}s:%{public}d]: " format, __func__, __LINE__, ##__VA_ARGS__)
52 #define CLOGE(format, ...) \
53     (void)HiLog::Error(CAST_ENGINE_LABEL, "[%{public}s:%{public}d]: " format, __func__, __LINE__, ##__VA_ARGS__)
54 
55 #undef CHECK_AND_RETURN_RET_LOG
56 #define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...)  \
57     do {                                               \
58         if (cond) {                                    \
59             CLOGE(fmt, ##__VA_ARGS__);                 \
60             return ret;                                \
61         }                                              \
62     } while (0)
63 
64 #undef CHECK_AND_RETURN_LOG
65 #define CHECK_AND_RETURN_LOG(cond, fmt, ...)     \
66     do {                                         \
67         if (!(cond)) {                           \
68             CLOGE(fmt, ##__VA_ARGS__);           \
69             return;                              \
70         }                                        \
71     } while (0)
72 } // namespace CastEngine
73 } // namespace OHOS
74 
75 #endif