2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (c) 2004 - 2005 Tilghman Lesher. All rights reserved.
6 * Tilghman Lesher <app_verbose_v001@the-tilghman.com>
8 * This code is released by the author with no restrictions on usage.
10 * See http://www.asterisk.org for more information about
11 * the Asterisk project. Please do not directly contact
12 * any of the maintainers of this project for assistance;
13 * the project provides a web site, mailing lists and IRC
14 * channels for your use.
20 * \brief Verbose logging application
22 * \author Tilghman Lesher <app_verbose_v001@the-tilghman.com>
24 * \ingroup applications
28 <support_level>core</support_level>
33 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
35 #include "asterisk/module.h"
36 #include "asterisk/app.h"
37 #include "asterisk/channel.h"
39 static char *app_verbose = "Verbose";
40 static char *app_log = "Log";
43 <application name="Verbose" language="en_US">
45 Send arbitrary text to verbose output.
48 <parameter name="level">
49 <para>Must be an integer value. If not specified, defaults to 0.</para>
51 <parameter name="message" required="true">
52 <para>Output text message.</para>
56 <para>Sends an arbitrary text message to verbose output.</para>
59 <application name="Log" language="en_US">
61 Send arbitrary text to a selected log level.
64 <parameter name="level" required="true">
65 <para>Level must be one of <literal>ERROR</literal>, <literal>WARNING</literal>, <literal>NOTICE</literal>,
66 <literal>DEBUG</literal>, <literal>VERBOSE</literal> or <literal>DTMF</literal>.</para>
68 <parameter name="message" required="true">
69 <para>Output text message.</para>
73 <para>Sends an arbitrary text message to a selected log level.</para>
79 static int verbose_exec(struct ast_channel *chan, const char *data)
83 AST_DECLARE_APP_ARGS(args,
88 if (ast_strlen_zero(data)) {
92 parse = ast_strdupa(data);
93 AST_STANDARD_APP_ARGS(args, parse);
95 args.msg = args.level;
99 if (sscanf(args.level, "%30d", &vsize) != 1) {
101 ast_log(LOG_WARNING, "'%s' is not a verboser number\n", args.level);
103 if (option_verbose >= vsize) {
106 ast_verb(0, "%s\n", args.msg);
109 ast_verb(1, "%s\n", args.msg);
112 ast_verb(2, "%s\n", args.msg);
115 ast_verb(3, "%s\n", args.msg);
118 ast_verb(4, "%s\n", args.msg);
125 static int log_exec(struct ast_channel *chan, const char *data)
129 char extension[AST_MAX_EXTENSION + 5], context[AST_MAX_EXTENSION + 2];
130 AST_DECLARE_APP_ARGS(args,
135 if (ast_strlen_zero(data))
138 parse = ast_strdupa(data);
139 AST_STANDARD_APP_ARGS(args, parse);
141 if (!strcasecmp(args.level, "ERROR")) {
143 } else if (!strcasecmp(args.level, "WARNING")) {
144 lnum = __LOG_WARNING;
145 } else if (!strcasecmp(args.level, "NOTICE")) {
147 } else if (!strcasecmp(args.level, "DEBUG")) {
149 } else if (!strcasecmp(args.level, "VERBOSE")) {
150 lnum = __LOG_VERBOSE;
151 } else if (!strcasecmp(args.level, "DTMF")) {
154 ast_log(LOG_ERROR, "Unknown log level: '%s'\n", args.level);
158 snprintf(context, sizeof(context), "@ %s", ast_channel_context(chan));
159 snprintf(extension, sizeof(extension), "Ext. %s", ast_channel_exten(chan));
161 ast_log(lnum, extension, ast_channel_priority(chan), context, "%s\n", args.msg);
167 static int unload_module(void)
171 res = ast_unregister_application(app_verbose);
172 res |= ast_unregister_application(app_log);
177 static int load_module(void)
181 res = ast_register_application_xml(app_log, log_exec);
182 res |= ast_register_application_xml(app_verbose, verbose_exec);
187 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send verbose output");