瀏覽代碼

xlog: new module parameters log_colors

- update the colorscheme for log levels
Elena-Ramona Modroiu 13 年之前
父節點
當前提交
a5a58239ef
共有 3 個文件被更改,包括 138 次插入12 次删除
  1. 32 12
      modules_k/xlog/README
  2. 23 0
      modules_k/xlog/doc/xlog_admin.xml
  3. 83 0
      modules_k/xlog/xlog.c

+ 32 - 12
modules_k/xlog/README

@@ -11,9 +11,9 @@ Elena-Ramona Modroiu
 
 
    <[email protected]>
    <[email protected]>
 
 
-   Copyright © 2003 FhG FOKUS
+   Copyright © 2003 FhG FOKUS
 
 
-   Copyright © 2008-2010 Elena-Ramona Modroiu
+   Copyright © 2008-2010 Elena-Ramona Modroiu
      __________________________________________________________________
      __________________________________________________________________
 
 
    Table of Contents
    Table of Contents
@@ -34,6 +34,7 @@ Elena-Ramona Modroiu
               4.3. long_format (integer)
               4.3. long_format (integer)
               4.4. prefix (str)
               4.4. prefix (str)
               4.5. log_facility (string)
               4.5. log_facility (string)
+              4.6. log_colors (string)
 
 
         5. Functions
         5. Functions
 
 
@@ -49,8 +50,9 @@ Elena-Ramona Modroiu
    1.3. Set long_format parameter
    1.3. Set long_format parameter
    1.4. Set prefix parameter
    1.4. Set prefix parameter
    1.5. log_facility example
    1.5. log_facility example
-   1.6. xlog usage
-   1.7. xdbg usage
+   1.6. log_colors example
+   1.7. xlog usage
+   1.8. xdbg usage
 
 
 Chapter 1. Admin Guide
 Chapter 1. Admin Guide
 
 
@@ -70,6 +72,7 @@ Chapter 1. Admin Guide
         4.3. long_format (integer)
         4.3. long_format (integer)
         4.4. prefix (str)
         4.4. prefix (str)
         4.5. log_facility (string)
         4.5. log_facility (string)
+        4.6. log_colors (string)
 
 
    5. Functions
    5. Functions
 
 
@@ -83,7 +86,7 @@ Chapter 1. Admin Guide
    This module provides the possibility to print user formatted log or
    This module provides the possibility to print user formatted log or
    debug messages from Kamailio scripts, similar to the printf function. A
    debug messages from Kamailio scripts, similar to the printf function. A
    C-style printf specifier is replaced with a part of the SIP request or
    C-style printf specifier is replaced with a part of the SIP request or
-   other variables from system. Section 2, "Implemented Specifiers" shows
+   other variables from system. Section 2, “Implemented Specifiers� shows
    what can be printed out.
    what can be printed out.
 
 
 2. Implemented Specifiers
 2. Implemented Specifiers
@@ -126,6 +129,7 @@ Chapter 1. Admin Guide
    4.3. long_format (integer)
    4.3. long_format (integer)
    4.4. prefix (str)
    4.4. prefix (str)
    4.5. log_facility (string)
    4.5. log_facility (string)
+   4.6. log_colors (string)
 
 
 4.1. buf_size (integer)
 4.1. buf_size (integer)
 
 
@@ -184,6 +188,22 @@ modparam("xlog", "prefix", "-xlog: ")
    Example 1.5. log_facility example
    Example 1.5. log_facility example
 modparam("xlog", "log_facility", "LOG_DAEMON")
 modparam("xlog", "log_facility", "LOG_DAEMON")
 
 
+4.6. log_colors (string)
+
+   Update terminal colors used by core for log levels (when log_stderr=1
+   and log_color=1). The value has to be 'logname=colors', where colors is
+   two characters specifying foreground and background in the same format
+   as $C(xy) variable.
+
+   The parameter can be set many times, its value can also be a
+   ';'-separated list of color specs.
+
+   Default value is NULL.
+
+   Example 1.6. log_colors example
+modparam("xlog", "log_colors", "L_ERR=cr")
+modparam("xlog", "log_colors", "L_ERR=cr;L_WARN=px")
+
 5. Functions
 5. Functions
 
 
    5.1. xlog([ [facility,] level,] format)
    5.1. xlog([ [facility,] level,] format)
