[asterisk-commits] bbryant: trunk r119126 - in /trunk: include/asterisk/ main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu May 29 16:30:38 CDT 2008
Author: bbryant
Date: Thu May 29 16:30:37 2008
New Revision: 119126
URL: http://svn.digium.com/view/asterisk?view=rev&rev=119126
Log:
Adds support for changing logger settingss on remote consoles with a
new command "logger set level".
i.e. "logger set level debug off"
(closes issue #10891)
Modified:
trunk/include/asterisk/logger.h
trunk/main/asterisk.c
trunk/main/logger.c
Modified: trunk/include/asterisk/logger.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/logger.h?view=diff&rev=119126&r1=119125&r2=119126
==============================================================================
--- trunk/include/asterisk/logger.h (original)
+++ trunk/include/asterisk/logger.h Thu May 29 16:30:37 2008
@@ -88,8 +88,9 @@
void ast_console_puts(const char *string);
-void ast_console_puts_mutable(const char *string);
+void ast_console_puts_mutable(const char *string, int level);
void ast_console_toggle_mute(int fd, int silent);
+void ast_console_toggle_loglevel(int fd, int leve, int state);
/* Note: The AST_LOG_* macros below are the same as
* the LOG_* macros and are intended to eventually replace
@@ -177,6 +178,8 @@
#undef AST_LOG_DTMF
#endif
#define AST_LOG_DTMF __LOG_DTMF, _A_
+
+#define NUMLOGLEVELS 6
/*!
* \brief Get the debug level for a file
Modified: trunk/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/trunk/main/asterisk.c?view=diff&rev=119126&r1=119125&r2=119126
==============================================================================
--- trunk/main/asterisk.c (original)
+++ trunk/main/asterisk.c Thu May 29 16:30:37 2008
@@ -179,6 +179,7 @@
int p[2]; /*!< Pipe */
pthread_t t; /*!< Thread of handler */
int mute; /*!< Is the console muted for logs */
+ int levels[NUMLOGLEVELS]; /*!< Which log levels are enabled for the console */
};
struct ast_atexit {
@@ -900,6 +901,17 @@
return res;
}
+void ast_console_toggle_loglevel(int fd, int level, int state)
+{
+ int x;
+ for (x = 0;x < AST_MAX_CONNECTS; x++) {
+ if (fd == consoles[x].fd) {
+ consoles[x].levels[level] = state;
+ return;
+ }
+ }
+}
+
/*!
* \brief mute or unmute a console from logging
*/
@@ -925,14 +937,16 @@
/*!
* \brief log the string to all attached console clients
*/
-static void ast_network_puts_mutable(const char *string)
+static void ast_network_puts_mutable(const char *string, int level)
{
int x;
for (x = 0;x < AST_MAX_CONNECTS; x++) {
if (consoles[x].mute)
continue;
- if (consoles[x].fd > -1)
- fdprint(consoles[x].p[1], string);
+ if (consoles[x].fd > -1) {
+ if (!consoles[x].levels[level])
+ fdprint(consoles[x].p[1], string);
+ }
}
}
@@ -940,11 +954,11 @@
* \brief log the string to the console, and all attached
* console clients
*/
-void ast_console_puts_mutable(const char *string)
+void ast_console_puts_mutable(const char *string, int level)
{
fputs(string, stdout);
fflush(stdout);
- ast_network_puts_mutable(string);
+ ast_network_puts_mutable(string, level);
}
/*!
@@ -972,7 +986,7 @@
static void network_verboser(const char *s)
{
- ast_network_puts_mutable(s);
+ ast_network_puts_mutable(s, __LOG_VERBOSE);
}
static pthread_t lthread;
Modified: trunk/main/logger.c
URL: http://svn.digium.com/view/asterisk/trunk/main/logger.c?view=diff&rev=119126&r1=119125&r2=119126
==============================================================================
--- trunk/main/logger.c (original)
+++ trunk/main/logger.c Thu May 29 16:30:37 2008
@@ -728,6 +728,44 @@
return CLI_SUCCESS;
}
+static char *handle_logger_set_level(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ int x;
+ int state;
+ int level = -1;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "logger set level";
+ e->usage =
+ "Usage: logger set level\n"
+ " Set a specific log level to enabled/disabled for this console.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc < 5)
+ return CLI_SHOWUSAGE;
+
+ for (x = 0; x <= NUMLOGLEVELS; x++) {
+ if (!strcasecmp(a->argv[3], levels[x])) {
+ level = x;
+ break;
+ }
+ }
+
+ state = ast_true(a->argv[4]) ? 1 : 0;
+
+ if (level != -1) {
+ ast_console_toggle_loglevel(a->fd, level, state);
+ ast_cli(a->fd, "Logger status for '%s' has been set to '%s'.\n", levels[level], state ? "on" : "off");
+ } else
+ return CLI_SHOWUSAGE;
+
+ return CLI_SUCCESS;
+}
+
/*! \brief CLI command to show logging system configuration */
static char *handle_logger_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
@@ -784,7 +822,8 @@
static struct ast_cli_entry cli_logger[] = {
AST_CLI_DEFINE(handle_logger_show_channels, "List configured log channels"),
AST_CLI_DEFINE(handle_logger_reload, "Reopens the log files"),
- AST_CLI_DEFINE(handle_logger_rotate, "Rotates and reopens the log files")
+ AST_CLI_DEFINE(handle_logger_rotate, "Rotates and reopens the log files"),
+ AST_CLI_DEFINE(handle_logger_set_level, "Enables/Disables a specific logging level for this console")
};
static int handle_SIGXFSZ(int sig)
@@ -863,7 +902,7 @@
term_color(tmp4, logmsg->function, COLOR_BRWHITE, 0, sizeof(tmp4)),
logmsg->str);
/* Print out */
- ast_console_puts_mutable(buf);
+ ast_console_puts_mutable(buf, logmsg->level);
/* File channels */
} else if (chan->type == LOGTYPE_FILE && (chan->logmask & (1 << logmsg->level))) {
int res = 0;
More information about the asterisk-commits
mailing list