xref: /OK3568_Linux_fs/external/linux-rga/im2d_api/src/im2d_log.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright (C) 2022 Rockchip Electronics Co., Ltd.
3  * Authors:
4  *  Cerf Yu <cerf.yu@rock-chips.com>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 #ifndef _im2d_log_hpp_
19 #define _im2d_log_hpp_
20 
21 #define IM_ERR_MSG_LEN 512
22 
23 typedef enum {
24     IM_LOG_UNKNOWN      = 0x0,
25     IM_LOG_DEFAULT      = 0x1,
26     IM_LOG_DEBUG        = 0x3,
27     IM_LOG_INFO         = 0x4,
28     IM_LOG_WARN         = 0x5,
29     IM_LOG_ERROR        = 0x6,
30     IM_LOG_LEVEL_MASK   = 0xff,
31 
32     IM_LOG_FORCE        = 0x1 << 8,         /* This will force output to stdout, not to internal error messages. */
33 } IM_LOG_LEVEL;
34 
35 #define GET_LOG_LEVEL(level) ((level) & IM_LOG_LEVEL_MASK)
36 #define LOG_LEVEL_CHECK(level) ((level) >= rga_log_level_get())
37 
38 int rga_error_msg_set(const char* format, ...);
39 int rga_log_level_init(void);
40 void rga_log_level_update(void);
41 int rga_log_level_get(void);
42 int rga_log_enable_get(void);
43 
44 size_t rga_get_current_time_ms(void);
45 size_t rga_get_start_time_ms(void);
46 
47 #ifdef ANDROID
48 #define IM_LOG(level, ...) \
49     do { \
50         if (!((level) & IM_LOG_FORCE)) \
51             rga_error_msg_set(__VA_ARGS__); \
52         if ((rga_log_enable_get() > 0 && LOG_LEVEL_CHECK(level)) || \
53             GET_LOG_LEVEL(level) == ANDROID_LOG_ERROR || \
54             (level) & IM_LOG_FORCE) \
55             ((void)__android_log_print(GET_LOG_LEVEL(level), LOG_TAG, __VA_ARGS__)); \
56     } while(0)
57 #define IM_LOGD(_str, ...) IM_LOG(ANDROID_LOG_DEBUG, _str , ## __VA_ARGS__)
58 #define IM_LOGI(_str, ...) IM_LOG(ANDROID_LOG_INFO, _str , ## __VA_ARGS__)
59 #define IM_LOGW(_str, ...) IM_LOG(ANDROID_LOG_WARN, _str , ## __VA_ARGS__)
60 #define IM_LOGE(_str, ...) IM_LOG(ANDROID_LOG_ERROR, _str , ## __VA_ARGS__)
61 #define IM_LOGFD(_str, ...) IM_LOG(ANDROID_LOG_DEBUG | IM_LOG_FORCE, _str , ## __VA_ARGS__)
62 #define IM_LOGFI(_str, ...) IM_LOG(ANDROID_LOG_INFO | IM_LOG_FORCE, _str , ## __VA_ARGS__)
63 #define IM_LOGFW(_str, ...) IM_LOG(ANDROID_LOG_WARN | IM_LOG_FORCE, _str , ## __VA_ARGS__)
64 #define IM_LOGFE(_str, ...) IM_LOG(ANDROID_LOG_ERROR | IM_LOG_FORCE, _str , ## __VA_ARGS__)
65 
66 #else
67 #define IM_LOG(level, _str, ...) \
68     do { \
69         if (!((level) & IM_LOG_FORCE)) \
70             rga_error_msg_set(_str, ## __VA_ARGS__); \
71         if ((rga_log_enable_get() > 0 && LOG_LEVEL_CHECK(level)) || \
72             GET_LOG_LEVEL(level) == IM_LOG_ERROR || \
73             (level) & IM_LOG_FORCE) \
74             fprintf(stdout, "%lu " LOG_TAG " %s(%d): " _str "\n", \
75                     (unsigned long)(rga_get_current_time_ms()-rga_get_start_time_ms()), \
76                     __FUNCTION__, __LINE__, ## __VA_ARGS__); \
77     } while(0)
78 #define IM_LOGD(_str, ...) IM_LOG(IM_LOG_DEBUG, _str , ## __VA_ARGS__)
79 #define IM_LOGI(_str, ...) IM_LOG(IM_LOG_INFO, _str , ## __VA_ARGS__)
80 #define IM_LOGW(_str, ...) IM_LOG(IM_LOG_WARN, _str , ## __VA_ARGS__)
81 #define IM_LOGE(_str, ...) IM_LOG(IM_LOG_ERROR, _str , ## __VA_ARGS__)
82 #define IM_LOGFD(_str, ...) IM_LOG(IM_LOG_DEBUG | IM_LOG_FORCE, _str , ## __VA_ARGS__)
83 #define IM_LOGFI(_str, ...) IM_LOG(IM_LOG_INFO | IM_LOG_FORCE, _str , ## __VA_ARGS__)
84 #define IM_LOGFW(_str, ...) IM_LOG(IM_LOG_WARN | IM_LOG_FORCE, _str , ## __VA_ARGS__)
85 #define IM_LOGFE(_str, ...) IM_LOG(IM_LOG_ERROR | IM_LOG_FORCE, _str , ## __VA_ARGS__)
86 #endif
87 
88 #endif /* #define _im2d_log_hpp_ */
89