1 /**
2  * @file lv_log.c
3  *
4  */
5 
6 /*********************
7  *      INCLUDES
8  *********************/
9 #include "lv_log.h"
10 #if LV_USE_LOG
11 
12 #if LV_LOG_PRINTF
13 #include <stdio.h>
14 #endif
15 /*********************
16  *      DEFINES
17  *********************/
18 
19 /**********************
20  *      TYPEDEFS
21  **********************/
22 
23 /**********************
24  *  STATIC PROTOTYPES
25  **********************/
26 
27 /**********************
28  *  STATIC VARIABLES
29  **********************/
30 static lv_log_print_g_cb_t custom_print_cb;
31 
32 /**********************
33  *      MACROS
34  **********************/
35 
36 /**********************
37  *   GLOBAL FUNCTIONS
38  **********************/
39 
40 /**
41  * Register custom print/write function to call when a log is added.
42  * It can format its "File path", "Line number" and "Description" as required
43  * and send the formatted log message to a consol or serial port.
44  * @param print_cb a function pointer to print a log
45  */
lv_log_register_print_cb(lv_log_print_g_cb_t print_cb)46 void lv_log_register_print_cb(lv_log_print_g_cb_t print_cb)
47 {
48     custom_print_cb = print_cb;
49 }
50 
51 /**
52  * Add a log
53  * @param level the level of log. (From `lv_log_level_t` enum)
54  * @param file name of the file when the log added
55  * @param line line number in the source code where the log added
56  * @param dsc description of the log
57  */
lv_log_add(lv_log_level_t level,const char * file,int line,const char * dsc)58 void lv_log_add(lv_log_level_t level, const char * file, int line, const char * dsc)
59 {
60     if(level >= _LV_LOG_LEVEL_NUM) return; /*Invalid level*/
61 
62     if(level >= LV_LOG_LEVEL) {
63 
64 #if LV_LOG_PRINTF
65         static const char * lvl_prefix[] = {"Trace", "Info", "Warn", "Error"};
66         printf("%s: %s \t(%s #%d)\n", lvl_prefix[level], dsc, file, line);
67 #else
68         if(custom_print_cb) custom_print_cb(level, file, line, dsc);
69 #endif
70     }
71 }
72 
73 /**********************
74  *   STATIC FUNCTIONS
75  **********************/
76 
77 #endif /*LV_USE_LOG*/
78