• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 AVCODEC_SAMPLE_LOG_H
17 #define AVCODEC_SAMPLE_LOG_H
18 
19 #include <hilog/log.h>
20 #include <cinttypes>
21 
22 #undef LOG_DOMAIN
23 #define LOG_DOMAIN 0x0002B66
24 
25 #define AVCODEC_SAMPLE_LOG(func, fmt, args...)                                                                         \
26     do {                                                                                                               \
27         (void)func(LOG_APP, "{%{public}s():%{public}d} " fmt, __FUNCTION__, __LINE__, ##args);                         \
28     } while (0)
29 
30 #define AVCODEC_SAMPLE_LOGF(fmt, ...) AVCODEC_SAMPLE_LOG(OH_LOG_FATAL, fmt, ##__VA_ARGS__)
31 #define AVCODEC_SAMPLE_LOGE(fmt, ...) AVCODEC_SAMPLE_LOG(OH_LOG_ERROR, fmt, ##__VA_ARGS__)
32 #define AVCODEC_SAMPLE_LOGW(fmt, ...) AVCODEC_SAMPLE_LOG(OH_LOG_WARN, fmt, ##__VA_ARGS__)
33 #define AVCODEC_SAMPLE_LOGI(fmt, ...) AVCODEC_SAMPLE_LOG(OH_LOG_INFO, fmt, ##__VA_ARGS__)
34 #define AVCODEC_SAMPLE_LOGD(fmt, ...) AVCODEC_SAMPLE_LOG(OH_LOG_DEBUG, fmt, ##__VA_ARGS__)
35 #define AVCODEC_SAMPLE_LOGD_LIMIT(frequency, fmt, ...)                                                                 \
36     do {                                                                                                               \
37         AVCODEC_SAMPLE_LOG_FREQ_LIMIT(frequency);                                                                      \
38         AVCODEC_SAMPLE_LOGD(fmt, ##__VA_ARGS__);                                                                       \
39     } while (0)
40 
41 #define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...)                                                                  \
42     do {                                                                                                               \
43         if (!(cond)) {                                                                                                 \
44             AVCODEC_SAMPLE_LOGE(fmt, ##__VA_ARGS__);                                                                   \
45             return ret;                                                                                                \
46         }                                                                                                              \
47     } while (0)
48 
49 #define CHECK_AND_RETURN_LOG(cond, fmt, ...)                                                                           \
50     do {                                                                                                               \
51         if (!(cond)) {                                                                                                 \
52             AVCODEC_SAMPLE_LOGE(fmt, ##__VA_ARGS__);                                                                   \
53             return;                                                                                                    \
54         }                                                                                                              \
55     } while (0)
56 
57 #define CHECK_AND_BREAK_LOG(cond, fmt, ...)                                                                            \
58     if (1) {                                                                                                           \
59         if (!(cond)) {                                                                                                 \
60             AVCODEC_SAMPLE_LOGW(fmt, ##__VA_ARGS__);                                                                   \
61             break;                                                                                                     \
62         }                                                                                                              \
63     } else                                                                                                             \
64         void(0)
65 
66 #define CHECK_AND_CONTINUE_LOG(cond, fmt, ...)                                                                         \
67     if (1) {                                                                                                           \
68         if (!(cond)) {                                                                                                 \
69             AVCODEC_SAMPLE_LOGW(fmt, ##__VA_ARGS__);                                                                   \
70             continue;                                                                                                  \
71         }                                                                                                              \
72     } else                                                                                                             \
73         void(0)
74 
75 #endif // AVCODEC_SAMPLE_LOG_H