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$")
31 #include "asterisk/module.h"
32 #include "asterisk/app.h"
33 #include "asterisk/channel.h"
35 static char *app_verbose
= "Verbose";
36 static char *verbose_synopsis
= "Send arbitrary text to verbose output";
37 static char *verbose_descrip
=
38 "Verbose([<level>,]<message>)\n"
39 " level must be an integer value. If not specified, defaults to 0.\n";
41 static char *app_log
= "Log";
42 static char *log_synopsis
= "Send arbitrary text to a selected log level";
43 static char *log_descrip
=
44 "Log(<level>,<message>)\n"
45 " level must be one of ERROR, WARNING, NOTICE, DEBUG, VERBOSE, DTMF\n";
48 static int verbose_exec(struct ast_channel
*chan
, void *data
)
52 AST_DECLARE_APP_ARGS(args
,
57 if (ast_strlen_zero(data
)) {
61 parse
= ast_strdupa(data
);
62 AST_STANDARD_APP_ARGS(args
, parse
);
64 args
.msg
= args
.level
;
68 if (sscanf(args
.level
, "%d", &vsize
) != 1) {
70 ast_log(LOG_WARNING
, "'%s' is not a verboser number\n", args
.level
);
72 if (option_verbose
>= vsize
) {
75 ast_verbose("%s\n", args
.msg
);
78 ast_verbose(VERBOSE_PREFIX_1
"%s\n", args
.msg
);
81 ast_verbose(VERBOSE_PREFIX_2
"%s\n", args
.msg
);
84 ast_verbose(VERBOSE_PREFIX_3
"%s\n", args
.msg
);
87 ast_verbose(VERBOSE_PREFIX_4
"%s\n", args
.msg
);
94 static int log_exec(struct ast_channel
*chan
, void *data
)
98 char extension
[AST_MAX_EXTENSION
+ 5], context
[AST_MAX_EXTENSION
+ 2];
99 AST_DECLARE_APP_ARGS(args
,
104 if (ast_strlen_zero(data
))
107 parse
= ast_strdupa(data
);
108 AST_STANDARD_APP_ARGS(args
, parse
);
110 if (!strcasecmp(args
.level
, "ERROR")) {
112 } else if (!strcasecmp(args
.level
, "WARNING")) {
113 lnum
= __LOG_WARNING
;
114 } else if (!strcasecmp(args
.level
, "NOTICE")) {
116 } else if (!strcasecmp(args
.level
, "DEBUG")) {
118 } else if (!strcasecmp(args
.level
, "VERBOSE")) {
119 lnum
= __LOG_VERBOSE
;
120 } else if (!strcasecmp(args
.level
, "DTMF")) {
122 } else if (!strcasecmp(args
.level
, "EVENT")) {
125 ast_log(LOG_ERROR
, "Unknown log level: '%s'\n", args
.level
);
129 snprintf(context
, sizeof(context
), "@ %s", chan
->context
);
130 snprintf(extension
, sizeof(extension
), "Ext. %s", chan
->exten
);
132 ast_log(lnum
, extension
, chan
->priority
, context
, "%s\n", args
.msg
);
138 static int unload_module(void)
142 res
= ast_unregister_application(app_verbose
);
143 res
|= ast_unregister_application(app_log
);
148 static int load_module(void)
152 res
= ast_register_application(app_log
, log_exec
, log_synopsis
, log_descrip
);
153 res
|= ast_register_application(app_verbose
, verbose_exec
, verbose_synopsis
, verbose_descrip
);
158 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY
, "Send verbose output");