Skip to content

Commit

Permalink
Optimizations to logger color pallet
Browse files Browse the repository at this point in the history
* Created macros to house the default message and tag colors for the 
logger. This allows reusability by my module and the user;
* Changed the logger color pallet to be a static variable;
  • Loading branch information
AndreLaranjeira committed Sep 22, 2021
1 parent c12c478 commit f88b097
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 46 deletions.
44 changes: 44 additions & 0 deletions include/message_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,50 @@
#include <time.h>

// Macros:
#define DEFAULT_LOGGER_MESSAGE_COLORS { \
[DEFAULT_MSG] = { \
.text_color = DFLT, \
.background_color = DFLT \
}, \
[ERROR_MSG] = { \
.text_color = DFLT, \
.background_color = DFLT \
}, \
[INFO_MSG] = { \
.text_color = DFLT, \
.background_color = DFLT \
}, \
[SUCCESS_MSG] = { \
.text_color = DFLT, \
.background_color = DFLT \
}, \
[WARNING_MSG] = { \
.text_color = DFLT, \
.background_color = DFLT \
} \
}
#define DEFAULT_LOGGER_TAG_COLORS { \
[CONTEXT_TAG] = { \
.text_color = B_WHT, \
.background_color = DFLT \
}, \
[ERROR_TAG] = { \
.text_color = B_RED, \
.background_color = DFLT \
}, \
[INFO_TAG] = { \
.text_color = B_BLU, \
.background_color = DFLT \
}, \
[SUCCESS_TAG] = { \
.text_color = B_GRN, \
.background_color = DFLT \
}, \
[WARNING_TAG] = { \
.text_color = B_YEL, \
.background_color = DFLT \
} \
}
#define TIME_FMT_SIZE 50

// Enumerations:
Expand Down
49 changes: 3 additions & 46 deletions src/message_logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,9 @@
// Private variables:
static char time_fmt[TIME_FMT_SIZE] = "%H:%M:%S %d-%m-%Y";
static FILE *log_file = NULL;
LoggerColorPallet logger_color_pallet = {
.message_colors = {
[DEFAULT_MSG] = {
.text_color = DFLT,
.background_color = DFLT
},
[ERROR_MSG] = {
.text_color = DFLT,
.background_color = DFLT
},
[INFO_MSG] = {
.text_color = DFLT,
.background_color = DFLT
},
[SUCCESS_MSG] = {
.text_color = DFLT,
.background_color = DFLT
},
[WARNING_MSG] = {
.text_color = DFLT,
.background_color = DFLT
},
},

.tag_colors = {
[CONTEXT_TAG] = {
.text_color = B_WHT,
.background_color = DFLT
},
[ERROR_TAG] = {
.text_color = B_RED,
.background_color = DFLT
},
[INFO_TAG] = {
.text_color = B_BLU,
.background_color = DFLT
},
[SUCCESS_TAG] = {
.text_color = B_GRN,
.background_color = DFLT
},
[WARNING_TAG] = {
.text_color = B_YEL,
.background_color = DFLT
}
}
static LoggerColorPallet logger_color_pallet = {
.message_colors = DEFAULT_LOGGER_MESSAGE_COLORS,
.tag_colors = DEFAULT_LOGGER_TAG_COLORS
};
static pthread_mutex_t *logger_recursive_mutex = NULL;

Expand Down

0 comments on commit f88b097

Please sign in to comment.