diff --git a/asterisk.c b/asterisk.c index 9702dc6e404ed47f0f702a7f369c72cd495524db..2390f65dc4e394f58ed7cb70ca628cdeeffda9ec 100755 --- a/asterisk.c +++ b/asterisk.c @@ -85,6 +85,7 @@ int option_overrideconfig = 0; int option_reconnect = 0; int fully_booted = 0; 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 */ diff --git a/cli.c b/cli.c index 8f91618f1b71c9a3877abcb4af607763a8a1aae0..683d37988249baa7f93c8ed4d3a74479731ddb00 100755 --- a/cli.c +++ b/cli.c @@ -441,6 +441,11 @@ static char debugchan_help[] = "Usage: debug channel <channel>\n" " Enables debugging on a specific channel.\n"; +static char debuglevel_help[] = +"Usage: debug level <level> [filename]\n" +" Set debug to specified level (0 to disable). If filename\n" +"is specified, debugging will be limited to just that file.\n"; + static char nodebugchan_help[] = "Usage: no debug channel <channel>\n" " Disables debugging on a specific channel.\n"; @@ -571,6 +576,25 @@ static int handle_commandcomplete(int fd, int argc, char *argv[]) return RESULT_SUCCESS; } +static int handle_debuglevel(int fd, int argc, char *argv[]) +{ + int newlevel; + char *filename = "<any>"; + if ((argc < 3) || (argc > 4)) + return RESULT_SHOWUSAGE; + if (sscanf(argv[2], "%i", &newlevel) != 1) + return RESULT_SHOWUSAGE; + option_debug = newlevel; + if (argc == 4) { + filename = argv[3]; + strncpy(debug_filename, filename, sizeof(debug_filename) - 1); + } else { + debug_filename[0] = '\0'; + } + ast_cli(fd, "Debugging level set to %d, file '%s'\n", newlevel, filename); + return RESULT_SUCCESS; +} + static int handle_debugchan(int fd, int argc, char *argv[]) { struct ast_channel *c=NULL; @@ -792,6 +816,7 @@ static struct ast_cli_entry builtins[] = { { { "_command", "nummatches", NULL }, handle_commandnummatches, "Returns number of command matches", commandnummatches_help }, { { "_command", "matchesarray", NULL }, handle_commandmatchesarray, "Returns command matches array", commandmatchesarray_help }, { { "debug", "channel", NULL }, handle_debugchan, "Enable debugging on a channel", debugchan_help, complete_ch_3 }, + { { "debug", "level", NULL }, handle_debuglevel, "Set global debug level", debuglevel_help }, { { "help", NULL }, handle_help, "Display help list, or specific help on a command", help_help }, { { "load", NULL }, handle_load, "Load a dynamic module by name", load_help, complete_fn }, { { "no", "debug", "channel", NULL }, handle_nodebugchan, "Disable debugging on a channel", nodebugchan_help, complete_ch_4 }, diff --git a/include/asterisk/options.h b/include/asterisk/options.h index d60cb000a66014d2b6fb163c87d8661f8b552c02..5cbdeab0f6eca5226785a639783f190ed13dc6d5 100755 --- a/include/asterisk/options.h +++ b/include/asterisk/options.h @@ -19,6 +19,7 @@ extern "C" { #endif #define AST_CACHE_DIR_LEN 512 +#define AST_FILENAME_MAX 80 extern int option_verbose; extern int option_debug; @@ -35,6 +36,7 @@ extern time_t ast_startuptime; extern time_t ast_lastreloadtime; extern int ast_mainpid; extern char record_cache_dir[AST_CACHE_DIR_LEN]; +extern char debug_filename[AST_FILENAME_MAX]; #define VERBOSE_PREFIX_1 " " #define VERBOSE_PREFIX_2 " == " diff --git a/logger.c b/logger.c index d9e5dfd32cf509158e2cc447b991320c811d67f7..502a9719fbeefa1afca3315895ddf56a821815bf 100755 --- a/logger.c +++ b/logger.c @@ -564,6 +564,10 @@ void ast_log(int level, const char *file, int line, const char *function, const /* Ignore anything that never gets logged anywhere */ 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; /* begin critical section */ ast_mutex_lock(&loglock);