[asterisk-commits] russell: trunk r76555 - in /trunk: include/asterisk/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jul 23 09:21:42 CDT 2007


Author: russell
Date: Mon Jul 23 09:21:41 2007
New Revision: 76555

URL: http://svn.digium.com/view/asterisk?view=rev&rev=76555
Log:
(closes issue #10192)
Reported by: bbryant
Patches:
      20070720__core_debug_by_file.patch uploaded by bbryant (license 36)
	  (with some modifications by me)
Tested by: russell, bbryant

This set of changes introduces the ability to set the core debug or verbose
levels on a per-file basis.  Interestingly enough, in 1.4, you have the ability
to set core debug for a single file, but that functionality was accidentally
lost in the conversion of the CLI commands to the new format.

This patch improves upon what was in 1.4 by letting you set it for more than 1
file, and by also supporting verbose.

*** Janitor Project ***

This patch also introduces a new macro, ast_verb(), which is similar
to ast_debug().  Setting the per file verbose value only works for messages that
use this macro.  Converting existing uses of ast_verbose() can be done like:

if (option_debug > 2)
   ast_verbose(VERBOSE_PREFIX_3 "Something useful\n");

...

ast_verb(3, "Something useful\n");


Modified:
    trunk/include/asterisk/logger.h
    trunk/include/asterisk/options.h
    trunk/main/asterisk.c
    trunk/main/cli.c
    trunk/main/logger.c
    trunk/main/pbx.c

Modified: trunk/include/asterisk/logger.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/logger.h?view=diff&rev=76555&r1=76554&r2=76555
==============================================================================
--- trunk/include/asterisk/logger.h (original)
+++ trunk/include/asterisk/logger.h Mon Jul 23 09:21:41 2007
@@ -59,6 +59,7 @@
 	\param function	Will be provided by the LOG_* macro
 	\param fmt	This is what is important.  The format is the same as your favorite breed of printf.  You know how that works, right? :-)
  */
+
 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
 	__attribute__ ((format (printf, 5, 6)));
 
@@ -130,14 +131,42 @@
 #define LOG_DTMF    __LOG_DTMF, _A_
 
 /*!
+ * \brief Get the debug level for a file
+ * \arg file the filename
+ * \return the debug level
+ */
+unsigned int ast_debug_get_by_file(const char *file);
+
+/*!
+ * \brief Get the debug level for a file
+ * \arg file the filename
+ * \return the debug level
+ */
+unsigned int ast_verbose_get_by_file(const char *file);
+
+/*!
  * \brief Log a DEBUG message
  * \param level The minimum value of option_debug for this message
  *        to get logged
  */
 #define ast_debug(level, ...) do {       \
-	if (option_debug >= (level)) {       \
+	if (option_debug >= (level) || (ast_opt_dbg_file && ast_debug_get_by_file(__FILE__) >= (level)) ) \
 		ast_log(LOG_DEBUG, __VA_ARGS__); \
-	}                                    \
+} while (0)
+
+#define ast_verb(level, ...) do { \
+	if (option_verbose >= (level) || (ast_opt_verb_file && ast_verbose_get_by_file(__FILE__) >= (level)) ) { \
+		if (level >= 4) \
+			ast_verbose(VERBOSE_PREFIX_4 __VA_ARGS__); \
+		else if (level == 3) \
+			ast_verbose(VERBOSE_PREFIX_3 __VA_ARGS__); \
+		else if (level == 2) \
+			ast_verbose(VERBOSE_PREFIX_2 __VA_ARGS__); \
+		else if (level == 1) \
+			ast_verbose(VERBOSE_PREFIX_1 __VA_ARGS__); \
+		else \
+			ast_verbose(__VA_ARGS__); \
+	} \
 } while (0)
 
 #if defined(__cplusplus) || defined(c_plusplus)

Modified: trunk/include/asterisk/options.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/options.h?view=diff&rev=76555&r1=76554&r2=76555
==============================================================================
--- trunk/include/asterisk/options.h (original)
+++ trunk/include/asterisk/options.h Mon Jul 23 09:21:41 2007
@@ -75,7 +75,11 @@
 	/*! Always fork, even if verbose or debug settings are non-zero */
 	AST_OPT_FLAG_ALWAYS_FORK = (1 << 21),
 	/*! Disable log/verbose output to remote consoles */
