refactor pxl8 repl
This commit is contained in:
parent
04d3af11a9
commit
3313c800a9
25 changed files with 537 additions and 424 deletions
|
|
@ -1,98 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#define PXL8_LOG_ERROR "\033[38;2;251;73;52m"
|
||||
#define PXL8_LOG_SUCCESS "\033[38;2;254;128;25m"
|
||||
#define PXL8_LOG_WARN "\033[38;2;250;189;47m"
|
||||
#define PXL8_LOG_INFO "\033[38;2;184;187;38m"
|
||||
#define PXL8_LOG_DEBUG "\033[38;2;131;165;152m"
|
||||
#define PXL8_LOG_TRACE "\033[38;2;211;134;155m"
|
||||
#define PXL8_LOG_MUTED "\033[38;2;168;153;132m"
|
||||
#define PXL8_LOG_RESET "\033[0m"
|
||||
|
||||
typedef enum {
|
||||
PXL8_LOG_LEVEL_TRACE = 0,
|
||||
PXL8_LOG_LEVEL_DEBUG = 1,
|
||||
PXL8_LOG_LEVEL_INFO = 2,
|
||||
PXL8_LOG_LEVEL_WARN = 3,
|
||||
PXL8_LOG_LEVEL_ERROR = 4,
|
||||
} pxl8_log_level;
|
||||
|
||||
#ifndef PXL8_LOG_LEVEL
|
||||
// Temporary: Always use DEBUG level for benchmarking
|
||||
#define PXL8_LOG_LEVEL PXL8_LOG_LEVEL_DEBUG
|
||||
#endif
|
||||
|
||||
static pxl8_log_level pxl8_current_log_level = PXL8_LOG_LEVEL;
|
||||
|
||||
static inline void pxl8_log_timestamp(char* buffer, size_t size) {
|
||||
time_t now = time(NULL);
|
||||
struct tm* tm_info = localtime(&now);
|
||||
strftime(buffer, size, "%H:%M:%S", tm_info);
|
||||
}
|
||||
|
||||
#define pxl8_trace(...) \
|
||||
do { \
|
||||
if (pxl8_current_log_level <= PXL8_LOG_LEVEL_TRACE) { \
|
||||
char timestamp[16]; \
|
||||
pxl8_log_timestamp(timestamp, sizeof(timestamp)); \
|
||||
fprintf(stderr, "\r\033[K" PXL8_LOG_TRACE "[%s TRACE]" PXL8_LOG_RESET \
|
||||
" %s:%d: ", timestamp, __FILE__, __LINE__); \
|
||||
fprintf(stderr, __VA_ARGS__); \
|
||||
fprintf(stderr, "\n"); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define pxl8_debug(...) \
|
||||
do { \
|
||||
if (pxl8_current_log_level <= PXL8_LOG_LEVEL_DEBUG) { \
|
||||
char timestamp[16]; \
|
||||
pxl8_log_timestamp(timestamp, sizeof(timestamp)); \
|
||||
fprintf(stderr, "\r\033[K" PXL8_LOG_DEBUG "[%s DEBUG]" PXL8_LOG_RESET \
|
||||
" %s:%d: ", timestamp, __FILE__, __LINE__); \
|
||||
fprintf(stderr, __VA_ARGS__); \
|
||||
fprintf(stderr, "\n"); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define pxl8_error(...) \
|
||||
do { \
|
||||
if (pxl8_current_log_level <= PXL8_LOG_LEVEL_ERROR) { \
|
||||
char timestamp[16]; \
|
||||
pxl8_log_timestamp(timestamp, sizeof(timestamp)); \
|
||||
fprintf(stderr, "\r\033[K" PXL8_LOG_ERROR "[%s ERROR]" PXL8_LOG_RESET \
|
||||
" %s:%d: ", timestamp, __FILE__, __LINE__); \
|
||||
fprintf(stderr, __VA_ARGS__); \
|
||||
fprintf(stderr, "\n"); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define pxl8_warn(...) \
|
||||
do { \
|
||||
if (pxl8_current_log_level <= PXL8_LOG_LEVEL_WARN) { \
|
||||
char timestamp[16]; \
|
||||
pxl8_log_timestamp(timestamp, sizeof(timestamp)); \
|
||||
fprintf(stderr, "\r\033[K" PXL8_LOG_WARN "[%s WARN]" PXL8_LOG_RESET \
|
||||
" %s:%d: ", timestamp, __FILE__, __LINE__); \
|
||||
fprintf(stderr, __VA_ARGS__); \
|
||||
fprintf(stderr, "\n"); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define pxl8_info(...) \
|
||||
do { \
|
||||
if (pxl8_current_log_level <= PXL8_LOG_LEVEL_INFO) { \
|
||||
char timestamp[16]; \
|
||||
pxl8_log_timestamp(timestamp, sizeof(timestamp)); \
|
||||
fprintf(stdout, "\r\033[K" PXL8_LOG_INFO "[%s INFO]" PXL8_LOG_RESET \
|
||||
" ", timestamp); \
|
||||
fprintf(stdout, __VA_ARGS__); \
|
||||
fprintf(stdout, "\n"); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#ifndef pxl8_min
|
||||
#define pxl8_min(a, b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue