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
29 ASTERISK_FILE_VERSION(__FILE__
, "$Revision$")
36 #include "asterisk/options.h"
37 #include "asterisk/logger.h"
38 #include "asterisk/channel.h"
39 #include "asterisk/pbx.h"
40 #include "asterisk/module.h"
42 static char *app_verbose
= "Verbose";
43 static char *verbose_synopsis
= "Send arbitrary text to verbose output";
44 static char *verbose_descrip
=
45 "Verbose([<level>|]<message>)\n"
46 " level must be an integer value. If not specified, defaults to 0.\n";
48 static char *app_log
= "Log";
49 static char *log_synopsis
= "Send arbitrary text to a selected log level";
50 static char *log_descrip
=
51 "Log(<level>|<message>)\n"
52 " level must be one of ERROR, WARNING, NOTICE, DEBUG, VERBOSE, DTMF\n";
55 static int verbose_exec(struct ast_channel
*chan
, void *data
)
59 struct ast_module_user
*u
;
61 u
= ast_module_user_add(chan
);
65 vtext
= ast_strdupa(data
);
66 tmp
= strsep(&vtext
, "|");
68 if (sscanf(tmp
, "%d", &vsize
) != 1) {
70 ast_log(LOG_WARNING
, "'%s' is not a verboser number\n", vtext
);
76 if (option_verbose
>= vsize
) {
79 ast_verbose("%s\n", vtext
);
82 ast_verbose(VERBOSE_PREFIX_1
"%s\n", vtext
);
85 ast_verbose(VERBOSE_PREFIX_2
"%s\n", vtext
);
88 ast_verbose(VERBOSE_PREFIX_3
"%s\n", vtext
);
91 ast_verbose(VERBOSE_PREFIX_4
"%s\n", vtext
);
96 ast_module_user_remove(u
);
101 static int log_exec(struct ast_channel
*chan
, void *data
)
104 struct ast_module_user
*u
;
106 char extension
[AST_MAX_EXTENSION
+ 5], context
[AST_MAX_EXTENSION
+ 2];
108 u
= ast_module_user_add(chan
);
109 if (ast_strlen_zero(data
)) {
110 ast_module_user_remove(u
);
114 ltext
= ast_strdupa(data
);
116 level
= strsep(<ext
, "|");
118 if (!strcasecmp(level
, "ERROR")) {
120 } else if (!strcasecmp(level
, "WARNING")) {
121 lnum
= __LOG_WARNING
;
122 } else if (!strcasecmp(level
, "NOTICE")) {
124 } else if (!strcasecmp(level
, "DEBUG")) {
126 } else if (!strcasecmp(level
, "VERBOSE")) {
127 lnum
= __LOG_VERBOSE
;
128 } else if (!strcasecmp(level
, "DTMF")) {
130 } else if (!strcasecmp(level
, "EVENT")) {
133 ast_log(LOG_ERROR
, "Unknown log level: '%s'\n", level
);
137 snprintf(context
, sizeof(context
), "@ %s", chan
->context
);
138 snprintf(extension
, sizeof(extension
), "Ext. %s", chan
->exten
);
140 ast_log(lnum
, extension
, chan
->priority
, context
, "%s\n", ltext
);
142 ast_module_user_remove(u
);
146 static int unload_module(void)
150 res
= ast_unregister_application(app_verbose
);
151 res
|= ast_unregister_application(app_log
);
153 ast_module_user_hangup_all();
158 static int load_module(void)
162 res
= ast_register_application(app_log
, log_exec
, log_synopsis
, log_descrip
);
163 res
|= ast_register_application(app_verbose
, verbose_exec
, verbose_synopsis
, verbose_descrip
);
168 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY
, "Send verbose output");