Index: logger.c =================================================================== RCS file: /usr/cvsroot/asterisk/logger.c,v retrieving revision 1.55 diff -u -r1.55 logger.c --- logger.c 25 Jan 2005 06:10:19 -0000 1.55 +++ logger.c 11 Feb 2005 07:19:07 -0000 @@ -68,6 +68,9 @@ static char hostname[256]; +static char** filterout = NULL; +static int filterout_count = 0; + struct logchannel { int logmask; int facility; /* syslog */ @@ -250,7 +253,10 @@ struct logchannel *chan, *cur; struct ast_config *cfg; struct ast_variable *var; + char **filterouttmp; + char *tok; char *s; + int index; /* delete our list of log channels */ ast_mutex_lock(&loglock); @@ -299,6 +305,43 @@ var = var->next; } + /* Process outgoing filter configuration. filterout=\ delimited values to look for in log output */ + /* And I didn't put in the 5+ checks for out of memory after allocations... */ + free(filterout); + filterout = NULL; + filterout_count = 0; + if ((s = ast_variable_retrieve(cfg, "general", "filterout"))) + { + index = 0; + filterout_count = 8; /* Good starting point is 8 items? */ + filterout = (char**)malloc(sizeof(char**) * filterout_count); + + s = strdup(s); /* Not sure it's safe to modify ast_config's buffers */ + tok = strtok(s, "\\"); + + while(tok && index < 128) /* If there's more than 128 filters, something's wrong. */ + { + filterout[index] = strdup(tok); + index++; + if (index == filterout_count) + { + filterouttmp = (char**)realloc(filterout, sizeof(char**) * filterout_count * 2); + if (!filterouttmp) + { + ast_log(LOG_ERROR, "Out of memory while expanding filterout.\n"); + ast_config_destroy(cfg); + ast_mutex_unlock(&loglock); + return; + } + filterout_count *= 2; + filterout = filterouttmp; + } + tok = strtok(NULL, "\\"); + } + free(s); + filterout_count = index; + filterout = (char**)realloc(filterout, sizeof(char**) * filterout_count * 2); + } ast_config_destroy(cfg); ast_mutex_unlock(&loglock); } @@ -555,6 +598,8 @@ time_t t; struct tm tm; char date[256]; + char *filter; + int index; va_list ap; @@ -564,6 +609,30 @@ /* Ignore anything that never gets logged anywhere */ if (!(global_logmask & (1 << level))) return; + + /* Check for filtering */ + if (filterout) + { + buf[BUFSIZ - 1] = '\0'; + + index = snprintf(buf, sizeof(buf) - 1, "%s:%d %s: ", file, line, function); + + va_start(ap, fmt); + vsnprintf(buf + index, sizeof(buf) - index - 1, fmt, ap); + va_end(ap); + + for(index = 0; index < filterout_count; index++) + { + if (filterout[index]) + { + filter = strstr(buf, filterout[index]); + if (filter && filter != buf) + { + return; /* Filter found, don't log */ + } + } + } + } /* begin critical section */ ast_mutex_lock(&loglock);