53 lines
946 B
C

#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include "config.h"
#include "logger.h"
#ifndef LOGGER_BUFFER_SIZE
#define LOGGER_BUFFER_SIZE 65536
#endif
char Logger_buff[LOGGER_BUFFER_SIZE];
uint16_t Logger_buff_wp = 0;
void logger_printf(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
int len = vsnprintf(&Logger_buff[Logger_buff_wp], LOGGER_BUFFER_SIZE-Logger_buff_wp, fmt, args);
va_end(args);
puts(&Logger_buff[Logger_buff_wp]);
Logger_buff_wp += len + 1;
}
void logger_printFullLog(CLI_t* cli)
{
uint16_t line = 0;
char str[20];
snprintf(str, 20, "%03u: ", line);
CLI_stringOut(cli, str);
line++;
for (uint16_t i = 0; i < Logger_buff_wp-1; i++)
{
if (Logger_buff[i] != '\0')
{
CLI_charOut_save(cli, Logger_buff[i]);
}
else
{
snprintf(str, 20, "\n%03u: ", line);
CLI_stringOut(cli, str);
line++;
}
}
printf("\n");
}
void logger_clearBuffer()
{
Logger_buff_wp = 0;
}