diff options
author | Danny Holman <dholman@gymli.org> | 2024-09-18 01:08:04 -0500 |
---|---|---|
committer | Danny Holman <dholman@gymli.org> | 2024-09-18 01:08:04 -0500 |
commit | 0b301a7ed041c85548b896418d926563e6eb0762 (patch) | |
tree | ecab05468e89e907a97ba2dfa154867bc373dbcc | |
parent | 43e60465a0b5686f3db71c87a1d73717d93e9964 (diff) |
core: logging: print errors and warnings in color
Print warnings and errors in yellow and red respectively. This will make
these messages stand out and make it easier for a developer to find them
in the terminal window.
Signed-off-by: Danny Holman <dholman@gymli.org>
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | core/logging.c | 24 | ||||
-rw-r--r-- | include/rune/core/logging.h | 2 |
3 files changed, 21 insertions, 6 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index cc8828e..d64deb7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,7 @@ set(HEADER_DIR include) add_compile_definitions(VERSION="${PROJECT_VERSION}") add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES}) +set_property(TARGET ${PROJECT_NAME} PROPERTY ENABLE_EXPORTS ON) target_include_directories(${PROJECT_NAME} PUBLIC ${HEADER_DIR}) set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION}) set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR}) diff --git a/core/logging.c b/core/logging.c index 98ee55b..df97b4d 100644 --- a/core/logging.c +++ b/core/logging.c @@ -3,11 +3,13 @@ #include <string.h> #include <stdarg.h> -#define LSTR_FATAL "[FATAL]" -#define LSTR_ERROR "[ERROR]" -#define LSTR_WARN "[WARNING]" -#define LSTR_INFO "[INFO]" -#define LSTR_DEBUG "[DEBUG]" +#define LSTR_FATAL "\033[31m[FATAL]" +#define LSTR_ERROR "\033[31m[ERROR]" +#define LSTR_WARN "\033[33m[WARNING]" +#define LSTR_INFO "\033[0m[INFO]" +#define LSTR_DEBUG "\033[32m[DEBUG]" + +static int debug_enabled = 0; void log_output(int level, const char *fmt, ...) { char out[8192]; @@ -33,8 +35,18 @@ void log_output(int level, const char *fmt, ...) { lvl_str = LSTR_INFO; break; case LOG_DEBUG: + if (debug_enabled == 0) + return; lvl_str = LSTR_DEBUG; break; } - printf("%s %s\n", lvl_str, out); + printf("%s %s\n%s", lvl_str, out, "\033[0m"); +} + +void enable_log_debug(void) { + debug_enabled = 1; +} + +void disable_log_debug(void) { + debug_enabled = 0; } diff --git a/include/rune/core/logging.h b/include/rune/core/logging.h index 6bb6470..91151bb 100644 --- a/include/rune/core/logging.h +++ b/include/rune/core/logging.h @@ -33,5 +33,7 @@ enum log_level { }; RAPI void log_output(int level, const char *fmt, ...); +RAPI void enable_log_debug(void); +RAPI void disable_log_debug(void); #endif |