Index: apps/app_verbose.c =================================================================== RCS file: /usr/cvsroot/asterisk/apps/app_verbose.c,v retrieving revision 1.6 diff -u -r1.6 app_verbose.c --- apps/app_verbose.c 15 Sep 2005 15:44:26 -0000 1.6 +++ apps/app_verbose.c 25 Sep 2005 06:07:46 -0000 @@ -40,14 +40,19 @@ static char *tdesc = "Send verbose output"; static char *app_verbose = "Verbose"; - static char *verbose_synopsis = "Send arbitrary text to verbose output"; - static char *verbose_descrip = "Verbose([|])\n" " level must be an integer value. If not specified, defaults to 0." " Always returns 0.\n"; +static char *app_log = "Log"; +static char *log_synopsis = "Send arbitrary text to a selected log level"; +static char *log_descrip = +"Log(|)\n" +" level must be one of ERROR, WARNING, NOTICE, DEBUG, VERBOSE, DTMF\n" +" Always returns 0.\n"; + STANDARD_LOCAL_USER; LOCAL_USER_DECL; @@ -96,14 +101,58 @@ return 0; } +static int log_exec(struct ast_channel *chan, void *data) +{ + char *level, *ltext; + if (data) { + ltext = ast_strdupa((char *)data); + if (! ltext) { + ast_log(LOG_ERROR, "Out of memory\n"); + } else { + int lnum = -1; + char extension[AST_MAX_EXTENSION + 5], context[AST_MAX_EXTENSION + 2]; + + level = strsep(<ext, "|"); + + if (!strcasecmp(level, "ERROR")) { + lnum = __LOG_ERROR; + } else if (!strcasecmp(level, "WARNING")) { + lnum = __LOG_WARNING; + } else if (!strcasecmp(level, "NOTICE")) { + lnum = __LOG_NOTICE; + } else if (!strcasecmp(level, "DEBUG")) { + lnum = __LOG_DEBUG; + } else if (!strcasecmp(level, "VERBOSE")) { + lnum = __LOG_VERBOSE; + } else if (!strcasecmp(level, "DTMF")) { + lnum = __LOG_DTMF; + } else if (!strcasecmp(level, "EVENT")) { + lnum = __LOG_EVENT; + } else { + ast_log(LOG_ERROR, "Unknown log level: '%s'\n", level); + } + + if (lnum > -1) { + snprintf(context, sizeof(context), "@ %s", chan->context); + snprintf(extension, sizeof(extension), "Ext. %s", chan->exten); + + ast_log(lnum, extension, chan->priority, context, "%s\n", ltext); + } + } + } + return 0; +} + int unload_module(void) { STANDARD_HANGUP_LOCALUSERS; + ast_unregister_application(app_log); return ast_unregister_application(app_verbose); } int load_module(void) { + ast_register_application(app_log, log_exec, log_synopsis, log_descrip); return ast_register_application(app_verbose, verbose_exec, verbose_synopsis, verbose_descrip); }