easy_port.c 修改
void elog_port_output(const char *log, size_t size) {
/* output to terminal */
usart1_printf("%.*s", size, log);//加入代码
//TODO output to flash
}
//usart1 代码实现
#include "string.h" //包含头文件
#include "stdarg.h"
#include "stdio.h"
#define USART1_REC_LEN 250
uint8_t USART1_PRINTF_Buffer[USART1_REC_LEN];//Usart1_printf发送缓冲区
void usart1_printf(char* fmt,...)
{
uint16_t i;
va_list ap;
va_start(ap,fmt); //
vsprintf((char*)USART1_PRINTF_Buffer,fmt,ap);
va_end(ap);
i=strlen((const char*)USART1_PRINTF_Buffer);//计算数据长度
HAL_UART_Transmit(&huart1,USART1_PRINTF_Buffer,i,100);
}
elog.c修改
3 #define ELOG_COLOR_ENABLE //开启颜色输出 ,修改后面颜色函数默认值
179 elog_set_text_color_enabled(true); //修改后打开颜色输出
初始化
elog_init();
/* set EasyLogger log format */
elog_set_fmt(ELOG_LVL_ASSERT, ELOG_FMT_ALL);
elog_set_fmt(ELOG_LVL_ERROR, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME);
elog_set_fmt(ELOG_LVL_WARN, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME);
elog_set_fmt(ELOG_LVL_INFO, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME);
elog_set_fmt(ELOG_LVL_DEBUG, ELOG_FMT_ALL & ~(ELOG_FMT_FUNC | ELOG_FMT_T_INFO | ELOG_FMT_P_INFO));
elog_set_fmt(ELOG_LVL_VERBOSE, ELOG_FMT_ALL & ~(ELOG_FMT_FUNC | ELOG_FMT_T_INFO | ELOG_FMT_P_INFO));
/* start EasyLogger */
elog_start();
调用案例
log_a("Hello EasyLogger!");//断言 assert
// A/NO_TAG [10:08:12 pid:1008 tid:24] (../Core/Src/freertos.c LED_TASK03:207)Hello EasyLogger!
log_e("Hello EasyLogger!");//error
// E/NO_TAG [10:08:12] Hello EasyLogger!
log_w("Hello EasyLogger!");//waring
// W/NO_TAG [10:08:12] Hello EasyLogger!
log_i("Hello EasyLogger!");//info
// I/NO_TAG [10:08:12] Hello EasyLogger!
log_d("Hello EasyLogger!");//dbug
// D/NO_TAG [10:08:12] (../Core/Src/freertos.c:211)Hello EasyLogger!
log_v("Hello EasyLogger!");//日志
//V/NO_TAG [10:08:12] (../Core/Src/freertos.c:212)Hello EasyLogger!