forked from SZV10X_Software/SZV103_FM33A0xxEV_SiZhu

wujiazhi
2024-06-11 65062d0d5b21f838aa0043a15ce54cfab8d72c43
Soft/test_log.c
New file
@@ -0,0 +1,48 @@
#include <stdio.h>
#include <stdarg.h>
#include "test_log.h"
#include "rtc.h"
#include "sundry.h"
static long long default_get_sys_time_ms(void)
{
   long long time_ms = 0;
   time_ms = BCD_2_HEX_U8(calendar_g.Hour) * 60 * 60 * 1000 + BCD_2_HEX_U8(calendar_g.Minute) * 60 * 1000 +
                  BCD_2_HEX_U8(calendar_g.Second) * 1000;
  return time_ms;
}
static get_sys_time_ms_def s_get_sys_time_ms = default_get_sys_time_ms;
void log_time_register(get_sys_time_ms_def p_get_sys_time_ms)
{
    s_get_sys_time_ms = p_get_sys_time_ms;
}
void log_print(enum log_debug_type debug_type, const char *file, int line, const char *func, const char* fmt, ...)
{
#if LOG_PRINT_OPEN == 1
   va_list ap;
   char buf[LOG_BUF_SIZE] = {0};
   long long time = s_get_sys_time_ms();
   va_start(ap, fmt);
   vsnprintf(buf, sizeof(buf), fmt, ap);
   va_end(ap);
   switch(debug_type)
   {
   case DEBUG_NORMAL:
    printf("<%lld ms>[%s:%d %s] %s", time, file, line, func, buf);
    break;
   case DEBUG_WARNING:
    printf("\033[31m<%lld ms>[%s:%d %s] %s\033[0m", time, file, line, func, buf);
    break;
   case DEBUG_ERROR:
    printf("\033[32m<%lld ms>[%s:%d %s] %s\033[0m", time, file, line, func, buf);
    break;
   default:break;
   }
#endif
}