Index: include/asterisk/logger.h =================================================================== --- include/asterisk/logger.h (revision 84691) +++ include/asterisk/logger.h (working copy) @@ -84,8 +84,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); +void ast_console_toggle_loglevel(int fd, int level, int state); #define _A_ __FILE__, __LINE__, __PRETTY_FUNCTION__ @@ -131,6 +132,8 @@ #define __LOG_DTMF 6 #define LOG_DTMF __LOG_DTMF, _A_ +#define NUMLOGLEVELS 6 + /*! * \brief Get the debug level for a file * \arg file the filename Index: main/asterisk.c =================================================================== --- main/asterisk.c (revision 84691) +++ main/asterisk.c (working copy) @@ -183,6 +183,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 { @@ -802,6 +803,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 */ @@ -825,14 +837,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); + } } } @@ -840,11 +854,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); } /*! @@ -872,7 +886,7 @@ static void network_verboser(const char *s) { - ast_network_puts_mutable(s); + ast_network_puts_mutable(s, __LOG_VERBOSE); } static pthread_t lthread; Index: main/logger.c =================================================================== --- main/logger.c (revision 84149) +++ main/logger.c (working copy) @@ -654,6 +654,39 @@ return CLI_SUCCESS; } +static char *handle_logger_set_level(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) +{ + int x, state, 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 enables/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; + } + } + if (ast_true(a->argv[4])) + state = 0; + else + state = 1; + + ast_cli(a->fd, "LEVEL %d STATUS %d\n", level, state); + if (level >= 0) + ast_console_toggle_loglevel(a->fd, level, state); + + 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) { @@ -710,7 +743,8 @@ static struct ast_cli_entry cli_logger[] = { NEW_CLI(handle_logger_show_channels, "List configured log channels"), NEW_CLI(handle_logger_reload, "Reopens the log files"), - NEW_CLI(handle_logger_rotate, "Rotates and reopens the log files") + NEW_CLI(handle_logger_rotate, "Rotates and reopens the log files"), + NEW_CLI(handle_logger_set_level, "Enables/Disables a specific logging level for this console") }; static int handle_SIGXFSZ(int sig) @@ -789,7 +823,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;