asterisk/apps/app_verbose.c

174 lines
4.1 KiB
C
Raw Normal View History

/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (c) 2004 - 2005 Tilghman Lesher. All rights reserved.
*
* Tilghman Lesher <app_verbose_v001@the-tilghman.com>
*
* This code is released by the author with no restrictions on usage.
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
*/
/*! \file
*
* \brief Verbose logging application
*
* \author Tilghman Lesher <app_verbose_v001@the-tilghman.com>
*
* \ingroup applications
*/
/*** MODULEINFO
<support_level>core</support_level>
***/
#include "asterisk.h"
git migration: Refactor the ASTERISK_FILE_VERSION macro Git does not support the ability to replace a token with a version string during check-in. While it does have support for replacing a token on clone, this is somewhat sub-optimal: the token is replaced with the object hash, which is not particularly easy for human consumption. What's more, in practice, the source file version was often not terribly useful. Generally, when triaging bugs, the overall version of Asterisk is far more useful than an individual SVN version of a file. As a result, this patch removes Asterisk's support for showing source file versions. Specifically, it does the following: * Rename ASTERISK_FILE_VERSION macro to ASTERISK_REGISTER_FILE, and remove passing the version in with the macro. Other facilities than 'core show file version' make use of the file names, such as setting a debug level only on a specific file. As such, the act of registering source files with the Asterisk core still has use. The macro rename now reflects the new macro purpose. * main/asterisk: - Refactor the file_version structure to reflect that it no longer tracks a version field. - Remove the "core show file version" CLI command. Without the file version, it is no longer useful. - Remove the ast_file_version_find function. The file version is no longer tracked. - Rename ast_register_file_version/ast_unregister_file_version to ast_register_file/ast_unregister_file, respectively. * main/manager: Remove value from the Version key of the ModuleCheck Action. The actual key itself has not been removed, as doing so would absolutely constitute a backwards incompatible change. However, since the file version is no longer tracked, there is no need to attempt to include it in the Version key. * UPGRADE: Add notes for: - Modification to the ModuleCheck AMI Action - Removal of the "core show file version" CLI command Change-Id: I6cf0ff280e1668bf4957dc21f32a5ff43444a40e
2015-04-12 02:38:22 +00:00
ASTERISK_REGISTER_FILE()
#include "asterisk/module.h"
#include "asterisk/app.h"
#include "asterisk/channel.h"
static char *app_verbose = "Verbose";
static char *app_log = "Log";
/*** DOCUMENTATION
<application name="Verbose" language="en_US">
<synopsis>
Send arbitrary text to verbose output.
</synopsis>
<syntax>
<parameter name="level">
<para>Must be an integer value. If not specified, defaults to 0.</para>
</parameter>
<parameter name="message" required="true">
<para>Output text message.</para>
</parameter>
</syntax>
<description>
<para>Sends an arbitrary text message to verbose output.</para>
</description>
</application>
<application name="Log" language="en_US">
<synopsis>
Send arbitrary text to a selected log level.
</synopsis>
<syntax>
<parameter name="level" required="true">
<para>Level must be one of <literal>ERROR</literal>, <literal>WARNING</literal>, <literal>NOTICE</literal>,
<literal>DEBUG</literal>, <literal>VERBOSE</literal> or <literal>DTMF</literal>.</para>
</parameter>
<parameter name="message" required="true">
<para>Output text message.</para>
</parameter>
</syntax>
<description>
<para>Sends an arbitrary text message to a selected log level.</para>
</description>
</application>
***/
static int verbose_exec(struct ast_channel *chan, const char *data)
{
unsigned int vsize;
char *parse;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(level);
AST_APP_ARG(msg);
);
if (ast_strlen_zero(data)) {
return 0;
}
parse = ast_strdupa(data);
AST_STANDARD_APP_ARGS(args, parse);
if (args.argc == 1) {
args.msg = args.level;
args.level = "0";
}
verbosity: Fix performance of console verbose messages. The per console verbose level feature as previously implemented caused a large performance penalty. The fix required some minor incompatibilities if the new rasterisk is used to connect to an earlier version. If the new rasterisk connects to an older Asterisk version then the root console verbose level is always affected by the "core set verbose" command of the remote console even though it may appear to only affect the current console. If an older version of rasterisk connects to the new version then the "core set verbose" command will have no effect. * Fixed the verbose performance by not generating a verbose message if nothing is going to use it and then filtered any generated verbose messages before actually sending them to the remote consoles. * Split the "core set debug" and "core set verbose" CLI commands to remove the per module verbose support that cannot work with the per console verbose level. * Added a silent option to the "core set verbose" command. * Fixed "core set debug off" tab completion. * Made "core show settings" list the current console verbosity in addition to the root console verbosity. * Changed the default verbose level of the 'verbose' setting in the logger.conf [logfiles] section. The default is now to once again follow the current root console level. As a result, using the AMI Command action with "core set verbose" could again set the root console verbose level and affect the verbose level logged. (closes issue AST-1252) Reported by: Guenther Kelleter Review: https://reviewboard.asterisk.org/r/3114/ ........ Merged revisions 405431 from http://svn.asterisk.org/svn/asterisk/branches/11 ........ Merged revisions 405432 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@405436 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-01-14 18:14:02 +00:00
if (sscanf(args.level, "%30u", &vsize) != 1) {
vsize = 0;
ast_log(LOG_WARNING, "'%s' is not a verboser number\n", args.level);
verbosity: Fix performance of console verbose messages. The per console verbose level feature as previously implemented caused a large performance penalty. The fix required some minor incompatibilities if the new rasterisk is used to connect to an earlier version. If the new rasterisk connects to an older Asterisk version then the root console verbose level is always affected by the "core set verbose" command of the remote console even though it may appear to only affect the current console. If an older version of rasterisk connects to the new version then the "core set verbose" command will have no effect. * Fixed the verbose performance by not generating a verbose message if nothing is going to use it and then filtered any generated verbose messages before actually sending them to the remote consoles. * Split the "core set debug" and "core set verbose" CLI commands to remove the per module verbose support that cannot work with the per console verbose level. * Added a silent option to the "core set verbose" command. * Fixed "core set debug off" tab completion. * Made "core show settings" list the current console verbosity in addition to the root console verbosity. * Changed the default verbose level of the 'verbose' setting in the logger.conf [logfiles] section. The default is now to once again follow the current root console level. As a result, using the AMI Command action with "core set verbose" could again set the root console verbose level and affect the verbose level logged. (closes issue AST-1252) Reported by: Guenther Kelleter Review: https://reviewboard.asterisk.org/r/3114/ ........ Merged revisions 405431 from http://svn.asterisk.org/svn/asterisk/branches/11 ........ Merged revisions 405432 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@405436 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-01-14 18:14:02 +00:00
} else if (4 < vsize) {
vsize = 4;
}
ast_verb(vsize, "%s\n", args.msg);
return 0;
}
static int log_exec(struct ast_channel *chan, const char *data)
{
char *parse;
int lnum = -1;
char extension[AST_MAX_EXTENSION + 5], context[AST_MAX_EXTENSION + 2];
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(level);
AST_APP_ARG(msg);
);
if (ast_strlen_zero(data))
return 0;
parse = ast_strdupa(data);
AST_STANDARD_APP_ARGS(args, parse);
if (!strcasecmp(args.level, "ERROR")) {
lnum = __LOG_ERROR;
} else if (!strcasecmp(args.level, "WARNING")) {
lnum = __LOG_WARNING;
} else if (!strcasecmp(args.level, "NOTICE")) {
lnum = __LOG_NOTICE;
} else if (!strcasecmp(args.level, "DEBUG")) {
lnum = __LOG_DEBUG;
} else if (!strcasecmp(args.level, "VERBOSE")) {
lnum = __LOG_VERBOSE;
} else if (!strcasecmp(args.level, "DTMF")) {
lnum = __LOG_DTMF;
} else {
ast_log(LOG_ERROR, "Unknown log level: '%s'\n", args.level);
}
if (lnum > -1) {
snprintf(context, sizeof(context), "@ %s", ast_channel_context(chan));
snprintf(extension, sizeof(extension), "Ext. %s", ast_channel_exten(chan));
ast_log(lnum, extension, ast_channel_priority(chan), context, "%s\n", args.msg);
}
return 0;
}
static int unload_module(void)
{
int res;
res = ast_unregister_application(app_verbose);
res |= ast_unregister_application(app_log);
return res;
}
static int load_module(void)
{
int res;
res = ast_register_application_xml(app_log, log_exec);
res |= ast_register_application_xml(app_verbose, verbose_exec);
return res;
}
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send verbose output");