8c0a03715221b629d90e222f21c85c68e4747e32
[o-du/phy.git] / fapi_5g / source / include / nr5g_fapi_log.h
1 /******************************************************************************
2 *
3 *   Copyright (c) 2019 Intel.
4 *
5 *   Licensed under the Apache License, Version 2.0 (the "License");
6 *   you may not use this file except in compliance with the License.
7 *   You may obtain a copy of the License at
8 *
9 *       http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *   Unless required by applicable law or agreed to in writing, software
12 *   distributed under the License is distributed on an "AS IS" BASIS,
13 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *   See the License for the specific language governing permissions and
15 *   limitations under the License.
16 *
17 *******************************************************************************/
18
19 /**
20  * @file This file consist of fapi logging macro.
21  *
22  **/
23
24 #ifndef NR5G_FAPI_LOG_H_
25 #define NR5G_FAPI_LOG_H_
26
27 #define NR5G_FAPI_STATS_FNAME "FapiStats.txt"
28
29 typedef enum _nr5g_fapi_log_types_t {
30     INFO_LOG = 0,
31     DEBUG_LOG,
32     ERROR_LOG,
33     TRACE_LOG,
34     HEXDUMP_LOG,
35     NONE_LOG                    // default
36 } nr5g_fapi_log_types_t;
37
38 extern nr5g_fapi_log_types_t nr5g_fapi_log_level_g;
39 // get_logger_type_str is utility function, returns logging lever string.
40 char *get_logger_type_str(
41     nr5g_fapi_log_types_t e);
42
43 void nr5g_fapi_set_log_level(
44     nr5g_fapi_log_types_t new_level);
45
46 nr5g_fapi_log_types_t nr5g_fapi_get_log_level(
47     );
48
49 // NR5G_FAPI__LOG utility Macro for logging.
50 #define NR5G_FAPI_LOG(TYPE, MSG) do { \
51     if(TYPE == ERROR_LOG) { \
52         printf("[NR5G_FAPI][%s]", get_logger_type_str(TYPE)); \
53         printf MSG ;\
54         printf("\n");\
55     }   \
56     else \
57     { \
58         if(nr5g_fapi_log_level_g == NONE_LOG) { \
59         }   \
60         else if(TYPE <= nr5g_fapi_log_level_g) { \
61             printf("[NR5G_FAPI][%s]", get_logger_type_str(TYPE)); \
62             printf MSG ;\
63             printf("\n");\
64         }   \
65         else if(TYPE <= nr5g_fapi_log_level_g && TYPE == DEBUG_LOG) { \
66             printf("[NR5G_FAPI][%s]", get_logger_type_str(TYPE)); \
67             printf MSG ;\
68             printf("\n");\
69         }   \
70         else if(TYPE == nr5g_fapi_log_level_g && TYPE == TRACE_LOG) { \
71             printf("[NR5G_FAPI][%s]", get_logger_type_str(TYPE)); \
72             printf MSG ;\
73             printf("\n");\
74         }   \
75         else {}\
76     } \
77 } while(0)
78
79 #endif                          // NR5G_FAPI_LOG_H_