定义打印函数
参考ESP8266的打印,定义如下打印函数
#ifndef _A_LOG_H_
#define _A_LOG_H_
#include "stdio.h"
#define Log(format, args...) printf( format, ##args ) /*这个地方替换成平台相关的打印函数*/
#ifdef LOG_COLOR_EANBLE
#define LOG_COLOR_BLACK "30"
#define LOG_COLOR_RED "31"
#define LOG_COLOR_GREEN "32"
#define LOG_COLOR_BROWN "33"
#define LOG_COLOR_BLUE "34"
#define LOG_COLOR_PURPLE "35"
#define LOG_COLOR_CYAN "36"
#define LOG_COLOR(COLOR) "\033[0;" COLOR "m"
#define LOG_BOLD(COLOR) "\033[1;" COLOR "m"
#define LOG_RESET_COLOR "\033[0m"
#define LOG_COLOR_C LOG_BOLD(LOG_COLOR_RED)
#define LOG_COLOR_E LOG_COLOR(LOG_COLOR_RED)
#define LOG_COLOR_W LOG_COLOR(LOG_COLOR_BROWN)
#define LOG_COLOR_I LOG_COLOR(LOG_COLOR_GREEN)
#define LOG_COLOR_D LOG_COLOR(LOG_COLOR_CYAN)
#define LOG_COLOR_V
#else
#define LOG_COLOR_C
#define LOG_COLOR_E
#define LOG_COLOR_W
#define LOG_COLOR_I
#define LOG_COLOR_D
#define LOG_COLOR_V
#define LOG_RESET_COLOR
#endif
typedef enum {
LOG_NONE, /*!< No log output */
LOG_CRITICAL, /*!< Critical log*/
LOG_ERROR, /*!< errors, software module can not recover on its own */
LOG_WARN, /*!< Error conditions from which recovery measures have been taken */
LOG_INFO, /*!< Information messages which describe normal flow of events */
LOG_DEBUG, /*!< Extra information which is not necessary for normal use (values, pointers, sizes, etc). */
LOG_VERBOSE /*!< Bigger chunks of debugging information, or frequent messages which can potentially flood the output. */
}loglevel;
#define LOG_FORMAT(letter, format) LOG_COLOR_ ## letter "%-10.10s ""|%-04d | " "["#letter"]" " [%s]" format LOG_RESET_COLOR
#define LOG_IMPL(tag, format, log_level, log_tag_letter, ...) do { \
Log(LOG_FORMAT(log_tag_letter, format),__FUNCTION__,__LINE__, tag, ##__VA_ARGS__); \
}while(0)
#define logD( tag, format, ... ) LOG_IMPL( tag,format,LOG_DEBUG, D,##__VA_ARGS__ )
#define logI( tag, format, ... ) LOG_IMPL( tag,format,LOG_INFO, I,##__VA_ARGS__ )
#define logW( tag, format, ... ) LOG_IMPL( tag,format,LOG_WARN, W,##__VA_ARGS__ )
#define logE( tag, format, ... ) LOG_IMPL( tag,format,LOG_ERROR, E,##__VA_ARGS__ )
#define logC( tag, format, ... ) LOG_IMPL( tag,format,LOG_CRITICAL,C,##__VA_ARGS__ )
#define logDump( tag,level,data,len ) ({if(len>0){int i;Log("%-10.10s " "|%-04d | " "*********************** %04d **********************",__FUNCTION__,__LINE__,(int)len );\
for( i=0;i<len;i++ )\
{\
if( 0==i%20 ) \
{\
Log("\r\n""%-10.10s " "|%-04d | ",__FUNCTION__,__LINE__);\
}\
Log("%02x ",*((unsigned char*)(data+i)) );\
}\
Log("\r\n\r\n");}\
})
#endif