-	AST_OPT_FLAG_MUTE = (1 << 22)
+	AST_OPT_FLAG_MUTE = (1 << 22),
+	/*! There is a per-file debug setting */
+	AST_OPT_FLAG_DEBUG_FILE = (1 << 23),
+	/*! There is a per-file verbose setting */
+	AST_OPT_FLAG_VERBOSE_FILE = (1 << 24),
 };
 
 /*! These are the options that set by default when Asterisk starts */
@@ -103,6 +107,8 @@
 #define ast_opt_internal_timing		ast_test_flag(&ast_options, AST_OPT_FLAG_INTERNAL_TIMING)
 #define ast_opt_always_fork		ast_test_flag(&ast_options, AST_OPT_FLAG_ALWAYS_FORK)
 #define ast_opt_mute			ast_test_flag(&ast_options, AST_OPT_FLAG_MUTE)
+#define ast_opt_dbg_file		ast_test_flag(&ast_options, AST_OPT_FLAG_DEBUG_FILE)
+#define ast_opt_verb_file		ast_test_flag(&ast_options, AST_OPT_FLAG_VERBOSE_FILE)
 
 extern struct ast_flags ast_options;
 
@@ -121,7 +127,6 @@
 extern pid_t ast_mainpid;
 
 extern char record_cache_dir[AST_CACHE_DIR_LEN];
-extern char debug_filename[AST_FILENAME_MAX];
 
 extern int ast_language_is_prefix;
 

Modified: trunk/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/trunk/main/asterisk.c?view=diff&rev=76555&r1=76554&r2=76555
==============================================================================
--- trunk/main/asterisk.c (original)
+++ trunk/main/asterisk.c Mon Jul 23 09:21:41 2007
@@ -163,7 +163,6 @@
 
 int option_verbose;				/*!< Verbosity level */
 int option_debug;				/*!< Debug level */
-
 double option_maxload;				/*!< Max load avg on system */
 int option_maxcalls;				/*!< Max number of active calls */
 int option_maxfiles;				/*!< Max number of open file handles (files, sockets) */
@@ -174,7 +173,6 @@
 /*! @} */
 
 char record_cache_dir[AST_CACHE_DIR_LEN] = AST_TMP_DIR;
-char debug_filename[AST_FILENAME_MAX] = "";
 
 static int ast_socket = -1;		/*!< UNIX Socket for allowing remote control */
 static int ast_consock = -1;		/*!< UNIX Socket for controlling another asterisk */

Modified: trunk/main/cli.c
URL: http://svn.digium.com/view/asterisk/trunk/main/cli.c?view=diff&rev=76555&r1=76554&r2=76555
==============================================================================
--- trunk/main/cli.c (original)
+++ trunk/main/cli.c Mon Jul 23 09:21:41 2007
@@ -49,6 +49,22 @@
 #include "editline/readline/readline.h"
 #include "asterisk/threadstorage.h"
 
+/*!
+ * \brief map a debug or verbose value to a filename
+ */
+struct ast_debug_file {
+	unsigned int level;
+	AST_RWLIST_ENTRY(ast_debug_file) entry;
+	char filename[0];
+};
+
+AST_RWLIST_HEAD(debug_file_list, ast_debug_file);
+
+/*! list of filenames and their debug settings */
+static struct debug_file_list debug_files;
+/*! list of filenames and their verbose settings */
+static struct debug_file_list verbose_files;
+
 AST_THREADSTORAGE(ast_cli_buf);
 
 /*! \brief Initial buffer size for resulting strings in ast_cli() */
@@ -69,6 +85,40 @@
 
 	if (res != AST_DYNSTR_BUILD_FAILED)
 		ast_carefulwrite(fd, buf->str, strlen(buf->str), 100);
