diff --git a/liblog.c b/liblog.c index b8f9073..d68c616 100644 --- a/liblog.c +++ b/liblog.c @@ -9,18 +9,15 @@ #include #ifdef FX9860G - static int number_max_messages=4096; // Ram 4Ko #define MAX_LENGHT 22 #define WIDTH 8 - #endif -#ifdef FXCG50 +#ifdef FXCG50 static int number_max_messages=10000; // Ram 10 Ko #define MAX_LENGHT 132 #define WIDTH 17 - #endif typedef struct log_line log_line; @@ -36,19 +33,16 @@ typedef struct log_line static log_line first_line= { 0, - "", + "Log beginning:", 0, 0 }; + static log_line* current_line=&first_line; -/// Change the following line to custom ram weight - // 1Ko max - - static int number_messages=0; -static int state=1; +static log_level_t priority=LOG_INFO; static log_line* cut_line() { @@ -83,14 +77,20 @@ void ll_set_size(int s) int ll_get_size(); -void ll_set_state(int s) +void ll_set_state(log_state_t s) { - state = s; + if (s==LOG_DISABLE) + priority=LOG_QUIET; + if (s==LOG_ENABLE) + priority=LOG_INFO; } int ll_get_state() { - return state; + if (priority=LOG_QUIET) + return 0; + else + return 1; } @@ -184,7 +184,7 @@ static void append_character(char c) // log something void ll_send(const char * txt) { - if (state) + if (priority!=LOG_QUIET) { char c=1; int i=0; @@ -197,6 +197,12 @@ void ll_send(const char * txt) } } +void ll_sendp(char const *s , log_level_t l) +{ + if (l>=priority) + ll_send(s); +} + static void show_line(const log_line* l, int y) { dtext(1, y, &l->text[0], C_BLACK, C_NONE); diff --git a/liblog.h b/liblog.h index da2583f..572f85f 100644 --- a/liblog.h +++ b/liblog.h @@ -1,31 +1,91 @@ #ifndef LLOG #define LLOG -// Enables or disable the log state -// It increases performances and then you can choose to enable && disable logging during execution -// s==1 => enabled -// s==0 => disabled -void ll_set_state(int s); +/** Liblog Commands Table + State [deprecated, see "Log level"] + Verbosity + Editing + Advanced behaviour + */ -// With this function you can copy the state somewhere, and restore it after modifications -int ll_get_state(); -// Display a message in the log stream -// you can add \n to start an new line ^^ -void ll_send(const char * txt); -// Put the 8 last lines of the stream -void ll_display(); -// Enable log displaying on panic -void ll_set_panic(); +/*** [deprecated] Log state + -> using "Log level" is recommended + Enables or disable the log state + It increases performances and then you can choose to enable|disable logging during execution */ +typedef enum {LOG_ENABLE=0,LOG_DISABLE=1} log_state_t; -// Display log, enable scrolling, and waits the user to press Exit -void ll_pause(); +/* ll_set_state(log_state_t): + sets log state */ +void ll_set_state(log_state_t); -// Clear log -void ll_clear(); +/* ll_get_state(): + return log state */ +log_state_t ll_get_state(void); -void ll_set_lenght(); + + + +/*** Log level: + Customs verbosities for the log stream ->messages have custom levels + Default value is LEVEL_INFO */ +typedef enum {LEVEL_BLABLA, LEVEL_INFO, LEVEL_WARNING, LEVEL_CRITICAL, LEVEL_FATAL, LEVEL_MAX, LEVEL_QUIET} log_level_t; + +/* ll_set_level(log_level_t): + sets log verbosity */ +void ll_set_level(log_level_t); + +/* ll_get_level(): + return log level */ +log_level_t ll_set_level(void); + + + + +/*** Log editing + Use the following functions to send messages + These commands does support '\n' */ + +/* ll_send(char const *)[deprecated]: + Print text + This function sends the message with a maximal priority + It will be ignored only if the log is disabled or set to quiet (same thing) */ +void ll_send(char const *); + +/* ll_sendp(char const *, log_level_t): + Print text + This function sends the message with a custom priority + Note: A message sent with `LEVEL_QUIET` counts as a `LEVEL_MAX` log */ +void ll_sendp(char const *, log_level_t); + +/* ll_clear(): + Reset log */ +void ll_clear(void); + + + + +/*** Log displaying + Here are different functions to display a log + There are both in fullscreen */ + +/* ll_display(): + One frame displaying + It shows the last lines of the log, without scrolling ability */ +void ll_display(void); + +/* ll_pause(): + Display log, enable scrolling with arrows, and waits the user to press Exit */ +void ll_pause(void); + + + + +/*** Advanced behaviour + This funciont sets the behaviour when an exception occurs + */ +void ll_set_panic(void); #endif