1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**
 *******************************************************************************
 * @file     app_log.h
 * @create   2024-11-01   
 * @author   Panchip BLE GROUP
 * @note
 * Copyright (c) 2022 Shanghai Panchip Microelectronics Co.,Ltd.
 *
 *******************************************************************************
 */
#ifndef _APP_LOG_H_
#define _APP_LOG_H_
 
#include <stdint.h>
#include <stdio.h>
#include "sdk_config.h"
 
#if 1
#include "app_log_uart.h"
#include "app_track.h"
#endif
 
#if CONFIG_RTT_LOG_ENABLE
#include "SEGGER_RTT.h"
#endif
 
/*!< app log level define. */
#define APP_LOG_LVL_NONE   0
#define APP_LOG_LVL_ERR    1
#define APP_LOG_LVL_WRN    2
#define APP_LOG_LVL_INFO   3
#define APP_LOG_LVL_DEBUG  4
 
#ifndef APP_LOG_LVL
#define APP_LOG_LVL        APP_LOG_LVL_DEBUG
#endif
 
void app_log_print_data(uint8_t *pdata, uint32_t len);
    
    
#if APP_LOG_EN && APP_LOG_LVL > APP_LOG_LVL_NONE
#if CONFIG_UART_LOG_ENABLE
    #define APP_LOG_PRINT(...)   printf(__VA_ARGS__)
#elif CONFIG_RTT_LOG_ENABLE
    #define APP_LOG_PRINT(...)   printf(__VA_ARGS__) //SEGGER_RTT_printf(0, __VA_ARGS__)
#else
    #define APP_LOG_PRINT(...) 
#endif
 
/**@brief Enable/Disable output log level info */
#if APP_LOG_LVL_OUTPUT_EN
#define APP_LOG_PRINT_LVL(level)  APP_LOG_PRINT("%s", level)
#else
#define APP_LOG_PRINT_LVL(level)
#endif
 
/**@brief Enable/Disable output trace info */
#if APP_LOG_TRACE_OUTPUT_EN
#define APP_LOG_PRINT_TRACE(...)  APP_LOG_PRINT(__VA_ARGS__)
#else
#define APP_LOG_PRINT_TRACE(...)
#endif
 
#define APP_LOG(...)    APP_LOG_PRINT(__VA_ARGS__)
 
#define APP_LOG_DEBUG(...)                                                        \
    do{                                                                      \
        if(APP_LOG_LVL >= APP_LOG_LVL_DEBUG){                                \
            APP_LOG_PRINT_LVL("[D] ");                                       \
            APP_LOG_PRINT_TRACE("%s %d %s ", __FILE__, __LINE__, __func__);  \
            APP_LOG_PRINT(__VA_ARGS__);                                      \
        }                                                                    \
    }while(0);
 
#define APP_LOG_INFO(...)                                                    \
    do{                                                                      \
        if(APP_LOG_LVL >= APP_LOG_LVL_INFO){                                 \
            APP_LOG_PRINT_LVL("[I] ");                                       \
            APP_LOG_PRINT_TRACE("%s %d %s ", __FILE__, __LINE__, __func__);  \
            APP_LOG_PRINT(__VA_ARGS__);                                      \
        }                                                                    \
    }while(0);
 
#define APP_LOG_WRN(...)                                                      \
    do{                                                                      \
        if(APP_LOG_LVL >= APP_LOG_LVL_WRN){                                  \
            APP_LOG_PRINT_LVL("[W] ");                                       \
            APP_LOG_PRINT_TRACE("%s %d %s ", __FILE__, __LINE__, __func__);  \
            APP_LOG_PRINT(__VA_ARGS__);                                      \
        }                                                                    \
    }while(0);
 
#define APP_LOG_ERR(...)                                                      \
    do{                                                                      \
        if(APP_LOG_LVL >= APP_LOG_LVL_ERR){                                  \
            APP_LOG_PRINT_LVL("[E] ");                                       \
            APP_LOG_PRINT_TRACE("%s %d %s ", __FILE__, __LINE__, __func__);  \
            APP_LOG_PRINT(__VA_ARGS__);                                      \
        }                                                                    \
    }while(0);
 
#define APP_LOG_DATA(pdata, len)   app_log_print_data(pdata, len)
 
#else
#define APP_LOG_PRINT(...) 
 
#define APP_LOG(...)
#define APP_LOG_DEBUG(...)
#define APP_LOG_INFO(...)
#define APP_LOG_WRN(...)
#define APP_LOG_ERR(...)
#define APP_LOG_DATA(pdata, len)
 
#endif /* End of LOG_EN */
    
#include "app_assert.h"
 
#endif /* End of APP_LOG_H_ */