12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #include "log.h"
- #include "usart.h"
- #include <stdarg.h>
- #include <stdio.h>
- #include "Freertos.h"
- #include "semphr.h"
- #include "main.h"
- #include "udp.h"
- static SemaphoreHandle_t logMutex;
- void LogPrint(logLevel_t logLevel,const char *file, const char *func, const int line, char * fmt, ...)
- {
- if (xSemaphoreTake(logMutex, 1000))
- {
- udp_log_start();
- va_list args;
- va_start(args, fmt);
- char buf[LOG_LEN_MAX];
- vsnprintf(buf, sizeof(buf), fmt, args);
- va_end(args);
- char *p=pvPortMalloc(1024);
- switch (logLevel)
- {
- #ifdef _LOG_INFO
- case LOG_INFO:
- sprintf(p,"[%s][%s][%s:%4d] %s\r\n", "INFO",file,func, line, buf);
- break;
- #endif
- #ifdef _LOG_DEBUG
- case LOG_DEBUG:
- sprintf(p,"[%s][%s][%s:%4d] %s\r\n", "DEBUG",file, func, line, buf);
- break;
- #endif
- #ifdef _LOG_WARN
- case LOG_WARN:
- sprintf(p,"[%s][%s][%s:%4d] %s\r\n", "WARN", file,func, line, buf);
- break;
- #endif
- case LOG_ERROR:
- sprintf(p,"[%s][%s][%s:%4d] %s\r\n", "ERROR",file, func, line, buf);
- break;
- default:
- break;
- }
- udp_send_printf(p);
- vPortFree(p);
- udp_log_close();
- xSemaphoreGive(logMutex);
- }
- }
- void log_init()
- {
- logMutex = xSemaphoreCreateMutex();//´´½¨Ò»¸ölog»¥³âÁ¿
- }
|