diff --git a/libreborn/CMakeLists.txt b/libreborn/CMakeLists.txt index 3739236..63debc8 100644 --- a/libreborn/CMakeLists.txt +++ b/libreborn/CMakeLists.txt @@ -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) diff --git a/libreborn/include/libreborn/log.h b/libreborn/include/libreborn/log.h index b850f3e..a57dc5b 100644 --- a/libreborn/include/libreborn/log.h +++ b/libreborn/include/libreborn/log.h @@ -3,9 +3,23 @@ #include #include +#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 diff --git a/libreborn/src/util/log.c b/libreborn/src/util/log.c new file mode 100644 index 0000000..b6a2dbc --- /dev/null +++ b/libreborn/src/util/log.c @@ -0,0 +1,16 @@ +#include +#include + +#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") diff --git a/media-layer/core/src/audio/engine.c b/media-layer/core/src/audio/engine.c index 17392d0..bc3a930 100644 --- a/media-layer/core/src/audio/engine.c +++ b/media-layer/core/src/audio/engine.c @@ -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"); } } diff --git a/media-layer/proxy/src/common/common.h b/media-layer/proxy/src/common/common.h index 8299af4..23fa672 100644 --- a/media-layer/proxy/src/common/common.h +++ b/media-layer/proxy/src/common/common.h @@ -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 diff --git a/mods/src/misc/logging.cpp b/mods/src/misc/logging.cpp index 4fa77af..bf43041 100644 --- a/mods/src/misc/logging.cpp +++ b/mods/src/misc/logging.cpp @@ -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);