Wed Jan 8 2020 09:49:40

Asterisk developer's documentation


app_verbose.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (c) 2004 - 2005 Tilghman Lesher. All rights reserved.
5  *
6  * Tilghman Lesher <app_verbose_v001@the-tilghman.com>
7  *
8  * This code is released by the author with no restrictions on usage.
9  *
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.
15  *
16  */
17 
18 /*! \file
19  *
20  * \brief Verbose logging application
21  *
22  * \author Tilghman Lesher <app_verbose_v001@the-tilghman.com>
23  *
24  * \ingroup applications
25  */
26 
27 /*** MODULEINFO
28  <support_level>core</support_level>
29  ***/
30 
31 #include "asterisk.h"
32 
33 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
34 
35 #include "asterisk/module.h"
36 #include "asterisk/app.h"
37 #include "asterisk/channel.h"
38 
39 static char *app_verbose = "Verbose";
40 static char *app_log = "Log";
41 
42 /*** DOCUMENTATION
43  <application name="Verbose" language="en_US">
44  <synopsis>
45  Send arbitrary text to verbose output.
46  </synopsis>
47  <syntax>
48  <parameter name="level">
49  <para>Must be an integer value. If not specified, defaults to 0.</para>
50  </parameter>
51  <parameter name="message" required="true">
52  <para>Output text message.</para>
53  </parameter>
54  </syntax>
55  <description>
56  <para>Sends an arbitrary text message to verbose output.</para>
57  </description>
58  </application>
59  <application name="Log" language="en_US">
60  <synopsis>
61  Send arbitrary text to a selected log level.
62  </synopsis>
63  <syntax>
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>
67  </parameter>
68  <parameter name="message" required="true">
69  <para>Output text message.</para>
70  </parameter>
71  </syntax>
72  <description>
73  <para>Sends an arbitrary text message to a selected log level.</para>
74  </description>
75  </application>
76  ***/
77 
78 
79 static int verbose_exec(struct ast_channel *chan, const char *data)
80 {
81  int vsize;
82  char *parse;
84  AST_APP_ARG(level);
85  AST_APP_ARG(msg);
86  );
87 
88  if (ast_strlen_zero(data)) {
89  return 0;
90  }
91 
92  parse = ast_strdupa(data);
94  if (args.argc == 1) {
95  args.msg = args.level;
96  args.level = "0";
97  }
98 
99  if (sscanf(args.level, "%30d", &vsize) != 1) {
100  vsize = 0;
101  ast_log(LOG_WARNING, "'%s' is not a verboser number\n", args.level);
102  }
103  if (option_verbose >= vsize) {
104  switch (vsize) {
105  case 0:
106  ast_verbose("%s\n", args.msg);
107  break;
108  case 1:
109  ast_verbose(VERBOSE_PREFIX_1 "%s\n", args.msg);
110  break;
111  case 2:
112  ast_verbose(VERBOSE_PREFIX_2 "%s\n", args.msg);
113  break;
114  case 3:
115  ast_verbose(VERBOSE_PREFIX_3 "%s\n", args.msg);
116  break;
117  default:
118  ast_verbose(VERBOSE_PREFIX_4 "%s\n", args.msg);
119  }
120  }
121 
122  return 0;
123 }
124 
125 static int log_exec(struct ast_channel *chan, const char *data)
126 {
127  char *parse;
128  int lnum = -1;
131  AST_APP_ARG(level);
132  AST_APP_ARG(msg);
133  );
134 
135  if (ast_strlen_zero(data))
136  return 0;
137 
138  parse = ast_strdupa(data);
139  AST_STANDARD_APP_ARGS(args, parse);
140 
141  if (!strcasecmp(args.level, "ERROR")) {
142  lnum = __LOG_ERROR;
143  } else if (!strcasecmp(args.level, "WARNING")) {
144  lnum = __LOG_WARNING;
145  } else if (!strcasecmp(args.level, "NOTICE")) {
146  lnum = __LOG_NOTICE;
147  } else if (!strcasecmp(args.level, "DEBUG")) {
148  lnum = __LOG_DEBUG;
149  } else if (!strcasecmp(args.level, "VERBOSE")) {
150  lnum = __LOG_VERBOSE;
151  } else if (!strcasecmp(args.level, "DTMF")) {
152  lnum = __LOG_DTMF;
153  } else {
154  ast_log(LOG_ERROR, "Unknown log level: '%s'\n", args.level);
155  }
156 
157  if (lnum > -1) {
158  snprintf(context, sizeof(context), "@ %s", chan->context);
159  snprintf(extension, sizeof(extension), "Ext. %s", chan->exten);
160 
161  ast_log(lnum, extension, chan->priority, context, "%s\n", args.msg);
162  }
163 
164  return 0;
165 }
166 
167 static int unload_module(void)
168 {
169  int res;
170 
171  res = ast_unregister_application(app_verbose);
172  res |= ast_unregister_application(app_log);
173 
174  return res;
175 }
176 
177 static int load_module(void)
178 {
179  int res;
180 
181  res = ast_register_application_xml(app_log, log_exec);
182  res |= ast_register_application_xml(app_verbose, verbose_exec);
183 
184  return res;
185 }
186 
Main Channel structure associated with a channel.
Definition: channel.h:742
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:396
Asterisk main include file. File version handling, generic pbx functions.
#define VERBOSE_PREFIX_1
Definition: logger.h:41
#define __LOG_DEBUG
Definition: logger.h:121
int priority
Definition: channel.h:841
char context[AST_MAX_CONTEXT]
Definition: channel.h:868
#define VERBOSE_PREFIX_3
Definition: logger.h:43
#define LOG_WARNING
Definition: logger.h:144
void ast_verbose(const char *fmt,...)
Definition: logger.c:1568
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
#define __LOG_DTMF
Definition: logger.h:176
static char * app_log
Definition: app_verbose.c:40
int option_verbose
Definition: asterisk.c:181
static int load_module(void)
Definition: app_verbose.c:177
#define __LOG_WARNING
Definition: logger.h:143
#define __LOG_ERROR
Definition: logger.h:154
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
static int verbose_exec(struct ast_channel *chan, const char *data)
Definition: app_verbose.c:79
#define VERBOSE_PREFIX_4
Definition: logger.h:44
General Asterisk PBX channel definitions.
#define VERBOSE_PREFIX_2
Definition: logger.h:42
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define AST_MAX_EXTENSION
Definition: channel.h:135
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
#define LOG_ERROR
Definition: logger.h:155
static struct @350 args
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1858
static char * app_verbose
Definition: app_verbose.c:39
#define __LOG_NOTICE
Definition: logger.h:132
#define __LOG_VERBOSE
Definition: logger.h:165
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
static int unload_module(void)
Definition: app_verbose.c:167
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:38
static int log_exec(struct ast_channel *chan, const char *data)
Definition: app_verbose.c:125
char exten[AST_MAX_EXTENSION]
Definition: channel.h:869
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180