add function "elog_set_text_color_enabled" and "elog_get_text_color_enabled" to enable and disable log text color

Signed-off-by: ju5t4fun <ihupeng@126.com>
pull/4/head
ju5t4fun 9 years ago
parent 5bca89b9a3
commit 764d600a48

@ -132,6 +132,8 @@ ElogErrCode elog_init(void);
void elog_start(void);
void elog_set_output_enabled(bool enabled);
bool elog_get_output_enabled(void);
void elog_set_text_color_enabled(bool enabled);
bool elog_get_text_color_enabled(void);
void elog_set_fmt(uint8_t level, size_t set);
void elog_set_filter(uint8_t level, const char *tag, const char *keyword);
void elog_set_filter_lvl(uint8_t level);

@ -49,6 +49,8 @@ static const char *level_output_info[] = {
};
/* the output lock enable or disable. default is enable */
static bool output_lock_enabled = true;
/* the log text color enable or disable. default is enable */
static bool text_color_enabled = true;
/* the output is locked before enable. */
static bool output_is_locked_before_enable = false;
/* the output is locked before disable. */
@ -97,6 +99,24 @@ void elog_set_output_enabled(bool enabled) {
elog.output_enabled = enabled;
}
/**
* set log text color enable or disable
*
* @param enabled TRUE: enable FALSE:disable
*/
void elog_set_text_color_enabled(bool enabled) {
text_color_enabled = enabled;
}
/**
* get log text color enable status
*
* @return enable or disable
*/
bool elog_get_text_color_enabled(void) {
return text_color_enabled;
}
/**
* get output is enable or disable
*
@ -241,7 +261,9 @@ void elog_output(uint8_t level, const char *tag, const char *file, const char *f
/* lock output */
output_lock();
/* add Escape Sequence start sign and color info*/
if(text_color_enabled) {
log_len += elog_strcpy(log_len, log_buf + log_len, ESC_START);
char *color = NULL;
switch(level)
@ -268,6 +290,8 @@ void elog_output(uint8_t level, const char *tag, const char *file, const char *f
;
}
log_len += elog_strcpy(log_len, log_buf + log_len, color);
}
/* package level info */
if (get_fmt_enabled(level, ELOG_FMT_LVL)) {
log_len += elog_strcpy(log_len, log_buf + log_len, level_output_info[level]);
@ -363,7 +387,9 @@ void elog_output(uint8_t level, const char *tag, const char *file, const char *f
}
/* add Escape Sequence end sign */
if(text_color_enabled) {
log_len += elog_strcpy(log_len, log_buf + log_len, ESC_END);
}
/* output log */
elog_port_output(log_buf, log_len);

Loading…
Cancel
Save