From 09f07c9a523dce7b8d7e013857f988f727f1a72b Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Sat, 1 Dec 2018 12:15:12 +0100 Subject: Created an extra log category for external errors. --- plugins/pychrysalide/core/logs.c | 6 ++++-- src/core/logs.c | 11 ++++++++++- src/core/logs.h | 42 +++++++++++++++++++++++++++++++++++++++- src/gui/panels/log.c | 17 ++++++++-------- 4 files changed, 64 insertions(+), 12 deletions(-) diff --git a/plugins/pychrysalide/core/logs.c b/plugins/pychrysalide/core/logs.c index 7b595c1..589315e 100644 --- a/plugins/pychrysalide/core/logs.c +++ b/plugins/pychrysalide/core/logs.c @@ -135,8 +135,9 @@ static PyObject *py_logs_log_message(PyObject *self, PyObject *args) case LMT_INFO: case LMT_PROCESS: case LMT_WARNING: - case LMT_ERROR: case LMT_BAD_BINARY: + case LMT_ERROR: + case LMT_EXT_ERROR: log_simple_message(type, msg); result = Py_None; Py_INCREF(result); @@ -235,8 +236,9 @@ static bool define_python_log_constants(PyTypeObject *obj_type) result &= PyDict_AddIntMacro(obj_type, LMT_INFO); result &= PyDict_AddIntMacro(obj_type, LMT_PROCESS); result &= PyDict_AddIntMacro(obj_type, LMT_WARNING); - result &= PyDict_AddIntMacro(obj_type, LMT_ERROR); result &= PyDict_AddIntMacro(obj_type, LMT_BAD_BINARY); + result &= PyDict_AddIntMacro(obj_type, LMT_ERROR); + result &= PyDict_AddIntMacro(obj_type, LMT_EXT_ERROR); result &= PyDict_AddIntMacro(obj_type, LMT_COUNT); return result; diff --git a/src/core/logs.c b/src/core/logs.c index 417039b..ec910e1 100644 --- a/src/core/logs.c +++ b/src/core/logs.c @@ -34,6 +34,9 @@ +/* ------------------------ EMISSIONS DE MESSAGES CLASSIQUES ------------------------ */ + + /* Tranche d'allocation pour les messages complexes */ #define VARIADIC_LOG_BUFSIZE 256 @@ -46,6 +49,11 @@ static void print_message_without_gui(LogMessageType, const char *); +/* ---------------------------------------------------------------------------------- */ +/* EMISSIONS DE MESSAGES CLASSIQUES */ +/* ---------------------------------------------------------------------------------- */ + + /****************************************************************************** * * * Paramètres : - * @@ -251,8 +259,9 @@ static void print_message_without_gui(LogMessageType type, const char *msg) prefix = FOREGROUND_RED "!" RESET; break; - case LMT_ERROR: case LMT_BAD_BINARY: + case LMT_ERROR: + case LMT_EXT_ERROR: prefix = BACKGROUND_RED "!" RESET; break; diff --git a/src/core/logs.h b/src/core/logs.h index 238c3ba..27dd039 100644 --- a/src/core/logs.h +++ b/src/core/logs.h @@ -25,7 +25,10 @@ #define _CORE_LOGS_H +#include #include +#include +#include #include @@ -38,14 +41,19 @@ typedef enum _LogMessageType LMT_INFO, /* Information sur l'exécution */ LMT_PROCESS, /* Début de tâche quelconque */ LMT_WARNING, /* Avertissment à remonter */ - LMT_ERROR, /* Erreur de traitement */ LMT_BAD_BINARY, /* Binaire malformé */ + LMT_ERROR, /* Erreur de traitement interne*/ + LMT_EXT_ERROR, /* Erreur de traitement externe*/ LMT_COUNT } LogMessageType; + +/* ------------------------ EMISSIONS DE MESSAGES CLASSIQUES ------------------------ */ + + /* Fournit la verbosité des messages système. */ LogMessageType get_log_verbosity(void); @@ -63,4 +71,36 @@ void log_variadic_message(LogMessageType, const char *, ...); +/* ------------------------ REMONTEE D'EVENEMENTS INATTENDUS ------------------------ */ + + +#define LOG_ERROR(tp, msg) \ + log_variadic_message(tp, "[%s:%u] %s", __FUNCTION__, __LINE__, msg); + +#define LOG_ERROR_N(func) \ + do \ + { \ + char __msg[1024]; \ + char *__msg_ptr; \ + __msg_ptr = strerror_r(errno, __msg, sizeof(__msg)); \ + log_variadic_message(LMT_EXT_ERROR, "[%s:%u] %s: %s", __FUNCTION__, __LINE__, func, __msg_ptr); \ + } \ + while (0) + +#define LOG_ERROR_OPENSSL \ + do \ + { \ + unsigned long __err; \ + const char *__msg; \ + __err = ERR_get_error(); \ + __msg = ERR_reason_error_string(__err); \ + if (__msg != NULL) \ + log_variadic_message(LMT_EXT_ERROR, "[%s:%u] %s", __FUNCTION__, __LINE__, __msg); \ + else \ + log_variadic_message(LMT_EXT_ERROR, "[%s:%u] unamed error", __FUNCTION__, __LINE__); \ + } \ + while (0) + + + #endif /* _CORE_LOGS_H */ diff --git a/src/gui/panels/log.c b/src/gui/panels/log.c index f0252e9..ffe8b42 100644 --- a/src/gui/panels/log.c +++ b/src/gui/panels/log.c @@ -292,30 +292,31 @@ static gboolean log_message(log_data *data) -1); break; - case LMT_BAD_BINARY: + case LMT_PROCESS: gtk_list_store_set(store, &iter, - LGC_PICTURE, "gtk-dialog-warning", + LGC_PICTURE, "gtk-execute", LGC_STRING, data->msg, -1); break; - case LMT_PROCESS: + case LMT_WARNING: gtk_list_store_set(store, &iter, - LGC_PICTURE, "gtk-execute", + LGC_PICTURE, "gtk-dialog-warning", LGC_STRING, data->msg, -1); break; - case LMT_ERROR: + case LMT_BAD_BINARY: gtk_list_store_set(store, &iter, - LGC_PICTURE, "gtk-dialog-error", + LGC_PICTURE, "gtk-dialog-warning", LGC_STRING, data->msg, -1); break; - case LMT_WARNING: + case LMT_ERROR: + case LMT_EXT_ERROR: gtk_list_store_set(store, &iter, - LGC_PICTURE, "gtk-dialog-warning", + LGC_PICTURE, "gtk-dialog-error", LGC_STRING, data->msg, -1); break; -- cgit v0.11.2-87-g4458