@@ -191,7 +211,7 @@ modparam("xlog", "log_facility", "LOG_DAEMON")
    5.3. xlogl([ [facility,] level,] format)
    5.3. xlogl([ [facility,] level,] format)
    5.4. xdbgl(format)
    5.4. xdbgl(format)
 
 
-5.1. xlog([ [facility,] level,] format)
+5.1.  xlog([ [facility,] level,] format)
 
 
    Print a formated message using LOG function.
    Print a formated message using LOG function.
 
 
@@ -214,13 +234,13 @@ modparam("xlog", "log_facility", "LOG_DAEMON")
             See above options for valid log levels.
             See above options for valid log levels.
        If it is not a pseudo-variable, then what really matters is the
        If it is not a pseudo-variable, then what really matters is the
        third letter of the value. If the log level is higher than the
        third letter of the value. If the log level is higher than the
-       "debug" global parameter, the message is not printed to syslog.
+       “debug� global parameter, the message is not printed to syslog.
        If this parameter is missing, the implicit log level is 'L_ERR'.
        If this parameter is missing, the implicit log level is 'L_ERR'.
      * format - The formatted string to be printed.
      * format - The formatted string to be printed.
 
 
    This function can be used from ANY_ROUTE.
    This function can be used from ANY_ROUTE.
 
 
-   Example 1.6. xlog usage
+   Example 1.7. xlog usage
 ...
 ...
 xlog("L_ERR", "time [$Tf] method ($rm) r-uri ($ru) 2nd via ($hdr(via[1]))\n");
 xlog("L_ERR", "time [$Tf] method ($rm) r-uri ($ru) 2nd via ($hdr(via[1]))\n");
 ...
 ...
@@ -233,7 +253,7 @@ xlog("LOG_LOCAL3", "L_ERR", "this message will be sent to syslog facility LOG_LO
 CAL3\n");
 CAL3\n");
 ...
 ...
 
 
-5.2. xdbg(format)
+5.2.  xdbg(format)
 
 
    Print a formatted message using DBG function.
    Print a formatted message using DBG function.
 
 
@@ -242,17 +262,17 @@ CAL3\n");
 
 
    This function can be used from ANY_ROUTE.
    This function can be used from ANY_ROUTE.
 
 
-   Example 1.7. xdbg usage
+   Example 1.8. xdbg usage
 ...
 ...
 xdbg("time $Cbx[$Tf]$Cxx method ($rm) r-uri ($ru)\n");
 xdbg("time $Cbx[$Tf]$Cxx method ($rm) r-uri ($ru)\n");
 ...
 ...
 
 
-5.3. xlogl([ [facility,] level,] format)
+5.3.  xlogl([ [facility,] level,] format)
 
 
    Similar to xlog(), in addition is printing cfg line number at the
    Similar to xlog(), in addition is printing cfg line number at the
    beginning of message.
    beginning of message.
 
 
-5.4. xdbgl(format)
+5.4.  xdbgl(format)
 
 
    Similar to xdbg(), in addition is printing cfg line number at the
    Similar to xdbg(), in addition is printing cfg line number at the
    beginning of message.
    beginning of message.

+ 23 - 0
modules_k/xlog/doc/xlog_admin.xml

@@ -185,6 +185,29 @@ modparam("xlog", "prefix", "-xlog: ")
 		<title>log_facility example</title>
 		<title>log_facility example</title>
 		<programlisting format="linespecific">
 		<programlisting format="linespecific">
 modparam("xlog", "log_facility", "LOG_DAEMON")
 modparam("xlog", "log_facility", "LOG_DAEMON")
+</programlisting>
+		</example>
+	</section>
+	<section>
+		<title><varname>log_colors</varname> (string)</title>
+		<para>
+		Update terminal colors used by core for log levels (when log_stderr=1
+		and log_color=1). The value has to be 'logname=colors', where colors
+		is two characters specifying foreground and background in the same
+		format as $C(xy) variable.
+		</para>
+		<para>
+		The parameter can be set many times, its value can also be a
+		';'-separated list of color specs.
+		</para>
+		<para>
+		Default value is NULL.
+		</para>
+		<example>
+		<title>log_colors example</title>
+		<programlisting format="linespecific">
+modparam("xlog", "log_colors", "L_ERR=cr")
+modparam("xlog", "log_colors", "L_ERR=cr;L_WARN=px")
 </programlisting>
 </programlisting>
 		</example>
 		</example>
 	</section>
 	</section>

+ 83 - 0
modules_k/xlog/xlog.c

@@ -34,6 +34,7 @@
 #include "../../dprint.h"
 #include "../../dprint.h"
 #include "../../error.h"
 #include "../../error.h"
 #include "../../mem/mem.h"
 #include "../../mem/mem.h"
+#include "../../parser/parse_param.h"
 
 
 #include "xl_lib.h"
 #include "xl_lib.h"
 
 
@@ -75,6 +76,8 @@ static int xdbgl_fixup(void** param, int param_no);
 
 
 static void destroy(void);
 static void destroy(void);
 
 
+static int xlog_log_colors_param(modparam_t type, void *val);
+
 int pv_parse_color_name(pv_spec_p sp, str *in);
 int pv_parse_color_name(pv_spec_p sp, str *in);
 static int pv_get_color(struct sip_msg *msg, pv_param_t *param, 
 static int pv_get_color(struct sip_msg *msg, pv_param_t *param, 
 		pv_value_t *res);
 		pv_value_t *res);
@@ -120,6 +123,7 @@ static param_export_t params[]={
 	{"long_format",  INT_PARAM, &long_format},
 	{"long_format",  INT_PARAM, &long_format},
 	{"prefix",       STR_PARAM, &_xlog_prefix},
 	{"prefix",       STR_PARAM, &_xlog_prefix},
 	{"log_facility", STR_PARAM, &xlog_facility_name},
 	{"log_facility", STR_PARAM, &xlog_facility_name},
+	{"log_colors",   STR_PARAM|USE_FUNC_PARAM, (void*)xlog_log_colors_param},
 	{0,0,0}
 	{0,0,0}
 };
 };
 
 
