Changeset: f22bb3ee59b2 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f22bb3ee59b2 Modified Files: gdk/gdk_tracer.c gdk/gdk_tracer.h Branch: gdk-tracer Log Message:
Introduced a different logging level per component diffs (252 lines): diff --git a/gdk/gdk_tracer.c b/gdk/gdk_tracer.c --- a/gdk/gdk_tracer.c +++ b/gdk/gdk_tracer.c @@ -43,7 +43,7 @@ static bool GDK_TRACER_STOP = false; static FILE *output_file; static ATOMIC_TYPE CUR_ADAPTER = DEFAULT_ADAPTER; static LOG_LEVEL CUR_FLUSH_LEVEL = DEFAULT_FLUSH_LEVEL; -LOG_LEVEL CUR_LOG_LEVEL = DEFAULT_LOG_LEVEL; +LOG_LEVEL LOG_LEVELS_LIST[COMPONENTS_COUNT]; // Output error from snprintf of vsnprintf @@ -62,6 +62,45 @@ static void } +static bool +_GDKtracer_adapter_exists(ADAPTER adapter) +{ + (void) adapter; + return true; +} + + +static bool +_GDKtracer_level_exists(LOG_LEVEL level) +{ + (void) level; + return true; +} + + +static bool +_GDKtracer_component_exists(COMPONENT comp) +{ + (void) comp; + return true; +} + + +static void +_GDKtracer_init_log_level_per_component(void) +{ + for(int i = 0; i < COMPONENTS_COUNT; i++) + { + LOG_LEVELS_LIST[i] = DEFAULT_LOG_LEVEL; + } + + /* CHECK */ + // Remove it later :) + // Put only MAL_RESOLVE in DEBUG mode for testing + LOG_LEVELS_LIST[MAL_RESOLVE] = M_DEBUG; +} + + // Prepares a file in order to write the contents of the buffer // when necessary. The file name each time is merovingian_{int}.log static void @@ -133,6 +172,7 @@ GDKtracer_get_timestamp(char* fmt) gdk_return GDKtracer_init(void) { + _GDKtracer_init_log_level_per_component(); _GDKtracer_create_file(); return GDK_SUCCEED; } @@ -147,36 +187,33 @@ GDKtracer_stop(void) gdk_return -GDKtracer_set_log_level(LOG_LEVEL level) +GDKtracer_set_component_log_level(COMPONENT comp, LOG_LEVEL level) { - if(CUR_LOG_LEVEL == level) + if(LOG_LEVELS_LIST[comp] == level) return GDK_SUCCEED; - if(level == DEFAULT_LOG_LEVEL && CUR_LOG_LEVEL != DEFAULT_LOG_LEVEL) - { - int GDK_result = GDKtracer_flush_buffer(); - if(GDK_result == GDK_FAIL) - return GDK_FAIL; - } + if(!_GDKtracer_component_exists(comp)) + return GDK_FAIL; + + if(!_GDKtracer_level_exists(level)) + return GDK_FAIL; + + LOG_LEVELS_LIST[comp] = level; - // TODO: Check level exists - CUR_LOG_LEVEL = level; - return GDK_SUCCEED; } gdk_return -GDKtracer_reset_log_level(void) +GDKtracer_reset_component_log_level(COMPONENT comp) { - if(CUR_LOG_LEVEL == DEFAULT_LOG_LEVEL) + if(LOG_LEVELS_LIST[comp] == DEFAULT_LOG_LEVEL) return GDK_SUCCEED; - int GDK_result = GDKtracer_flush_buffer(); - if(GDK_result == GDK_FAIL) + if(!_GDKtracer_component_exists(comp)) return GDK_FAIL; - - CUR_LOG_LEVEL = DEFAULT_LOG_LEVEL; + + LOG_LEVELS_LIST[comp] = DEFAULT_LOG_LEVEL; return GDK_SUCCEED; } @@ -188,7 +225,9 @@ GDKtracer_set_flush_level(LOG_LEVEL leve if(CUR_FLUSH_LEVEL == level) return GDK_SUCCEED; - // TODO: Check level exists + if(!_GDKtracer_level_exists(level)) + return GDK_FAIL; + CUR_FLUSH_LEVEL = level; return GDK_SUCCEED; @@ -215,11 +254,12 @@ GDKtracer_set_adapter(ADAPTER adapter) // Here when switching between adapters we can open/close the file // But it is not so important to keep it open in case the adapter switches - // From BASIC to other => close the file // From other to BASIC => open the file - // TODO: Check adapter exists + if(!_GDKtracer_adapter_exists(adapter)) + return GDK_FAIL; + ATOMIC_SET(&CUR_ADAPTER, adapter); return GDK_SUCCEED; diff --git a/gdk/gdk_tracer.h b/gdk/gdk_tracer.h --- a/gdk/gdk_tracer.h +++ b/gdk/gdk_tracer.h @@ -13,8 +13,7 @@ #define BUFFER_SIZE 64000 #define DEFAULT_ADAPTER BASIC -#define DEFAULT_COMPONENT_SEL M_ALL -#define DEFAULT_LOG_LEVEL M_DEBUG +#define DEFAULT_LOG_LEVEL M_CRITICAL #define DEFAULT_FLUSH_LEVEL M_DEBUG #define FILE_NAME "trace" @@ -31,6 +30,7 @@ // TODO -> Sort it per layer // COMPONENTS typedef enum { + // ALL M_ALL, @@ -94,6 +94,7 @@ typedef enum { MAL_NAMESPACE, MAL_PROFILER, MAL_MAL, + MAL_DEBUGGER, // OPT @@ -133,18 +134,20 @@ typedef enum { // GDK GDK_ALL, - GDK_LOGGER + GDK_LOGGER, + COMPONENTS_COUNT // Do not remove - it is used in order to find quickly + // the size of the COMPONENT array } COMPONENT; // LOG LEVELS typedef enum { - M_CRITICAL = 1, - M_ERROR = 100, - M_WARNING = 150, - M_INFO = 200, - M_DEBUG = 255 + M_CRITICAL, + M_ERROR, + M_WARNING, + M_INFO, + M_DEBUG, } LOG_LEVEL; @@ -158,8 +161,6 @@ typedef enum { } ADAPTER; -extern LOG_LEVEL CUR_LOG_LEVEL; - /** * * Macros for logging @@ -167,13 +168,15 @@ extern LOG_LEVEL CUR_LOG_LEVEL; * */ +extern LOG_LEVEL LOG_LEVELS_LIST[COMPONENTS_COUNT]; + // If the LOG_LEVEL of the message is one of the following: CRITICAL, ERROR or WARNING // it is logged no matter the component. In any other case the component is taken into account (needs fix) #define GDK_TRACER_LOG(LOG_LEVEL, COMP, MSG, ...) \ if(LOG_LEVEL == M_CRITICAL || \ LOG_LEVEL == M_ERROR || \ LOG_LEVEL == M_WARNING || \ - (LOG_LEVEL >= CUR_LOG_LEVEL)) \ + (LOG_LEVELS_LIST[COMP] >= LOG_LEVEL)) \ { \ GDKtracer_log(LOG_LEVEL, \ "[%s] %s <%s:%d> (%s - %s) %s # "MSG, \ @@ -185,7 +188,6 @@ extern LOG_LEVEL CUR_LOG_LEVEL; ENUM_STR(COMP), \ MT_thread_getname(), \ ## __VA_ARGS__); \ - \ } \ #define CRITICAL(COMP, MSG, ...) \ @@ -231,16 +233,10 @@ gdk_return GDKtracer_init(void); gdk_return GDKtracer_stop(void); -// Sets the log level to one of the enum LOG_LEVELS above. If the current log level -// is not NONE and GDK_tracer_set_log_level sets it to NONE we flush the buffer first -// in order to "discard" the messages that are there from the previous log levels -gdk_return GDKtracer_set_log_level(LOG_LEVEL level); +gdk_return GDKtracer_set_component_log_level(COMPONENT comp, LOG_LEVEL level); -// Resets the log level to the default one - NONE. If the current log level is not NONE -// and GDK_tracer_reset_log_level() is called we need to flush the buffer first in order to -// "discard" messages kept from other log levels -gdk_return GDKtracer_reset_log_level(void); +gdk_return GDKtracer_reset_component_log_level(COMPONENT comp); // Sets the minimum flush level that an event will trigger the logger to flush the buffer _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list