diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/asterisk.c | 45 | ||||
-rw-r--r-- | main/bridge.c | 4 | ||||
-rw-r--r-- | main/config_options.c | 2 | ||||
-rw-r--r-- | main/loader.c | 19 | ||||
-rw-r--r-- | main/logger.c | 59 | ||||
-rw-r--r-- | main/optional_api.c | 10 | ||||
-rw-r--r-- | main/pbx.c | 5 | ||||
-rw-r--r-- | main/xmldoc.c | 2 |
8 files changed, 75 insertions, 71 deletions
diff --git a/main/asterisk.c b/main/asterisk.c index a3bb88198..213828c03 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -2068,13 +2068,14 @@ static void __remote_quit_handler(int num) sig_flags.need_quit = 1; } -static const char *fix_header(char *outbuf, int maxout, const char *s, char level) +static void set_header(char *outbuf, int maxout, char level) { const char *cmp; + char date[40]; switch (level) { - case 0: *outbuf = '\0'; - return s; + case 0: cmp = NULL; + break; case 1: cmp = VERBOSE_PREFIX_1; break; case 2: cmp = VERBOSE_PREFIX_2; @@ -2085,12 +2086,20 @@ static const char *fix_header(char *outbuf, int maxout, const char *s, char leve break; } - if (!strncmp(s, cmp, strlen(cmp))) { - s += strlen(cmp); + if (ast_opt_timestamp) { + struct ast_tm tm; + struct timeval now = ast_tvnow(); + ast_localtime(&now, &tm, NULL); + ast_strftime(date, sizeof(date), ast_logger_get_dateformat(), &tm); } - term_color(outbuf, cmp, COLOR_GRAY, 0, maxout); - return s; + snprintf(outbuf, maxout, "%s%s%s%s%s%s", + ast_opt_timestamp ? "[" : "", + ast_opt_timestamp ? date : "", + ast_opt_timestamp ? "] " : "", + cmp ? ast_term_color(COLOR_GRAY, 0) : "", + cmp ? cmp : "", + cmp ? ast_term_reset() : ""); } struct console_state_data { @@ -2118,16 +2127,15 @@ static int console_print(const char *s, int local) do { if (VERBOSE_HASMAGIC(s)) { + /* always use the given line's level, otherwise we'll use the last line's level */ state->verbose_line_level = VERBOSE_MAGIC2LEVEL(s); + /* move past magic */ s++; - if (local) { - s = fix_header(prefix, sizeof(prefix), s, - state->verbose_line_level); - } + set_header(prefix, sizeof(prefix), state->verbose_line_level); } else { *prefix = '\0'; } @@ -2149,7 +2157,7 @@ static int console_print(const char *s, int local) continue; } - if (local && !ast_strlen_zero(prefix)) { + if (!ast_strlen_zero(prefix)) { fputs(prefix, stdout); } @@ -2572,8 +2580,6 @@ static char *show_license(struct ast_cli_entry *e, int cmd, struct ast_cli_args #define ASTERISK_PROMPT "*CLI> " -#define ASTERISK_PROMPT2 "%s*CLI> " - /*! * \brief Shutdown Asterisk CLI commands. * @@ -2841,10 +2847,10 @@ static char *cli_prompt(EditLine *editline) /* Force colors back to normal at end */ ast_term_color_code(&prompt, 0, 0); } - } else if (remotehostname) { - ast_str_set(&prompt, 0, ASTERISK_PROMPT2, remotehostname); } else { - ast_str_set(&prompt, 0, "%s", ASTERISK_PROMPT); + ast_str_set(&prompt, 0, "%s%s", + remotehostname ? remotehostname : "", + ASTERISK_PROMPT); } return ast_str_buffer(prompt); @@ -4552,9 +4558,6 @@ int main(int argc, char *argv[]) dnsmgr_start_refresh(); - /* We might have the option of showing a console, but for now just - do nothing... */ - ast_verb(0, COLORIZE_FMT "\n", COLORIZE(COLOR_BRWHITE, COLOR_BLACK, "Asterisk Ready.")); if (ast_opt_no_fork) { consolethread = pthread_self(); } @@ -4581,6 +4584,8 @@ int main(int argc, char *argv[]) run_startup_commands(); + ast_verb(0, COLORIZE_FMT "\n", COLORIZE(COLOR_BRGREEN, 0, "Asterisk Ready.")); + if (ast_opt_console) { /* Console stuff now... */ /* Register our quit function */ diff --git a/main/bridge.c b/main/bridge.c index fa4e3c699..dd6861785 100644 --- a/main/bridge.c +++ b/main/bridge.c @@ -2541,7 +2541,7 @@ static int try_swap_optimize_out(struct ast_bridge *chan_bridge, id = ast_atomic_fetchadd_int((int *) &optimization_id, +1); - ast_verb(3, "Move-swap optimizing %s <-- %s.\n", + ast_verb(4, "Move-swap optimizing %s <-- %s.\n", ast_channel_name(dst_bridge_channel->chan), ast_channel_name(other->chan)); @@ -2658,7 +2658,7 @@ static int try_merge_optimize_out(struct ast_bridge *chan_bridge, return 0; } - ast_verb(3, "Merge optimizing %s -- %s out.\n", + ast_verb(4, "Merge optimizing %s -- %s out.\n", ast_channel_name(chan_bridge_channel->chan), ast_channel_name(peer_bridge_channel->chan)); diff --git a/main/config_options.c b/main/config_options.c index a52a9da25..ae40c6289 100644 --- a/main/config_options.c +++ b/main/config_options.c @@ -1191,7 +1191,7 @@ static void cli_show_module_options(struct ast_cli_args *a) ast_cli(a->fd, "\n"); } term_color(option_name, tmp->ref, COLOR_MAGENTA, COLOR_BLACK, sizeof(option_name)); - ast_cli(a->fd, "[%s%s]\n", option_name, term_end()); + ast_cli(a->fd, "[%s%s]\n", option_name, ast_term_reset()); if (ast_str_strlen(tmp->syntax)) { ast_cli(a->fd, "%s\n", ast_xmldoc_printable(ast_str_buffer(tmp->syntax), 1)); } diff --git a/main/loader.c b/main/loader.c index e40cbf369..d4e94a622 100644 --- a/main/loader.c +++ b/main/loader.c @@ -185,7 +185,7 @@ void ast_module_register(const struct ast_module_info *info) mod = resource_being_loaded; } - ast_verb(5, "Registering module %s\n", info->name); + ast_debug(5, "Registering module %s\n", info->name); mod->info = info; AST_LIST_HEAD_INIT(&mod->users); @@ -232,7 +232,7 @@ void ast_module_unregister(const struct ast_module_info *info) AST_LIST_UNLOCK(&module_list); if (mod) { - ast_verb(5, "Unregistering module %s\n", info->name); + ast_debug(5, "Unregistering module %s\n", info->name); AST_LIST_HEAD_DESTROY(&mod->users); ast_free(mod); } @@ -440,20 +440,16 @@ static int is_module_loaded(const char *resource_name) char fn[PATH_MAX] = ""; void *lib; - ast_verb(10, "Checking if %s is loaded\n", resource_name); - snprintf(fn, sizeof(fn), "%s/%s", ast_config_AST_MODULE_DIR, resource_name); lib = dlopen(fn, RTLD_LAZY | RTLD_NOLOAD); if (lib) { - ast_verb(10, " %s loaded\n", resource_name); logged_dlclose(resource_name, lib); return 1; } - ast_verb(10, " %s not loaded\n", resource_name); return 0; } #endif @@ -843,7 +839,7 @@ enum ast_module_reload_result ast_module_reload(const char *name) } if (ast_mutex_trylock(&reloadlock)) { - ast_verbose("The previous reload command didn't finish yet\n"); + ast_verb(3, "The previous reload command didn't finish yet\n"); res = AST_MODULE_RELOAD_IN_PROGRESS; goto module_reload_exit; } @@ -859,7 +855,7 @@ enum ast_module_reload_result ast_module_reload(const char *name) } } if (res != AST_LOCK_SUCCESS) { - ast_verbose("Cannot grab lock on %s\n", ast_config_AST_CONFIG_DIR); + ast_log(AST_LOG_WARNING, "Cannot grab lock on %s\n", ast_config_AST_CONFIG_DIR); ast_mutex_unlock(&reloadlock); res = AST_MODULE_RELOAD_ERROR; goto module_reload_exit; @@ -977,12 +973,7 @@ static enum ast_module_load_result start_resource(struct ast_module *mod) switch (res) { case AST_MODULE_LOAD_SUCCESS: if (!ast_fully_booted) { - ast_verb(1, "%s => (%s)\n", mod->resource, term_color(tmp, mod->info->description, COLOR_BROWN, COLOR_BLACK, sizeof(tmp))); - if (ast_opt_console && !option_verbose) { - /* This never looks good on anything but the root console, so - * it's best not to try to funnel it through the logger. */ - fprintf(stdout, "."); - } + ast_verb(2, "%s => (%s)\n", mod->resource, term_color(tmp, mod->info->description, COLOR_BROWN, COLOR_BLACK, sizeof(tmp))); } else { ast_verb(1, "Loaded %s => (%s)\n", mod->resource, mod->info->description); } diff --git a/main/logger.c b/main/logger.c index 2c0f3f4a3..16a044a6e 100644 --- a/main/logger.c +++ b/main/logger.c @@ -235,6 +235,7 @@ static const int colors[NUMLOGLEVELS] = { }; AST_THREADSTORAGE(verbose_buf); +AST_THREADSTORAGE(verbose_build_buf); #define VERBOSE_BUF_INIT_SIZE 256 AST_THREADSTORAGE(log_buf); @@ -1171,25 +1172,50 @@ static void ast_log_vsyslog(struct logmsg *msg) syslog(syslog_level, "%s", buf); } +static char *logger_strip_verbose_magic(const char *message, int level) +{ + char *p; + char *stripped_message = ast_strdup(message); + char magic = -(level + 1); + + if (!stripped_message) { + return NULL; + } + + do { + p = strchr(stripped_message, (char)magic); + if (p) { + *p++ = ' '; + } + } while (p && *p); + + return stripped_message; +} + /*! \brief Print a normal log message to the channels */ static void logger_print_normal(struct logmsg *logmsg) { struct logchannel *chan = NULL; char buf[BUFSIZ]; struct verb *v = NULL; + char *tmpmsg; int level = 0; if (logmsg->level == __LOG_VERBOSE) { - char *tmpmsg = ast_strdupa(logmsg->message + 1); - - level = VERBOSE_MAGIC2LEVEL(logmsg->message); /* Iterate through the list of verbosers and pass them the log message string */ AST_RWLIST_RDLOCK(&verbosers); AST_RWLIST_TRAVERSE(&verbosers, v, list) v->verboser(logmsg->message); AST_RWLIST_UNLOCK(&verbosers); - ast_string_field_set(logmsg, message, tmpmsg); + + level = VERBOSE_MAGIC2LEVEL(logmsg->message); + + tmpmsg = logger_strip_verbose_magic(logmsg->message, level); + if (tmpmsg) { + ast_string_field_set(logmsg, message, tmpmsg); + ast_free(tmpmsg); + } } AST_RWLIST_RDLOCK(&logchannels); @@ -1746,9 +1772,8 @@ void ast_log_backtrace(void) void __ast_verbose_ap(const char *file, int line, const char *func, int level, struct ast_callid *callid, const char *fmt, va_list ap) { const char *p; - struct ast_str *prefixed, *buf = NULL; + struct ast_str *prefixed, *buf; int res = 0; - const char *prefix = level >= 4 ? VERBOSE_PREFIX_4 : level == 3 ? VERBOSE_PREFIX_3 : level == 2 ? VERBOSE_PREFIX_2 : level == 1 ? VERBOSE_PREFIX_1 : ""; signed char magic = level > 9 ? -10 : -level - 1; /* 0 => -1, 1 => -2, etc. Can't pass NUL, as it is EOS-delimiter */ /* For compatibility with modules still calling ast_verbose() directly instead of using ast_verb() */ @@ -1767,18 +1792,18 @@ void __ast_verbose_ap(const char *file, int line, const char *func, int level, s } if (!(prefixed = ast_str_thread_get(&verbose_buf, VERBOSE_BUF_INIT_SIZE)) || - !(buf = ast_str_create(VERBOSE_BUF_INIT_SIZE))) { + !(buf = ast_str_thread_get(&verbose_build_buf, VERBOSE_BUF_INIT_SIZE))) { return; } res = ast_str_set_va(&buf, 0, fmt, ap); /* If the build failed then we can drop this allocated message */ if (res == AST_DYNSTR_BUILD_FAILED) { - ast_free(buf); return; } ast_str_reset(prefixed); + /* for every newline found in the buffer add verbose prefix data */ fmt = ast_str_buffer(buf); do { @@ -1787,22 +1812,12 @@ void __ast_verbose_ap(const char *file, int line, const char *func, int level, s } ++p; - if (ast_opt_timestamp) { - struct ast_tm tm; - char date[40]; - struct timeval now = ast_tvnow(); - ast_localtime(&now, &tm, NULL); - ast_strftime(date, sizeof(date), dateformat, &tm); - ast_str_append(&prefixed, 0, "%c[%s] %s", (char) magic, date, prefix); - } else { - ast_str_append(&prefixed, 0, "%c%s", (char) magic, prefix); - } + ast_str_append(&prefixed, 0, "%c", (char)magic); ast_str_append_substr(&prefixed, 0, fmt, p - fmt); fmt = p; } while (p && *p); ast_log_callid(__LOG_VERBOSE, file, line, func, callid, "%s", ast_str_buffer(prefixed)); - ast_free(buf); } void __ast_verbose(const char *file, int line, const char *func, int level, const char *fmt, ...) @@ -2121,3 +2136,9 @@ void ast_logger_unregister_level(const char *name) AST_RWLIST_UNLOCK(&logchannels); } } + +const char *ast_logger_get_dateformat(void) +{ + return dateformat; +} + diff --git a/main/optional_api.c b/main/optional_api.c index f9d5fc68f..92f36eaf9 100644 --- a/main/optional_api.c +++ b/main/optional_api.c @@ -135,7 +135,6 @@ static struct optional_api *optional_api_create(const char *symname) struct optional_api *api; size_t size; - ast_verb(6, "%s: building api object\n", symname); size = sizeof(*api) + strlen(symname) + 1; api = ast_std_calloc(1, size); if (!api) { @@ -219,11 +218,8 @@ static void optional_api_user_relink(struct optional_api_user *user, struct optional_api *api) { if (api->impl && *user->optional_ref != api->impl) { - ast_verb(4, "%s: linking for %s\n", api->symname, user->module); *user->optional_ref = api->impl; } else if (!api->impl && *user->optional_ref != user->stub) { - ast_verb(4, "%s: stubbing for %s\n", api->symname, - user->module); *user->optional_ref = user->stub; } } @@ -252,8 +248,6 @@ void ast_optional_api_provide(const char *symname, ast_optional_fn impl) { struct optional_api *api; - ast_verb(4, "%s: providing\n", symname); - api = get_api(symname); if (!api) { ast_log(LOG_ERROR, "%s: Allocation failed\n", symname); @@ -268,8 +262,6 @@ void ast_optional_api_unprovide(const char *symname, ast_optional_fn impl) { struct optional_api *api; - ast_verb(4, "%s: un-providing\n", symname); - api = get_api(symname); if (!api) { ast_log(LOG_ERROR, "%s: Could not find api\n", symname); @@ -341,8 +333,6 @@ void ast_optional_api_unuse(const char *symname, ast_optional_fn *optional_ref, if (user->optional_ref == optional_ref) { if (*user->optional_ref != user->stub) { - ast_verb(4, "%s: stubbing for %s\n", symname, - module); *user->optional_ref = user->stub; } diff --git a/main/pbx.c b/main/pbx.c index faddc4774..0d0c7aafa 100644 --- a/main/pbx.c +++ b/main/pbx.c @@ -8613,7 +8613,6 @@ struct ast_context *ast_context_find_or_create(struct ast_context **extcontexts, *local_contexts = tmp; ast_hashtab_insert_safe(contexts_table, tmp); /*put this context into the tree */ ast_unlock_contexts(); - ast_debug(1, "Registered context '%s'(%p) in table %p registrar: %s\n", tmp->name, tmp, contexts_table, registrar); ast_verb(3, "Registered extension context '%s'; registrar: %s\n", tmp->name, registrar); } else { tmp->next = *local_contexts; @@ -8621,7 +8620,6 @@ struct ast_context *ast_context_find_or_create(struct ast_context **extcontexts, ast_hashtab_insert_immediate(exttable, tmp); /*put this context into the tree */ *local_contexts = tmp; - ast_debug(1, "Registered context '%s'(%p) in local table %p; registrar: %s\n", tmp->name, tmp, exttable, registrar); ast_verb(3, "Registered extension context '%s'; registrar: %s\n", tmp->name, registrar); } return tmp; @@ -11927,7 +11925,7 @@ int load_pbx(void) /* Initialize the PBX */ ast_verb(1, "Asterisk PBX Core Initializing\n"); - ast_verb(1, "Registering builtin applications:\n"); + ast_verb(2, "Registering builtin applications and functions:\n"); ast_cli_register_multiple(pbx_cli, ARRAY_LEN(pbx_cli)); ast_data_register_multiple_core(pbx_data_providers, ARRAY_LEN(pbx_data_providers)); __ast_custom_function_register(&exception_function, NULL); @@ -11935,7 +11933,6 @@ int load_pbx(void) /* Register builtin applications */ for (x = 0; x < ARRAY_LEN(builtins); x++) { - ast_verb(1, "[%s]\n", builtins[x].name); if (ast_register_application2(builtins[x].name, builtins[x].execute, NULL, NULL, NULL)) { ast_log(LOG_ERROR, "Unable to register builtin application '%s'\n", builtins[x].name); return -1; diff --git a/main/xmldoc.c b/main/xmldoc.c index 431eb1dd7..28bea86bd 100644 --- a/main/xmldoc.c +++ b/main/xmldoc.c @@ -432,7 +432,7 @@ char *ast_xmldoc_printable(const char *bwinput, int withcolors) } if (withcolors) { - ast_str_append(&colorized, 0, "%s", term_end()); + ast_str_append(&colorized, 0, "%s", ast_term_reset()); if (!colorized) { return NULL; } |