1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #include "log.h"
- #include <stdarg.h>
- #include <stdbool.h>
- #include "Freertos.h"
- #include "semphr.h"
- #include "main.h"
- #include "udp.h"
- #include "app_ethernet.h"
- SemaphoreHandle_t logMutex;
- void LogPrint(logLevel_t logLevel,const char *file, const char *func, const int line, char * fmt, ...)
- {
- #ifdef USE_DHCP
- if(dhcp_done!=1)return;
- #endif
- 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=mymalloc(SRAMEX,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);
- myfree(SRAMEX, p);
- udp_log_close();
- xSemaphoreGive(logMutex);
- }
- }
- void log_init()
- {
- logMutex = xSemaphoreCreateMutex();//´´½¨Ò»¸ölog»¥³âÁ¿
- }
|