@@ -713,3 +717,82 @@ error:
 	return -1;
 	return -1;
 }
 }
 
 
+/**
+ *
+ */
+static int xlog_log_colors_param(modparam_t type, void *val)
+{
+	param_t* params_list = NULL;
+	param_hooks_t phooks;
+	param_t *pit=NULL;
+	str s;
+	int level;
+
+	if(val==NULL)
+		goto error;
+
+	s.s = (char*)val;
+	s.len = strlen(s.s);
+
+	if(s.len<=0)
+		goto error;
+
+	if(s.s[s.len-1]==';')
+		s.len--;
+	if (parse_params(&s, CLASS_ANY, &phooks, &params_list)<0)
+		goto error;
+
+	for (pit = params_list; pit; pit=pit->next)
+	{
+		if (pit->name.len==7
+				&& strncasecmp(pit->name.s, "l_alert", 7)==0) {
+			level = L_ALERT;
+		} else if (pit->name.len==5
+				&& strncasecmp(pit->name.s, "l_bug", 5)==0) {
+			level = L_BUG;
+		} else if (pit->name.len==7
+				&& strncasecmp(pit->name.s, "l_crit2", 7)==0) {
+			level = L_CRIT2;
+		} else if (pit->name.len==6
+				&& strncasecmp(pit->name.s, "l_crit", 6)==0) {
+			level = L_CRIT;
+		} else if (pit->name.len==5
+				&& strncasecmp(pit->name.s, "l_err", 5)==0) {
+			level = L_ERR;
+		} else if (pit->name.len==6
+				&& strncasecmp(pit->name.s, "l_warn", 6)==0) {
+			level = L_WARN;
+		} else if (pit->name.len==8
+				&& strncasecmp(pit->name.s, "l_notice", 8)==0) {
+			level = L_NOTICE;
+		} else if (pit->name.len==6
+				&& strncasecmp(pit->name.s, "l_info", 6)==0) {
+			level = L_INFO;
+		} else if (pit->name.len==5
+				&& strncasecmp(pit->name.s, "l_dbg", 5)==0) {
+			level = L_DBG;
+		} else {
+			LM_ERR("invalid level name %.*s\n",
+					pit->name.len, pit->name.s);
+			goto error;
+		}
+			
+		if(pit->body.len!=2) {
+			LM_ERR("invalid color spec for level %.*s (%.*s)\n",
+					pit->name.len, pit->name.s,
+					pit->body.len, pit->body.s);
+			goto error;
+		}
+		dprint_color_update(level, pit->body.s[0], pit->body.s[1]);
+	}
+
+	if(params_list!=NULL)
+		free_params(params_list);
+	return 0;
+
+error:
+	if(params_list!=NULL)
+		free_params(params_list);
+	return -1;
+
+}