Subversion Repositories ESP8266_P1_Meter

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 raymond 1
#ifndef __SERIALLOG_H__
2
#define __SERIALLOG_H__
3
 
4
#include <stdio.h>
5
#include <string.h>
6
 
7
#ifdef __cplusplus
8
extern "C"
9
{
10
#endif
11
 
12
#define DBG_OUTPUT_PORT     Serial
13
// Allow external override; default to verbose debug if not provided
14
#ifndef LOG_LEVEL
15
#define LOG_LEVEL           1    // (0 disable, 1 error, 2 info, 3 debug)
16
#endif
17
 
18
#define __SOURCE_FILE_NAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__))
19
#define _LOG_FORMAT(letter, format)  "\n["#letter"][%s:%u] %s():\t" format, __SOURCE_FILE_NAME__, __LINE__, __FUNCTION__
20
 
21
#if defined(LOG_LEVEL) && (LOG_LEVEL == 0)
22
#define log_error(format, ...)
23
#define log_info(format, ...)
24
#define log_debug(format, ...)
25
#endif
26
 
27
#if defined(LOG_LEVEL) && (LOG_LEVEL > 0)
28
#define log_error(format, ...) DBG_OUTPUT_PORT.printf(_LOG_FORMAT(E, format), ##__VA_ARGS__)
29
#define log_info(format, ...)
30
#define log_debug(format, ...)
31
#endif
32
 
33
#if defined(LOG_LEVEL) && (LOG_LEVEL > 1)
34
#undef log_info
35
#define log_info(format, ...) DBG_OUTPUT_PORT.printf(_LOG_FORMAT(I, format), ##__VA_ARGS__)
36
#endif
37
 
38
#if defined(LOG_LEVEL) && (LOG_LEVEL > 2)
39
#undef log_debug
40
#define log_debug(format, ...) DBG_OUTPUT_PORT.printf(_LOG_FORMAT(D, format), ##__VA_ARGS__)
41
#endif
42
 
43
 
44
 
45
#ifdef __cplusplus
46
}
47
#endif
48
 
49
#endif