diff --git a/conf/console.conf.xml b/conf/console.conf.xml
index 9ea7b65c5e..20960c9ea9 100644
--- a/conf/console.conf.xml
+++ b/conf/console.conf.xml
@@ -5,4 +5,8 @@
+
+
+
+
diff --git a/src/include/switch_types.h b/src/include/switch_types.h
index 0da1ed8b41..f7adb2290e 100644
--- a/src/include/switch_types.h
+++ b/src/include/switch_types.h
@@ -38,6 +38,68 @@
#include
SWITCH_BEGIN_EXTERN_C
+#define SWITCH_SEQ_ESC "\033["
+
+/* Ansi Control character suffixes */
+#define SWITCH_SEQ_HOME_CHAR 'H'
+#define SWITCH_SEQ_HOME_CHAR_STR "H"
+#define SWITCH_SEQ_CLEARLINE_CHAR '1'
+#define SWITCH_SEQ_CLEARLINE_CHAR_STR "1"
+#define SWITCH_SEQ_CLEARLINEEND_CHAR "K"
+#define SWITCH_SEQ_CLEARSCR_CHAR0 '2'
+#define SWITCH_SEQ_CLEARSCR_CHAR1 'J'
+#define SWITCH_SEQ_CLEARSCR_CHAR "2J"
+
+#define SWITCH_SEQ_DEFAULT_COLOR SWITCH_SEQ_ESC SWITCH_SEQ_END_COLOR /* Reset to Default fg/bg color */
+#define SWITCH_SEQ_AND_COLOR ";" /* To add multiple color definitions */
+#define SWITCH_SEQ_END_COLOR "m" /* To end color definitions */
+
+/* Foreground colors values */
+#define SWITCH_SEQ_F_BLACK "30"
+#define SWITCH_SEQ_F_RED "31"
+#define SWITCH_SEQ_F_GREEN "32"
+#define SWITCH_SEQ_F_YELLOW "33"
+#define SWITCH_SEQ_F_BLUE "34"
+#define SWITCH_SEQ_F_MAGEN "35"
+#define SWITCH_SEQ_F_CYAN "36"
+#define SWITCH_SEQ_F_WHITE "37"
+
+/* Background colors values */
+#define SWITCH_SEQ_B_BLACK "40"
+#define SWITCH_SEQ_B_RED "41"
+#define SWITCH_SEQ_B_GREEN "42"
+#define SWITCH_SEQ_B_YELLOW "43"
+#define SWITCH_SEQ_B_BLUE "44"
+#define SWITCH_SEQ_B_MAGEN "45"
+#define SWITCH_SEQ_B_CYAN "46"
+#define SWITCH_SEQ_B_WHITE "47"
+
+/* Preset escape sequences - Change foreground colors only */
+#define SWITCH_SEQ_FBLACK SWITCH_SEQ_ESC SWITCH_SEQ_F_BLACK SWITCH_SEQ_END_COLOR
+#define SWITCH_SEQ_FRED SWITCH_SEQ_ESC SWITCH_SEQ_F_RED SWITCH_SEQ_END_COLOR
+#define SWITCH_SEQ_FGREEN SWITCH_SEQ_ESC SWITCH_SEQ_F_GREEN SWITCH_SEQ_END_COLOR
+#define SWITCH_SEQ_FYELLOW SWITCH_SEQ_ESC SWITCH_SEQ_F_YELLOW SWITCH_SEQ_END_COLOR
+#define SWITCH_SEQ_FBLUE SWITCH_SEQ_ESC SWITCH_SEQ_F_BLUE SWITCH_SEQ_END_COLOR
+#define SWITCH_SEQ_FMAGEN SWITCH_SEQ_ESC SWITCH_SEQ_F_MAGEN SWITCH_SEQ_END_COLOR
+#define SWITCH_SEQ_FCYAN SWITCH_SEQ_ESC SWITCH_SEQ_F_CYAN SWITCH_SEQ_END_COLOR
+#define SWITCH_SEQ_FWHITE SWITCH_SEQ_ESC SWITCH_SEQ_F_WHITE SWITCH_SEQ_END_COLOR
+
+#define SWITCH_SEQ_BBLACK SWITCH_SEQ_ESC SWITCH_SEQ_B_BLACK SWITCH_SEQ_END_COLOR
+#define SWITCH_SEQ_BRED SWITCH_SEQ_ESC SWITCH_SEQ_B_RED SWITCH_SEQ_END_COLOR
+#define SWITCH_SEQ_BGREEN SWITCH_SEQ_ESC SWITCH_SEQ_B_GREEN SWITCH_SEQ_END_COLOR
+#define SWITCH_SEQ_BYELLOW SWITCH_SEQ_ESC SWITCH_SEQ_B_YELLOW SWITCH_SEQ_END_COLOR
+#define SWITCH_SEQ_BBLUE SWITCH_SEQ_ESC SWITCH_SEQ_B_BLUE SWITCH_SEQ_END_COLOR
+#define SWITCH_SEQ_BMAGEN SWITCH_SEQ_ESC SWITCH_SEQ_B_MAGEN SWITCH_SEQ_END_COLOR
+#define SWITCH_SEQ_BCYAN SWITCH_SEQ_ESC SWITCH_SEQ_B_CYAN SWITCH_SEQ_END_COLOR
+#define SWITCH_SEQ_BWHITE SWITCH_SEQ_ESC SWITCH_SEQ_B_WHITE SWITCH_SEQ_END_COLOR
+
+/* Preset escape sequences */
+#define SWITCH_SEQ_HOME SWITCH_SEQ_ESC SWITCH_SEQ_HOME_CHAR_STR
+#define SWITCH_SEQ_CLEARLINE SWITCH_SEQ_ESC SWITCH_SEQ_CLEARLINE_CHAR_STR
+#define SWITCH_SEQ_CLEARLINEEND SWITCH_SEQ_ESC SWITCH_SEQ_CLEARLINEEND_CHAR
+#define SWITCH_SEQ_CLEARSCR SWITCH_SEQ_ESC SWITCH_SEQ_CLEARSCR_CHAR SWITCH_SEQ_HOME
+
+
#ifdef WIN32
#define SWITCH_PATH_SEPARATOR "\\"
#else
diff --git a/src/mod/loggers/mod_console/mod_console.c b/src/mod/loggers/mod_console/mod_console.c
index fed16c87b0..f8f35fc5b8 100644
--- a/src/mod/loggers/mod_console/mod_console.c
+++ b/src/mod/loggers/mod_console/mod_console.c
@@ -33,6 +33,9 @@
static const char modname[] = "mod_console";
static const uint8_t STATIC_LEVELS[] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
+static int COLORIZE = 0;
+static const char *COLORS[] =
+ { SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FMAGEN, SWITCH_SEQ_FCYAN, SWITCH_SEQ_FGREEN, SWITCH_SEQ_FYELLOW, "" };
static switch_loadable_module_interface_t console_module_interface = {
/*.module_name */ modname,
@@ -100,6 +103,17 @@ static switch_status_t config_logger(void)
}
}
+ if ((settings = switch_xml_child(cfg, "settings"))) {
+ for (param = switch_xml_child(settings, "param"); param; param = param->next) {
+ char *var = (char *) switch_xml_attr_soft(param, "name");
+ char *val = (char *) switch_xml_attr_soft(param, "value");
+
+ if (!strcasecmp(var, "colorize") && switch_true(val)) {
+ COLORIZE = 1;
+ }
+ }
+ }
+
switch_xml_free(xml);
return SWITCH_STATUS_SUCCESS;
@@ -128,7 +142,11 @@ static switch_status_t switch_console_logger(const switch_log_node_t *node, swit
}
if (!log_hash || (((all_level > - 1) || lookup) && level >= node->level)) {
- fprintf(handle, "%s", node->data);
+ if (COLORIZE) {
+ fprintf(handle, "%s%s%s", COLORS[node->level], node->data, SWITCH_SEQ_DEFAULT_COLOR);
+ } else {
+ fprintf(handle, "%s", node->data);
+ }
}
} else {
fprintf(stderr, "HELP I HAVE NO CONSOLE TO LOG TO!\n");