Creating tag for the release of asterisk-1.6.1-beta1
[asterisk-bristuff.git] / apps / app_verbose.c
blob525cc1c55c59d66916a0081586b63e2636db21c3
1 /*
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.
18 /*! \file
20 * \brief Verbose logging application
22 * \author Tilghman Lesher <app_verbose_v001@the-tilghman.com>
24 * \ingroup applications
27 #include "asterisk.h"
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)
50 int vsize;
51 char *parse;
52 AST_DECLARE_APP_ARGS(args,
53 AST_APP_ARG(level);
54 AST_APP_ARG(msg);
57 if (ast_strlen_zero(data)) {
58 return 0;
61 parse = ast_strdupa(data);
62 AST_STANDARD_APP_ARGS(args, parse);
63 if (args.argc == 1) {
64 args.msg = args.level;
65 args.level = "0";
68 if (sscanf(args.level, "%d", &vsize) != 1) {
69 vsize = 0;
70 ast_log(LOG_WARNING, "'%s' is not a verboser number\n", args.level);
72 if (option_verbose >= vsize) {
73 switch (vsize) {
74 case 0:
75 ast_verbose("%s\n", args.msg);
76 break;
77 case 1:
78 ast_verbose(VERBOSE_PREFIX_1 "%s\n", args.msg);
79 break;
80 case 2:
81 ast_verbose(VERBOSE_PREFIX_2 "%s\n", args.msg);
82 break;
83 case 3:
84 ast_verbose(VERBOSE_PREFIX_3 "%s\n", args.msg);
85 break;
86 default:
87 ast_verbose(VERBOSE_PREFIX_4 "%s\n", args.msg);
91 return 0;
94 static int log_exec(struct ast_channel *chan, void *data)
96 char *parse;
97 int lnum = -1;
98 char extension[AST_MAX_EXTENSION + 5], context[AST_MAX_EXTENSION + 2];
99 AST_DECLARE_APP_ARGS(args,
100 AST_APP_ARG(level);
101 AST_APP_ARG(msg);
104 if (ast_strlen_zero(data))
105 return 0;
107 parse = ast_strdupa(data);
108 AST_STANDARD_APP_ARGS(args, parse);
110 if (!strcasecmp(args.level, "ERROR")) {
111 lnum = __LOG_ERROR;
112 } else if (!strcasecmp(args.level, "WARNING")) {
113 lnum = __LOG_WARNING;
114 } else if (!strcasecmp(args.level, "NOTICE")) {
115 lnum = __LOG_NOTICE;
116 } else if (!strcasecmp(args.level, "DEBUG")) {
117 lnum = __LOG_DEBUG;
118 } else if (!strcasecmp(args.level, "VERBOSE")) {
119 lnum = __LOG_VERBOSE;
120 } else if (!strcasecmp(args.level, "DTMF")) {
121 lnum = __LOG_DTMF;
122 } else if (!strcasecmp(args.level, "EVENT")) {
123 lnum = __LOG_EVENT;
124 } else {
125 ast_log(LOG_ERROR, "Unknown log level: '%s'\n", args.level);
128 if (lnum > -1) {
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);
135 return 0;
138 static int unload_module(void)
140 int res;
142 res = ast_unregister_application(app_verbose);
143 res |= ast_unregister_application(app_log);
145 return res;
148 static int load_module(void)
150 int res;
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);
155 return res;
158 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send verbose output");