improve logging facility

we have a log viewer within the program now
This commit is contained in:
tildearrow 2022-04-10 22:12:02 -05:00
parent 4ae13c15e6
commit fddd05dc1a
33 changed files with 556 additions and 386 deletions

View file

@ -19,8 +19,12 @@
#ifndef _TA_LOG_H
#define _TA_LOG_H
#include <chrono>
#include <stdio.h>
#include <stdarg.h>
#include <atomic>
#include <string>
#include <fmt/printf.h>
#define LOGLEVEL_ERROR 0
#define LOGLEVEL_WARN 1
@ -28,11 +32,51 @@
#define LOGLEVEL_DEBUG 3
#define LOGLEVEL_TRACE 4
// this has to be a power of 2
#define TA_LOG_SIZE 2048
extern int logLevel;
int logV(const char* format, ...);
int logD(const char* format, ...);
int logI(const char* format, ...);
int logW(const char* format, ...);
int logE(const char* format, ...);
extern std::atomic<unsigned short> logPosition;
struct LogEntry {
int loglevel;
std::chrono::system_clock::time_point time;
std::string text;
bool ready;
LogEntry():
loglevel(0),
ready(false) {}
};
int writeLog(int level, const char* msg, fmt::printf_args& args);
extern LogEntry logEntries[TA_LOG_SIZE];
template<typename... T> int logV(const char* msg, const T&... args) {
fmt::printf_args a=fmt::make_printf_args(args...);
return writeLog(LOGLEVEL_TRACE,msg,a);
}
template<typename... T> int logD(const char* msg, const T&... args) {
fmt::printf_args a=fmt::make_printf_args(args...);
return writeLog(LOGLEVEL_DEBUG,msg,a);
}
template<typename... T> int logI(const char* msg, const T&... args) {
fmt::printf_args a=fmt::make_printf_args(args...);
return writeLog(LOGLEVEL_INFO,msg,a);
}
template<typename... T> int logW(const char* msg, const T&... args) {
fmt::printf_args a=fmt::make_printf_args(args...);
return writeLog(LOGLEVEL_WARN,msg,a);
}
template<typename... T> int logE(const char* msg, const T&... args) {
fmt::printf_args a=fmt::make_printf_args(args...);
return writeLog(LOGLEVEL_ERROR,msg,a);
}
void initLog();
#endif