Asterisk - The Open Source Telephony Project  18.5.0
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 <[email protected]>
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 <[email protected]>
23  *
24  * \ingroup applications
25  */
26 
27 /*** MODULEINFO
28  <support_level>core</support_level>
29  ***/
30 
31 #include "asterisk.h"
32 
33 #include "asterisk/module.h"
34 #include "asterisk/app.h"
35 #include "asterisk/channel.h"
36 #include "asterisk/logger.h"
37 
38 static char *app_verbose = "Verbose";
39 static char *app_log = "Log";
40 
41 /*** DOCUMENTATION
42  <application name="Verbose" language="en_US">
43  <synopsis>
44  Send arbitrary text to verbose output.
45  </synopsis>
46  <syntax>
47  <parameter name="level">
48  <para>Must be an integer value. If not specified, defaults to 0.</para>
49  </parameter>
50  <parameter name="message" required="true">
51  <para>Output text message.</para>
52  </parameter>
53  </syntax>
54  <description>
55  <para>Sends an arbitrary text message to verbose output.</para>
56  </description>
57  </application>
58  <application name="Log" language="en_US">
59  <synopsis>
60  Send arbitrary text to a selected log level.
61  </synopsis>
62  <syntax>
63  <parameter name="level" required="true">
64  <para>Level must be one of <literal>ERROR</literal>, <literal>WARNING</literal>, <literal>NOTICE</literal>,
65  <literal>DEBUG</literal>, <literal>VERBOSE</literal>, or <literal>DTMF</literal>, or
66  the name of a custom dynamic logging level.</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  unsigned 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, "%30u", &vsize) != 1) {
100  vsize = 0;
101  ast_log(LOG_WARNING, "'%s' is not a verboser number\n", args.level);
102  } else if (4 < vsize) {
103  vsize = 4;
104  }
105 
106  ast_verb(vsize, "%s\n", args.msg);
107 
108  return 0;
109 }
110 
111 static int log_exec(struct ast_channel *chan, const char *data)
112 {
113  char *parse;
114  int lnum = -1;
117  AST_APP_ARG(level);
118  AST_APP_ARG(msg);
119  );
120 
121  if (ast_strlen_zero(data))
122  return 0;
123 
124  parse = ast_strdupa(data);
125  AST_STANDARD_APP_ARGS(args, parse);
126 
127  if (!strcasecmp(args.level, "ERROR")) {
128  lnum = __LOG_ERROR;
129  } else if (!strcasecmp(args.level, "WARNING")) {
130  lnum = __LOG_WARNING;
131  } else if (!strcasecmp(args.level, "NOTICE")) {
132  lnum = __LOG_NOTICE;
133  } else if (!strcasecmp(args.level, "DEBUG")) {
134  lnum = __LOG_DEBUG;
135  } else if (!strcasecmp(args.level, "VERBOSE")) {
136  lnum = __LOG_VERBOSE;
137  } else if (!strcasecmp(args.level, "DTMF")) {
138  lnum = __LOG_DTMF;
139  } else {
140  int level = ast_dynamic_logger_level(args.level);
141  if (level > -1) {
142  ast_log_dynamic_level(level, "%s\n", args.msg);
143  } else {
144  ast_log(LOG_ERROR, "Unknown log level: '%s'\n", args.level);
145  }
146  }
147 
148  if (lnum > -1) {
149  snprintf(context, sizeof(context), "@ %s", ast_channel_context(chan));
150  snprintf(extension, sizeof(extension), "Ext. %s", ast_channel_exten(chan));
151 
152  ast_log(lnum, extension, ast_channel_priority(chan), context, "%s\n", args.msg);
153  }
154 
155  return 0;
156 }
157 
158 static int unload_module(void)
159 {
160  int res;
161 
164 
165  return res;
166 }
167 
168 static int load_module(void)
169 {
170  int res;
171 
174 
175  return res;
176 }
177 
Main Channel structure associated with a channel.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:567
Asterisk main include file. File version handling, generic pbx functions.
#define __LOG_DEBUG
Definition: logger.h:240
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
#define LOG_WARNING
Definition: logger.h:274
#define __LOG_DTMF
Definition: logger.h:306
static char * app_log
Definition: app_verbose.c:39
#define ast_log_dynamic_level(level,...)
Send a log message to a dynamically registered log level.
Definition: logger.h:439
static int load_module(void)
Definition: app_verbose.c:168
#define __LOG_WARNING
Definition: logger.h:273
#define __LOG_ERROR
Definition: logger.h:284
const char * args
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
static int verbose_exec(struct ast_channel *chan, const char *data)
Definition: app_verbose.c:79
int ast_channel_priority(const struct ast_channel *chan)
#define ast_verb(level,...)
Definition: logger.h:463
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
General Asterisk PBX channel definitions.
#define AST_MAX_EXTENSION
Definition: channel.h:135
structure to hold extensions
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
const char * ast_channel_exten(const struct ast_channel *chan)
#define LOG_ERROR
Definition: logger.h:285
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1872
int ast_dynamic_logger_level(const char *name)
Checks if a dynamic logger level exists.
Definition: logger.c:2514
static char * app_verbose
Definition: app_verbose.c:38
Support for logging to various files, console and syslog Configuration in file logger.conf.
#define __LOG_NOTICE
Definition: logger.h:262
#define __LOG_VERBOSE
Definition: logger.h:295
const char * ast_channel_context(const struct ast_channel *chan)
static int unload_module(void)
Definition: app_verbose.c:158
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
Asterisk module definitions.
static int log_exec(struct ast_channel *chan, const char *data)
Definition: app_verbose.c:111
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626
#define AST_APP_ARG(name)
Define an application argument.