+}
+
+unsigned int ast_debug_get_by_file(const char *file) 
+{
+	struct ast_debug_file *adf;
+	unsigned int res = 0;
+
+	AST_RWLIST_RDLOCK(&debug_files);
+	AST_LIST_TRAVERSE(&debug_files, adf, entry) {
+		if (!strncasecmp(adf->filename, file, strlen(adf->filename))) {
+			res = adf->level;
+			break;
+		}
+	}
+	AST_RWLIST_UNLOCK(&debug_files);
+
+	return res;
+}
+
+unsigned int ast_verbose_get_by_file(const char *file) 
+{
+	struct ast_debug_file *adf;
+	unsigned int res = 0;
+
+	AST_RWLIST_RDLOCK(&verbose_files);
+	AST_LIST_TRAVERSE(&verbose_files, adf, entry) {
+		if (!strncasecmp(adf->filename, file, strlen(file))) {
+			res = adf->level;
+			break;
+		}
+	}
+	AST_RWLIST_UNLOCK(&verbose_files);
+
+	return res;
 }
 
 static AST_LIST_HEAD_STATIC(helpers, ast_cli_entry);
@@ -184,6 +234,23 @@
 	return s;
 }
 
+/*! 
+ * \brief Find the debug or verbose file setting 
+ * \arg debug 1 for debug, 0 for verbose
+ */
+static struct ast_debug_file *find_debug_file(const char *fn, unsigned int debug)
+{
+	struct ast_debug_file *df = NULL;
+	struct debug_file_list *dfl = debug ? &debug_files : &verbose_files;
+
+	AST_LIST_TRAVERSE(dfl, df, entry) {
+		if (!strcasecmp(df->filename, fn))
+			break;
+	}
+
+	return df;
+}
+
 static char *handle_verbose(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	int oldval;
@@ -194,14 +261,18 @@
 	char **argv = a->argv;
 	int *dst;
 	char *what;
+	struct debug_file_list *dfl;
+	struct ast_debug_file *adf;
+	char *fn;
 
 	switch (cmd) {
 	case CLI_INIT:
 		e->command = "core set {debug|verbose} [off|atleast]";
 		e->usage =
-			"Usage: core set {debug|verbose} [atleast] <level>\n"
+			"Usage: core set {debug|verbose} [atleast] <level> [filename]\n"
 			"       core set {debug|verbose} off\n"
-			"       Sets level of debug or verbose messages to be displayed.\n"
+			"       Sets level of debug or verbose messages to be displayed or \n"
+			"       sets a filename to display debug messages from.\n"
 			"	0 or off means no messages should be displayed.\n"
 			"	Equivalent to -d[d[...]] or -v[v[v...]] on startup\n";
 		return NULL;
@@ -225,15 +296,67 @@
 		what = "Verbosity";
 	}
 	if (argc == e->args && !strcasecmp(argv[e->args - 1], "off")) {
+		unsigned int debug = (*what == 'C');
 		newlevel = 0;
+
+		dfl = debug ? &debug_files : &verbose_files;
+
+		AST_RWLIST_WRLOCK(dfl);
+		while ((adf = AST_RWLIST_REMOVE_HEAD(dfl, entry)))
+			ast_free(adf);
+		ast_clear_flag(&ast_options, debug ? AST_OPT_FLAG_DEBUG_FILE : AST_OPT_FLAG_VERBOSE_FILE);
+		AST_RWLIST_UNLOCK(dfl);
+
 		goto done;
 	}
 	if (!strcasecmp(argv[e->args-1], "atleast"))
 		atleast = 1;
-	if (argc != e->args + atleast)
+	if (argc != e->args + atleast && argc != e->args + atleast + 1)
 		return CLI_SHOWUSAGE;
 	if (sscanf(argv[e->args + atleast - 1], "%d", &newlevel) != 1)
 		return CLI_SHOWUSAGE;
+	if (argc == e->args + atleast + 1) {
+		unsigned int debug = (*what == 'C');
+		dfl = debug ? &debug_files : &verbose_files;
+
+		fn = argv[e->args + atleast];
+
+		AST_RWLIST_WRLOCK(dfl);
+
+		if ((adf = find_debug_file(fn, debug)) && !newlevel) {
+			AST_RWLIST_REMOVE(dfl, adf, entry);
+			if (AST_RWLIST_EMPTY(dfl))
+				ast_clear_flag(&ast_options, debug ? AST_OPT_FLAG_DEBUG_FILE : AST_OPT_FLAG_VERBOSE_FILE);
+			AST_RWLIST_UNLOCK(dfl);
+			ast_cli(fd, "%s was %d and has been set to 0 for '%s'\n", what, adf->level, fn);
+			ast_free(adf);
+			return CLI_SUCCESS;
+		}
+
+		if (adf) {
+			if ((atleast && newlevel < adf->level) || adf->level == newlevel) {
+				ast_cli(fd, "%s is %d for '%s'\n", what, adf->level, fn);
+				AST_RWLIST_UNLOCK(dfl);
+				return CLI_SUCCESS;
+			}
+		} else if (!(adf = ast_calloc(1, sizeof(*adf) + strlen(fn) + 1))) {
+			AST_RWLIST_UNLOCK(dfl);
+			return CLI_FAILURE;
+		}
+
+		oldval = adf->level;
+		adf->level = newlevel;
+		strcpy(adf->filename, fn);
+
+		ast_set_flag(&ast_options, debug ? AST_OPT_FLAG_DEBUG_FILE : AST_OPT_FLAG_VERBOSE_FILE);
+
+		AST_RWLIST_INSERT_TAIL(dfl, adf, entry);
+		AST_RWLIST_UNLOCK(dfl);
+
+		ast_cli(fd, "%s was %d and has been set to %d for '%s'\n", what, oldval, adf->level, adf->filename);
+
+		return CLI_SUCCESS;
+	}
 
 done:
 	if (!atleast || newlevel > *dst)

Modified: trunk/main/logger.c
URL: http://svn.digium.com/view/asterisk/trunk/main/logger.c?view=diff&rev=76555&r1=76554&r2=76555
==============================================================================
--- trunk/main/logger.c (original)
+++ trunk/main/logger.c Mon Jul 23 09:21:41 2007
@@ -80,7 +80,6 @@
 #else
 #define GETTID() getpid()
 #endif
-
 
 static char dateformat[256] = "%b %e %T";		/* Original Asterisk Format */
 
@@ -909,10 +908,6 @@
 	if (!(global_logmask & (1 << level)))
 		return;
 	
-	/* Ignore anything other than the currently debugged file if there is one */
-	if ((level == __LOG_DEBUG) && !ast_strlen_zero(debug_filename) && strcasecmp(debug_filename, file))
-		return;
-
 	/* Build string */
 	va_start(ap, fmt);
 	res = ast_str_set_va(&buf, BUFSIZ, fmt, ap);

Modified: trunk/main/pbx.c
URL: http://svn.digium.com/view/asterisk/trunk/main/pbx.c?view=diff&rev=76555&r1=76554&r2=76555
==============================================================================
--- trunk/main/pbx.c (original)
+++ trunk/main/pbx.c Mon Jul 23 09:21:41 2007
@@ -1399,8 +1399,7 @@
 	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&acf_root, cur, acflist) {
 		if (cur == acf) {
 			AST_RWLIST_REMOVE_CURRENT(&acf_root, acflist);
-			if (option_verbose > 1)
-				ast_verbose(VERBOSE_PREFIX_2 "Unregistered custom function %s\n", acf->name);
+			ast_verb(2, "Unregistered custom function %s\n", acf->name);
 			break;
 		}
 	}
