[Freeswitch-svn] [commit] r4413 - in freeswitch/trunk: conf src/include src/mod/loggers/mod_console
Freeswitch SVN
anthm at freeswitch.org
Wed Feb 28 13:28:07 EST 2007
Author: anthm
Date: Wed Feb 28 13:28:07 2007
New Revision: 4413
Modified:
freeswitch/trunk/conf/console.conf.xml
freeswitch/trunk/src/include/switch_types.h
freeswitch/trunk/src/mod/loggers/mod_console/mod_console.c
Log:
add colorize option to mod_console (see in-tree conf/console.conf.xml)
Modified: freeswitch/trunk/conf/console.conf.xml
==============================================================================
--- freeswitch/trunk/conf/console.conf.xml (original)
+++ freeswitch/trunk/conf/console.conf.xml Wed Feb 28 13:28:07 2007
@@ -5,4 +5,8 @@
<!-- <param name="log_event" value="DEBUG"/> -->
<param name="all" value="DEBUG"/>
</mappings>
+ <settings>
+ <!-- uncomment for color logging (for debugging) -->
+ <!--<param name="colorize" value="true"/>-->
+ </settings>
</configuration>
Modified: freeswitch/trunk/src/include/switch_types.h
==============================================================================
--- freeswitch/trunk/src/include/switch_types.h (original)
+++ freeswitch/trunk/src/include/switch_types.h Wed Feb 28 13:28:07 2007
@@ -38,6 +38,68 @@
#include <ctype.h>
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
Modified: freeswitch/trunk/src/mod/loggers/mod_console/mod_console.c
==============================================================================
--- freeswitch/trunk/src/mod/loggers/mod_console/mod_console.c (original)
+++ freeswitch/trunk/src/mod/loggers/mod_console/mod_console.c Wed Feb 28 13:28:07 2007
@@ -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 @@
}
}
+ 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 @@
}
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");
More information about the Freeswitch-svn
mailing list