Colored Logs
This commit is contained in:
parent
7c2d0d5625
commit
492725ed63
@ -1,6 +1,6 @@
|
||||
project(libreborn)
|
||||
|
||||
add_library(reborn-util STATIC src/util/elf.c src/util/exec.c src/util/string.c src/util/util.c)
|
||||
add_library(reborn-util STATIC src/util/elf.c src/util/exec.c src/util/string.c src/util/util.c src/util/log.c)
|
||||
target_include_directories(reborn-util PUBLIC include)
|
||||
|
||||
if(BUILD_ARM_COMPONENTS)
|
||||
|
@ -3,9 +3,23 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Colors
|
||||
char *color_reset();
|
||||
char *color_yellow();
|
||||
char *color_faint();
|
||||
char *color_red();
|
||||
|
||||
// Logging
|
||||
#define INFO(format, ...) { fprintf(stderr, "[INFO]: " format "\n", ##__VA_ARGS__); }
|
||||
#define WARN(format, ...) { fprintf(stderr, "[WARN]: " format "\n", ##__VA_ARGS__); }
|
||||
#define DEBUG(format, ...) { const char *debug = getenv("MCPI_DEBUG"); if (debug != NULL && strlen(debug) > 0) { fprintf(stderr, "[DEBUG]: " format "\n", ##__VA_ARGS__); } }
|
||||
#define ERR(format, ...) { fprintf(stderr, "[ERR]: (%s:%i): " format "\n", __FILE__, __LINE__, ##__VA_ARGS__); exit(EXIT_FAILURE); }
|
||||
#define WARN(format, ...) { fprintf(stderr, "%s[WARN]: " format "%s\n", color_yellow(), ##__VA_ARGS__, color_reset()); }
|
||||
#define DEBUG(format, ...) { const char *debug = getenv("MCPI_DEBUG"); if (debug != NULL && strlen(debug) > 0) { fprintf(stderr, "%s[DEBUG]: " format "%s\n", color_faint(), ##__VA_ARGS__, color_reset()); } }
|
||||
#define ERR(format, ...) { fprintf(stderr, "%s[ERR]: (%s:%i): " format "%s\n", color_red(), __FILE__, __LINE__, ##__VA_ARGS__, color_reset()); exit(EXIT_FAILURE); }
|
||||
#define IMPOSSIBLE() ERR("This Should Never Be Called")
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
16
libreborn/src/util/log.c
Normal file
16
libreborn/src/util/log.c
Normal file
@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define COLOR(name, value) \
|
||||
char *color_##name() { \
|
||||
static char *out = NULL; \
|
||||
if (out == NULL) { \
|
||||
out = isatty(fileno(stderr)) ? "\x1b[" value "m" : ""; \
|
||||
} \
|
||||
return out; \
|
||||
}
|
||||
|
||||
COLOR(reset, "0")
|
||||
COLOR(yellow, "93")
|
||||
COLOR(faint, "2")
|
||||
COLOR(red, "91")
|
@ -48,7 +48,7 @@ void _media_audio_init() {
|
||||
}
|
||||
|
||||
// Log
|
||||
INFO("Loaded Audio Engine");
|
||||
DEBUG("Loaded Audio Engine");
|
||||
is_loaded = 1;
|
||||
}
|
||||
|
||||
@ -80,6 +80,6 @@ void _media_audio_cleanup() {
|
||||
}
|
||||
|
||||
// Log
|
||||
INFO("Unloaded Audio Engine");
|
||||
DEBUG("Unloaded Audio Engine");
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ extern "C" {
|
||||
|
||||
#define CONNECTED_MSG "Connected"
|
||||
|
||||
#define PROXY_INFO(format, ...) INFO(PROXY_LOG_TAG format, ##__VA_ARGS__);
|
||||
#define PROXY_INFO(format, ...) DEBUG(PROXY_LOG_TAG format, ##__VA_ARGS__);
|
||||
#define PROXY_ERR(format, ...) { close_connection(); ERR(PROXY_LOG_TAG format, ##__VA_ARGS__); }
|
||||
|
||||
// Safely Send/Receive Data From The Connection
|
||||
|
@ -89,7 +89,7 @@ static void Minecraft_update_injection(unsigned char *minecraft) {
|
||||
// Log When Game Is Saved
|
||||
void Level_saveLevelData_injection(unsigned char *level) {
|
||||
// Print Log Message
|
||||
INFO("Saving Game");
|
||||
DEBUG("Saving Game");
|
||||
|
||||
// Call Original Method
|
||||
(*Level_saveLevelData)(level);
|
||||
|
Loading…
Reference in New Issue
Block a user