@@ -1442,8 +1441,7 @@
 
 	AST_RWLIST_UNLOCK(&acf_root);
 
-	if (option_verbose > 1)
-		ast_verbose(VERBOSE_PREFIX_2 "Registered custom function %s\n", acf->name);
+	ast_verb(2, "Registered custom function %s\n", acf->name);
 
 	return 0;
 }
@@ -1785,7 +1783,7 @@
 			}
 			if (option_verbose > 2) {
 				char tmp[80], tmp2[80], tmp3[EXT_DATA_SIZE];
-				ast_verbose( VERBOSE_PREFIX_3 "Executing [%s@%s:%d] %s(\"%s\", \"%s\") %s\n",
+				ast_verb(3, "Executing [%s@%s:%d] %s(\"%s\", \"%s\") %s\n",
 					exten, context, priority,
 					term_color(tmp, app->name, COLOR_BRCYAN, 0, sizeof(tmp)),
 					term_color(tmp2, c->name, COLOR_BRMAGENTA, 0, sizeof(tmp2)),
@@ -2368,8 +2366,7 @@
 	/* Start by trying whatever the channel is set to */
 	if (!ast_exists_extension(c, c->context, c->exten, c->priority, c->cid.cid_num)) {
 		/* If not successful fall back to 's' */
-		if (option_verbose > 1)
-			ast_verbose( VERBOSE_PREFIX_2 "Starting %s at %s,%s,%d failed so falling back to exten 's'\n", c->name, c->context, c->exten, c->priority);
+		ast_verb(2, "Starting %s at %s,%s,%d failed so falling back to exten 's'\n", c->name, c->context, c->exten, c->priority);
 		/* XXX the original code used the existing priority in the call to
 		 * ast_exists_extension(), and reset it to 1 afterwards.
 		 * I believe the correct thing is to set it to 1 immediately.
@@ -2377,8 +2374,7 @@
 		set_ext_pri(c, "s", 1);
 		if (!ast_exists_extension(c, c->context, c->exten, c->priority, c->cid.cid_num)) {
 			/* JK02: And finally back to default if everything else failed */
-			if (option_verbose > 1)
-				ast_verbose( VERBOSE_PREFIX_2 "Starting %s at %s,%s,%d still failed so falling back to context 'default'\n", c->name, c->context, c->exten, c->priority);
+			ast_verb(2, "Starting %s at %s,%s,%d still failed so falling back to context 'default'\n", c->name, c->context, c->exten, c->priority);
 			ast_copy_string(c->context, "default", sizeof(c->context));
 		}
 	}
@@ -2403,14 +2399,12 @@
 				}
 				if (res == AST_PBX_KEEPALIVE) {
 					ast_debug(1, "Spawn extension (%s,%s,%d) exited KEEPALIVE on '%s'\n", c->context, c->exten, c->priority, c->name);
-					if (option_verbose > 1)
-						ast_verbose( VERBOSE_PREFIX_2 "Spawn extension (%s, %s, %d) exited KEEPALIVE on '%s'\n", c->context, c->exten, c->priority, c->name);
+					ast_verb(2, "Spawn extension (%s, %s, %d) exited KEEPALIVE on '%s'\n", c->context, c->exten, c->priority, c->name);
 					error = 1;
 					break;
 				}
 				ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
-				if (option_verbose > 1)
-					ast_verbose( VERBOSE_PREFIX_2 "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
+				ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
 				if (c->_softhangup == AST_SOFTHANGUP_ASYNCGOTO) {
 					c->_softhangup =0;
 				} else if (c->_softhangup == AST_SOFTHANGUP_TIMEOUT) {
@@ -2445,8 +2439,7 @@
 			 * Try to continue at "i", 1 or exit if the latter does not exist.
 			 */
 			if (ast_exists_extension(c, c->context, "i", 1, c->cid.cid_num)) {
-				if (option_verbose > 2)
-					ast_verbose(VERBOSE_PREFIX_3 "Sent into invalid extension '%s' in context '%s' on %s\n", c->exten, c->context, c->name);
+				ast_verb(3, "Sent into invalid extension '%s' in context '%s' on %s\n", c->exten, c->context, c->name);
 				pbx_builtin_setvar_helper(c, "INVALID_EXTEN", c->exten);
 				set_ext_pri(c, "i", 1);
 			} else {
@@ -2468,8 +2461,7 @@
 				const char *status = pbx_builtin_getvar_helper(c, "DIALSTATUS");
 				if (!status)
 					status = "UNKNOWN";
-				if (option_verbose > 2)
-					ast_verbose(VERBOSE_PREFIX_2 "Auto fallthrough, channel '%s' status is '%s'\n", c->name, status);
+				ast_verb(3, "Auto fallthrough, channel '%s' status is '%s'\n", c->name, status);
 				if (!strcasecmp(status, "CONGESTION"))
 					res = pbx_builtin_congestion(c, "10");
 				else if (!strcasecmp(status, "CHANUNAVAIL"))
@@ -2489,8 +2481,7 @@
 				if (!ast_strlen_zero(dst_exten)) {
 					/* An invalid extension */
 					if (ast_exists_extension(c, c->context, "i", 1, c->cid.cid_num)) {
-						if (option_verbose > 2)
-							ast_verbose( VERBOSE_PREFIX_3 "Invalid extension '%s' in context '%s' on %s\n", dst_exten, c->context, c->name);
+						ast_verb(3, "Invalid extension '%s' in context '%s' on %s\n", dst_exten, c->context, c->name);
 						pbx_builtin_setvar_helper(c, "INVALID_EXTEN", dst_exten);
 						set_ext_pri(c, "i", 1);
 					} else {
@@ -2501,8 +2492,7 @@
 				} else {
 					/* A simple timeout */
 					if (ast_exists_extension(c, c->context, "t", 1, c->cid.cid_num)) {
-						if (option_verbose > 2)
-							ast_verbose( VERBOSE_PREFIX_3 "Timeout on %s\n", c->name);
+						ast_verb(3, "Timeout on %s\n", c->name);
 						set_ext_pri(c, "t", 1);
 					} else {
 						ast_log(LOG_WARNING, "Timeout, but no rule 't' in context '%s'\n", c->context);
@@ -2512,8 +2502,7 @@
 				}
 			}
 			if (c->cdr) {
-				if (option_verbose > 2)
-					ast_verbose(VERBOSE_PREFIX_2 "CDR updated on %s\n",c->name);
+				ast_verb(2, "CDR updated on %s\n",c->name);
 				ast_cdr_update(c);
 			}
 		}
@@ -2530,8 +2519,7 @@
 			if ((res = ast_spawn_extension(c, c->context, c->exten, c->priority, c->cid.cid_num))) {
 				/* Something bad happened, or a hangup has been requested. */
 				ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
-				if (option_verbose > 1)
-					ast_verbose( VERBOSE_PREFIX_2 "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
+				ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
 				break;
 			}
 			c->priority++;
@@ -2994,8 +2982,7 @@
 	if (!cur)
 		AST_RWLIST_INSERT_TAIL(&apps, tmp, list);
 
-	if (option_verbose > 1)
-		ast_verbose( VERBOSE_PREFIX_2 "Registered application '%s'\n", term_color(tmps, tmp->name, COLOR_BRCYAN, 0, sizeof(tmps)));
+	ast_verb(2, "Registered application '%s'\n", term_color(tmps, tmp->name, COLOR_BRCYAN, 0, sizeof(tmps)));
 
 	AST_RWLIST_UNLOCK(&apps);
 
@@ -3875,8 +3862,7 @@
 		if (!strcasecmp(app, tmp->name)) {
 			unreference_cached_app(tmp);
 			AST_RWLIST_REMOVE_CURRENT(&apps, list);
-			if (option_verbose > 1)
-				ast_verbose( VERBOSE_PREFIX_2 "Unregistered application '%s'\n", tmp->name);
+			ast_verb(2, "Unregistered application '%s'\n", tmp->name);
 			ast_free(tmp);
 			break;
 		}
@@ -3920,8 +3906,7 @@
 		tmp->ignorepats = NULL;
 		*local_contexts = tmp;
 		ast_debug(1, "Registered context '%s'\n", tmp->name);
-		if (option_verbose > 2)
-			ast_verbose( VERBOSE_PREFIX_3 "Registered extension context '%s'\n", tmp->name);
+		ast_verb(3, "Registered extension context '%s'\n", tmp->name);
 	}
 
 	if (!extcontexts)
@@ -4369,8 +4354,7 @@
 		il->next = new_include;
 	else
 		con->includes = new_include;
-	if (option_verbose > 2)
-		ast_verbose(VERBOSE_PREFIX_3 "Including context '%s' in context '%s'\n", new_include->name, ast_get_context_name(con));
+	ast_verb(3, "Including context '%s' in context '%s'\n", new_include->name, ast_get_context_name(con));
 
 	ast_unlock_context(con);
 
@@ -4457,8 +4441,7 @@
 	/* ... sw new context into context list, unlock, return */
 	AST_LIST_INSERT_TAIL(&con->alts, new_sw, list);
 
-	if (option_verbose > 2)
-		ast_verbose(VERBOSE_PREFIX_3 "Including switch '%s/%s' in context '%s'\n", new_sw->name, new_sw->data, ast_get_context_name(con));
+	ast_verb(3, "Including switch '%s/%s' in context '%s'\n", new_sw->name, new_sw->data, ast_get_context_name(con));
 
 	ast_unlock_context(con);
 
@@ -4893,15 +4876,15 @@
 				tmp->exten, tmp->priority, con->name);
 		}
 	}
-	if (option_verbose > 2) {
-		if (tmp->matchcid) {
-			ast_verbose( VERBOSE_PREFIX_3 "Added extension '%s' priority %d (CID match '%s')to %s\n",
-				tmp->exten, tmp->priority, tmp->cidmatch, con->name);
-		} else {
-			ast_verbose( VERBOSE_PREFIX_3 "Added extension '%s' priority %d to %s\n",
-				tmp->exten, tmp->priority, con->name);
-		}
-	}
+
+	if (tmp->matchcid) {
+		ast_verb(3, "Added extension '%s' priority %d (CID match '%s')to %s\n",
+			tmp->exten, tmp->priority, tmp->cidmatch, con->name);
+	} else {
+		ast_verb(3, "Added extension '%s' priority %d to %s\n",
+			tmp->exten, tmp->priority, con->name);
+	}
+	
 	return 0;
 }
 
