Newer
Older
* Asterisk -- An open source telephony toolkit.
* Copyright (c) 2004 - 2005 Tilghman Lesher. All rights reserved.
*
* Tilghman Lesher <app_verbose_v001@the-tilghman.com>
*
* This code is released by the author with no restrictions on usage.
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
*/
* \brief Verbose logging application
* \author Tilghman Lesher <app_verbose_v001@the-tilghman.com>
*
Kevin P. Fleming
committed
#include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
Kevin P. Fleming
committed
#include "asterisk/module.h"
Tilghman Lesher
committed
#include "asterisk/app.h"
#include "asterisk/channel.h"
static char *app_verbose = "Verbose";
static char *verbose_synopsis = "Send arbitrary text to verbose output";
static char *verbose_descrip =
Tilghman Lesher
committed
"Verbose([<level>,]<message>)\n"
" level must be an integer value. If not specified, defaults to 0.\n";
Russell Bryant
committed
static char *app_log = "Log";
static char *log_synopsis = "Send arbitrary text to a selected log level";
static char *log_descrip =
Tilghman Lesher
committed
"Log(<level>,<message>)\n"
Russell Bryant
committed
" level must be one of ERROR, WARNING, NOTICE, DEBUG, VERBOSE, DTMF\n";
static int verbose_exec(struct ast_channel *chan, void *data)
{
int vsize;
Tilghman Lesher
committed
char *parse;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(level);
AST_APP_ARG(msg);
);
Tilghman Lesher
committed
if (ast_strlen_zero(data)) {
return 0;
Tilghman Lesher
committed
}
parse = ast_strdupa(data);
AST_STANDARD_APP_ARGS(args, parse);
if (args.argc == 1) {
args.msg = args.level;
args.level = "0";
}
if (sscanf(args.level, "%d", &vsize) != 1) {
vsize = 0;
Tilghman Lesher
committed
ast_log(LOG_WARNING, "'%s' is not a verboser number\n", args.level);
}
if (option_verbose >= vsize) {
switch (vsize) {
case 0:
Tilghman Lesher
committed
ast_verbose("%s\n", args.msg);
break;
case 1:
Tilghman Lesher
committed
ast_verbose(VERBOSE_PREFIX_1 "%s\n", args.msg);
break;
case 2:
Tilghman Lesher
committed
ast_verbose(VERBOSE_PREFIX_2 "%s\n", args.msg);
break;
case 3:
Tilghman Lesher
committed
ast_verbose(VERBOSE_PREFIX_3 "%s\n", args.msg);
break;
default:
Tilghman Lesher
committed
ast_verbose(VERBOSE_PREFIX_4 "%s\n", args.msg);
Russell Bryant
committed
static int log_exec(struct ast_channel *chan, void *data)
{
Tilghman Lesher
committed
char *parse;
Russell Bryant
committed
int lnum = -1;
char extension[AST_MAX_EXTENSION + 5], context[AST_MAX_EXTENSION + 2];
Tilghman Lesher
committed
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(level);
AST_APP_ARG(msg);
);
Russell Bryant
committed
if (ast_strlen_zero(data))
Russell Bryant
committed
return 0;
Tilghman Lesher
committed
parse = ast_strdupa(data);
AST_STANDARD_APP_ARGS(args, parse);
Russell Bryant
committed
Tilghman Lesher
committed
if (!strcasecmp(args.level, "ERROR")) {
Russell Bryant
committed
lnum = __LOG_ERROR;
Tilghman Lesher
committed
} else if (!strcasecmp(args.level, "WARNING")) {
Russell Bryant
committed
lnum = __LOG_WARNING;
Tilghman Lesher
committed
} else if (!strcasecmp(args.level, "NOTICE")) {
Russell Bryant
committed
lnum = __LOG_NOTICE;
Tilghman Lesher
committed
} else if (!strcasecmp(args.level, "DEBUG")) {
Russell Bryant
committed
lnum = __LOG_DEBUG;
Tilghman Lesher
committed
} else if (!strcasecmp(args.level, "VERBOSE")) {
Russell Bryant
committed
lnum = __LOG_VERBOSE;
Tilghman Lesher
committed
} else if (!strcasecmp(args.level, "DTMF")) {
Russell Bryant
committed
lnum = __LOG_DTMF;
Tilghman Lesher
committed
} else if (!strcasecmp(args.level, "EVENT")) {
Russell Bryant
committed
lnum = __LOG_EVENT;
} else {
Tilghman Lesher
committed
ast_log(LOG_ERROR, "Unknown log level: '%s'\n", args.level);
Russell Bryant
committed
}
if (lnum > -1) {
snprintf(context, sizeof(context), "@ %s", chan->context);
snprintf(extension, sizeof(extension), "Ext. %s", chan->exten);
Tilghman Lesher
committed
ast_log(lnum, extension, chan->priority, context, "%s\n", args.msg);
Russell Bryant
committed
}
Russell Bryant
committed
return 0;
}
static int unload_module(void)
Russell Bryant
committed
int res;
res = ast_unregister_application(app_verbose);
Russell Bryant
committed
res |= ast_unregister_application(app_log);
Russell Bryant
committed
return res;
static int load_module(void)
Russell Bryant
committed
int res;
res = ast_register_application(app_log, log_exec, log_synopsis, log_descrip);
res |= ast_register_application(app_verbose, verbose_exec, verbose_synopsis, verbose_descrip);
return res;
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send verbose output");