Asterisk - The Open Source Telephony Project GIT-master-754dea3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
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#include "asterisk/module.h"
34#include "asterisk/app.h"
35#include "asterisk/channel.h"
36#include "asterisk/logger.h"
37
38static char *app_verbose = "Verbose";
39static char *app_log = "Log";
40
41/*** DOCUMENTATION
42 <application name="Verbose" language="en_US">
43 <since>
44 <version>1.0.0</version>
45 </since>
46 <synopsis>
47 Send arbitrary text to verbose output.
48 </synopsis>
49 <syntax>
50 <parameter name="level">
51 <para>Must be an integer value. If not specified, defaults to 0.</para>
52 </parameter>
53 <parameter name="message" required="true">
54 <para>Output text message.</para>
55 </parameter>
56 </syntax>
57 <description>
58 <para>Sends an arbitrary text message to verbose output.</para>
59 </description>
60 </application>
61 <application name="Log" language="en_US">
62 <since>
63 <version>1.4.0</version>
64 </since>
65 <synopsis>
66 Send arbitrary text to a selected log level.
67 </synopsis>
68 <syntax>
69 <parameter name="level" required="true">
70 <para>Level must be one of <literal>ERROR</literal>, <literal>WARNING</literal>, <literal>NOTICE</literal>,
71 <literal>DEBUG</literal>, <literal>VERBOSE</literal>, <literal>DTMF</literal>, or
72 the name of a custom dynamic logging level.</para>
73 </parameter>
74 <parameter name="message" required="true">
75 <para>Output text message.</para>
76 </parameter>
77 </syntax>
78 <description>
79 <para>Sends an arbitrary text message to a selected log level.</para>
80 </description>
81 </application>
82 ***/
83
84
85static int verbose_exec(struct ast_channel *chan, const char *data)
86{
87 unsigned int vsize;
88 char *parse;
90 AST_APP_ARG(level);
91 AST_APP_ARG(msg);
92 );
93
94 if (ast_strlen_zero(data)) {
95 return 0;
96 }
97
98 parse = ast_strdupa(data);
100 if (args.argc == 1) {
101 args.msg = args.level;
102 args.level = "0";
103 }
104
105 if (sscanf(args.level, "%30u", &vsize) != 1) {
106 vsize = 0;
107 ast_log(LOG_WARNING, "'%s' is not a verboser number\n", args.level);
108 } else if (4 < vsize) {
109 vsize = 4;
110 }
111
112 ast_verb(vsize, "%s\n", args.msg);
113
114 return 0;
115}
116
117static int log_exec(struct ast_channel *chan, const char *data)
118{
119 char *parse;
120 int lnum = -1;
123 AST_APP_ARG(level);
124 AST_APP_ARG(msg);
125 );
126
127 if (ast_strlen_zero(data))
128 return 0;
129
130 parse = ast_strdupa(data);
132
133 if (!strcasecmp(args.level, "ERROR")) {
134 lnum = __LOG_ERROR;
135 } else if (!strcasecmp(args.level, "WARNING")) {
136 lnum = __LOG_WARNING;
137 } else if (!strcasecmp(args.level, "NOTICE")) {
138 lnum = __LOG_NOTICE;
139 } else if (!strcasecmp(args.level, "DEBUG")) {
140 lnum = __LOG_DEBUG;
141 } else if (!strcasecmp(args.level, "VERBOSE")) {
142 lnum = __LOG_VERBOSE;
143 } else if (!strcasecmp(args.level, "DTMF")) {
144 lnum = __LOG_DTMF;
145 } else {
147 }
148
149 if (lnum > -1) {
150 snprintf(context, sizeof(context), "@ %s", ast_channel_context(chan));
151 snprintf(extension, sizeof(extension), "Ext. %s", ast_channel_exten(chan));
152
153 ast_log(lnum, extension, ast_channel_priority(chan), context, "%s\n", args.msg);
154 } else {
155 ast_log(LOG_ERROR, "Unknown log level: '%s'\n", args.level);
156 return 0;
157 }
158
159 return 0;
160}
161
162static int unload_module(void)
163{
164 int res;
165
168
169 return res;
170}
171
172static int load_module(void)
173{
174 int res;
175
178
179 return res;
180}
181
static int verbose_exec(struct ast_channel *chan, const char *data)
Definition: app_verbose.c:85
static char * app_log
Definition: app_verbose.c:39
static int log_exec(struct ast_channel *chan, const char *data)
Definition: app_verbose.c:117
static int load_module(void)
Definition: app_verbose.c:172
static char * app_verbose
Definition: app_verbose.c:38
static int unload_module(void)
Definition: app_verbose.c:162
Asterisk main include file. File version handling, generic pbx functions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_log
Definition: astobj2.c:42
General Asterisk PBX channel definitions.
int ast_channel_priority(const struct ast_channel *chan)
const char * ast_channel_context(const struct ast_channel *chan)
const char * ast_channel_exten(const struct ast_channel *chan)
#define AST_MAX_EXTENSION
Definition: channel.h:134
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
#define AST_APP_ARG(name)
Define an application argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
Support for logging to various files, console and syslog Configuration in file logger....
int ast_logger_get_dynamic_level(const char *name)
Retrieve dynamic logging level id.
Definition: logger.c:2855
#define __LOG_ERROR
#define __LOG_DTMF
#define __LOG_VERBOSE
#define __LOG_NOTICE
#define __LOG_DEBUG
#define __LOG_WARNING
#define LOG_ERROR
#define ast_verb(level,...)
#define LOG_WARNING
Asterisk module definitions.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:581
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:640
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Main Channel structure associated with a channel.
structure to hold extensions
const char * args