• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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  */
15 
16 #ifndef LOG_H
17 #define LOG_H
18 
19 #include <hilog/log_cpp.h>
20 #include <cinttypes>
21 
22 inline constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0xD002BAC, "HCODEC"};
23 
24 #ifdef __FILE_NAME__
25 #define FILENAME __FILE_NAME__
26 #else
27 #define FILENAME __FILE__
28 #endif
29 
30 
31 #define LOG_FMT "[%{public}s][%{public}s %{public}d] "
32 #define LOGE(x, ...) OHOS::HiviewDFX::HiLog::Error(LABEL, LOG_FMT x, FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)
33 #define LOGW(x, ...) OHOS::HiviewDFX::HiLog::Warn(LABEL, LOG_FMT x, FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)
34 #define LOGI(x, ...) OHOS::HiviewDFX::HiLog::Info(LABEL, LOG_FMT x, FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)
35 #define LOGD(x, ...) OHOS::HiviewDFX::HiLog::Debug(LABEL, LOG_FMT x, FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)
36 
37 // for HCodec
38 #define HLOG_FMT "[%{public}u][%{public}s][%{public}s][%{public}s][%{public}s %{public}d] "
39 #define HLOGE(x, ...) OHOS::HiviewDFX::HiLog::Error(LABEL, HLOG_FMT x, componentId_, componentName_.c_str(), \
40     currState_->GetName().c_str(), FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)
41 #define HLOGW(x, ...) OHOS::HiviewDFX::HiLog::Warn(LABEL, HLOG_FMT x, componentId_, componentName_.c_str(), \
42     currState_->GetName().c_str(), FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)
43 #define HLOGI(x, ...) OHOS::HiviewDFX::HiLog::Info(LABEL, HLOG_FMT x, componentId_, componentName_.c_str(), \
44     currState_->GetName().c_str(), FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)
45 #define HLOGD(x, ...) \
46     do {    \
47         if (debugMode_) {   \
48             OHOS::HiviewDFX::HiLog::Debug(LABEL, HLOG_FMT x, componentId_, componentName_.c_str(), \
49             currState_->GetName().c_str(), FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
50         }   \
51     } while (0)
52 
53 // for HCodec inner state
54 #define SLOGE(x, ...) OHOS::HiviewDFX::HiLog::Error(LABEL, HLOG_FMT x, codec_->componentId_, \
55     codec_->componentName_.c_str(), stateName_.c_str(), FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)
56 #define SLOGW(x, ...) OHOS::HiviewDFX::HiLog::Warn(LABEL, HLOG_FMT x, codec_->componentId_, \
57     codec_->componentName_.c_str(), stateName_.c_str(), FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)
58 #define SLOGI(x, ...) OHOS::HiviewDFX::HiLog::Info(LABEL, HLOG_FMT x, codec_->componentId_, \
59     codec_->componentName_.c_str(), stateName_.c_str(), FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)
60 #define SLOGD(x, ...) \
61     do {    \
62         if (codec_->debugMode_) {   \
63             OHOS::HiviewDFX::HiLog::Debug(LABEL, HLOG_FMT x, codec_->componentId_, \
64             codec_->componentName_.c_str(), stateName_.c_str(), FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
65         }   \
66     } while (0)
67 
68 #define IF_TRUE_RETURN_VAL(cond, val)  \
69     do {                               \
70         if (cond) {                    \
71             return val;                \
72         }                              \
73     } while (0)
74 #define IF_TRUE_RETURN_VAL_WITH_MSG(cond, val, msg, ...) \
75     do {                                        \
76         if (cond) {                             \
77             LOGE(msg, ##__VA_ARGS__);           \
78             return val;                         \
79         }                                       \
80     } while (0)
81 #define IF_TRUE_RETURN_VOID(cond)  \
82     do {                                \
83         if (cond) {                     \
84             return;                     \
85         }                               \
86     } while (0)
87 #define IF_TRUE_RETURN_VOID_WITH_MSG(cond, msg, ...)     \
88     do {                                        \
89         if (cond) {                             \
90             LOGE(msg, ##__VA_ARGS__);           \
91             return;                             \
92         }                                       \
93     } while (0)
94 
95 #endif