diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2018-04-23 19:59:12 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2018-04-23 19:59:12 (GMT) |
commit | 79bbaa69ab1c3475bb4775b447da0fda0ca05cd7 (patch) | |
tree | de5514d9a8fd25d162b081aaa1189d471f366901 /src | |
parent | 5d99d1bb648d757724662b0b0b56366e60ed3693 (diff) |
Formatted the log messages displayed in batch mode.
Diffstat (limited to 'src')
-rw-r--r-- | src/core/logs.c | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/src/core/logs.c b/src/core/logs.c index 8327203..aedc78e 100644 --- a/src/core/logs.c +++ b/src/core/logs.c @@ -25,8 +25,10 @@ #include <malloc.h> +#include <string.h> +#include "../common/extstr.h" #include "../gui/core/panels.h" #include "../gui/panels/log.h" @@ -186,6 +188,51 @@ void log_variadic_message(LogMessageType type, const char *fmt, ...) static void print_message_without_gui(LogMessageType type, const char *msg) { - printf("!! MSG :: %s\n", msg); + char *formatted; /* Copie formatée du message */ + const char *prefix; /* Introduction de la ligne */ + + formatted = strdup(msg); + +#define FOREGROUND_LIGHT_GRAY "\e[37m" +#define FOREGROUND_RED "\e[91m" + +#define BACKGROUND_RED "\e[101m" + +#define BOLD "\e[1m" +#define ITALIC "\e[3m" + +#define RESET "\e[0m" + + switch (type) + { + case LMT_INFO: + default: + prefix = "i"; + break; + + case LMT_PROCESS: + prefix = FOREGROUND_LIGHT_GRAY "*" RESET; + break; + + case LMT_WARNING: + prefix = FOREGROUND_RED "!" RESET; + break; + + case LMT_ERROR: + case LMT_BAD_BINARY: + prefix = BACKGROUND_RED "!" RESET; + break; + + } + + formatted = strrpl(formatted, "<b>", BOLD); + formatted = strrpl(formatted, "</b>", RESET); + + formatted = strrpl(formatted, "<i>", ITALIC); + formatted = strrpl(formatted, "</i>", RESET); + + printf("[%s] %s\n", prefix, formatted); + + free(formatted); } |