@@ -4947,8 +4930,7 @@
 		if (!ast_strlen_zero(as->app)) {
 			app = pbx_findapp(as->app);
 			if (app) {
-				if (option_verbose > 2)
-					ast_verbose(VERBOSE_PREFIX_3 "Launching %s(%s) on %s\n", as->app, as->appdata, chan->name);
+				ast_verb(3, "Launching %s(%s) on %s\n", as->app, as->appdata, chan->name);
 				pbx_exec(chan, app, as->appdata);
 			} else
 				ast_log(LOG_WARNING, "No such application '%s'\n", as->app);
@@ -5030,8 +5012,7 @@
 		if (chan) {
 			if (chan->_state == AST_STATE_UP) {
 					res = 0;
-				if (option_verbose > 3)
-					ast_verbose(VERBOSE_PREFIX_4 "Channel %s was answered.\n", chan->name);
+				ast_verb(4, "Channel %s was answered.\n", chan->name);
 
 				if (sync > 1) {
 					if (channel)
@@ -5055,8 +5036,7 @@
 					}
 				}
 			} else {
-				if (option_verbose > 3)
-					ast_verbose(VERBOSE_PREFIX_4 "Channel %s was never answered.\n", chan->name);
+				ast_verb(4, "Channel %s was never answered.\n", chan->name);
 
 				if (chan->cdr) { /* update the cdr */
 					/* here we update the status of the call, which sould be busy.
@@ -5153,8 +5133,7 @@
 	struct ast_app *app;
 	app = pbx_findapp(tmp->app);
 	if (app) {
-		if (option_verbose > 3)
-			ast_verbose(VERBOSE_PREFIX_4 "Launching %s(%s) on %s\n", tmp->app, tmp->data, tmp->chan->name);
+		ast_verb(4, "Launching %s(%s) on %s\n", tmp->app, tmp->data, tmp->chan->name);
 		pbx_exec(tmp->chan, app, tmp->data);
 	} else
 		ast_log(LOG_WARNING, "No such application '%s'\n", tmp->app);
@@ -5202,8 +5181,7 @@
 				ast_cdr_setaccount(chan, account);
 			if (chan->_state == AST_STATE_UP) {
 				res = 0;
-				if (option_verbose > 3)
-					ast_verbose(VERBOSE_PREFIX_4 "Channel %s was answered.\n", chan->name);
+				ast_verb(4, "Channel %s was answered.\n", chan->name);
 				tmp = ast_calloc(1, sizeof(*tmp));
 				if (!tmp)
 					res = -1;
@@ -5233,8 +5211,7 @@
 					}
 				}
 			} else {
-				if (option_verbose > 3)
-					ast_verbose(VERBOSE_PREFIX_4 "Channel %s was never answered.\n", chan->name);
+				ast_verb(4, "Channel %s was never answered.\n", chan->name);
 				if (chan->cdr) { /* update the cdr */
 					/* here we update the status of the call, which sould be busy.
 					 * if that fails then we set the status to failed */
@@ -5637,11 +5614,9 @@
 	res = ast_waitfordigit(chan, ms);
 	if (!res) {
 		if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 1, chan->cid.cid_num)) {
-			if (option_verbose > 2)
-				ast_verbose(VERBOSE_PREFIX_3 "Timeout on %s, continuing...\n", chan->name);
+			ast_verb(3, "Timeout on %s, continuing...\n", chan->name);
 		} else if (ast_exists_extension(chan, chan->context, "t", 1, chan->cid.cid_num)) {
-			if (option_verbose > 2)
-				ast_verbose(VERBOSE_PREFIX_3 "Timeout on %s, going to 't'\n", chan->name);
+			ast_verb(3, "Timeout on %s, going to 't'\n", chan->name);
 			set_ext_pri(chan, "t", 0); /* XXX is the 0 correct ? */
 		} else {
 			ast_log(LOG_WARNING, "Timeout but no rule 't' in context '%s'\n", chan->context);
@@ -5744,8 +5719,8 @@
 static int pbx_builtin_goto(struct ast_channel *chan, void *data)
 {
 	int res = ast_parseable_goto(chan, data);
-	if (!res && (option_verbose > 2))
-		ast_verbose( VERBOSE_PREFIX_3 "Goto (%s,%s,%d)\n", chan->context,chan->exten, chan->priority+1);
+	if (!res)
+		ast_verb(3, "Goto (%s,%s,%d)\n", chan->context,chan->exten, chan->priority+1);
 	return res;
 }
 
@@ -5826,8 +5801,8 @@
 	headp = (chan) ? &chan->varshead : &globals;
 
 	if (value) {
-		if ((option_verbose > 1) && (headp == &globals))
-			ast_verbose(VERBOSE_PREFIX_2 "Setting global variable '%s' to '%s'\n", name, value);
+		if (headp == &globals)
+			ast_verb(2, "Setting global variable '%s' to '%s'\n", name, value);
 		newvariable = ast_var_assign(name, value);
 		if (headp == &globals)
 			ast_rwlock_wrlock(&globalslock);
@@ -5872,8 +5847,8 @@
 	}
 
 	if (value) {
-		if ((option_verbose > 1) && (headp == &globals))
-			ast_verbose(VERBOSE_PREFIX_2 "Setting global variable '%s' to '%s'\n", name, value);
+		if (headp == &globals)
+			ast_verb(2, "Setting global variable '%s' to '%s'\n", name, value);
 		newvariable = ast_var_assign(name, value);
 		AST_LIST_INSERT_HEAD(headp, newvariable, entries);
 		manager_event(EVENT_FLAG_CALL, "VarSet", 
@@ -6075,16 +6050,14 @@
 	int x;
 
 	/* Initialize the PBX */
-	if (option_verbose) {
-		ast_verbose( "Asterisk PBX Core Initializing\n");
-		ast_verbose( "Registering builtin applications:\n");
-	}
+	ast_verb(1, "Asterisk PBX Core Initializing\n");
+	ast_verb(1, "Registering builtin applications:\n");
+	
 	ast_cli_register_multiple(pbx_cli, sizeof(pbx_cli) / sizeof(struct ast_cli_entry));
 
 	/* Register builtin applications */
 	for (x=0; x<sizeof(builtins) / sizeof(struct pbx_builtin); x++) {
-		if (option_verbose)
-			ast_verbose( VERBOSE_PREFIX_1 "[%s]\n", builtins[x].name);
+		ast_verb(1, "[%s]\n", builtins[x].name);
 		if (ast_register_application2(builtins[x].name, builtins[x].execute, builtins[x].synopsis, builtins[x].description, NULL)) {
 			ast_log(LOG_ERROR, "Unable to register builtin application '%s'\n", builtins[x].name);
 			return -1;




More information about the asterisk-commits mailing list