Newer
Older
/* don't display LOG_DEBUG messages unless option_verbose _or_ option_debug
are non-zero; LOG_DEBUG messages can still be displayed if option_debug
is zero, if option_verbose is non-zero (this allows for 'level zero'
LOG_DEBUG messages to be displayed, if the logmask on any channel
allows it)
*/
if (!option_verbose && !option_debug && (level == __LOG_DEBUG))
Kevin P. Fleming
committed
/* Ignore anything that never gets logged anywhere */
if (!(global_logmask & (1 << level)))
return;
/* Build string */
va_start(ap, fmt);
res = ast_str_set_va(&buf, BUFSIZ, fmt, ap);
va_end(ap);
Jeremy McNamara
committed
/* If the build failed, then abort and free this structure */
if (res == AST_DYNSTR_BUILD_FAILED)
return;
/* Create a new logging message */
if (!(logmsg = ast_calloc(1, sizeof(*logmsg) + res + 1)))
/* Copy string over */
strcpy(logmsg->str, buf->str);
/* Set type to be normal */
logmsg->type = LOGMSG_NORMAL;
/* Create our date/time */
Tilghman Lesher
committed
ast_localtime(&tv, &tm, NULL);
ast_strftime(logmsg->date, sizeof(logmsg->date), dateformat, &tm);
/* Copy over data */
logmsg->level = level;
logmsg->file = file;
logmsg->line = line;
logmsg->function = function;
/* If the logger thread is active, append it to the tail end of the list - otherwise skip that step */
if (logthread != AST_PTHREADT_NULL) {
AST_LIST_LOCK(&logmsgs);
AST_LIST_INSERT_TAIL(&logmsgs, logmsg, list);
ast_cond_signal(&logcond);
AST_LIST_UNLOCK(&logmsgs);
} else {
logger_print_normal(logmsg);
free(logmsg);
return;
int count=0, i=0;
void **addresses;
char **strings;
Russell Bryant
committed
if ((addresses = ast_calloc(MAX_BACKTRACE_FRAMES, sizeof(*addresses)))) {
count = backtrace(addresses, MAX_BACKTRACE_FRAMES);
Russell Bryant
committed
if ((strings = backtrace_symbols(addresses, count))) {
ast_debug(1, "Got %d backtrace record%c\n", count, count != 1 ? 's' : ' ');
#if __WORDSIZE == 32
ast_log(LOG_DEBUG, "#%d: [%08X] %s\n", i, (unsigned int)addresses[i], strings[i]);
#elif __WORDSIZE == 64
ast_log(LOG_DEBUG, "#%d: [%016lX] %s\n", i, (unsigned long)addresses[i], strings[i]);
#endif
}
free(strings);
} else {
ast_debug(1, "Could not allocate memory for backtrace\n");
}
free(addresses);
}
#else
ast_log(LOG_WARNING, "Must run configure with '--enable-dev-mode' for stack backtraces.\n");
ast_log(LOG_WARNING, "Inline stack backtraces are only available on the Linux platform.\n");
void ast_verbose(const char *fmt, ...)
struct logmsg *logmsg = NULL;
struct ast_str *buf = NULL;
int res = 0;
if (!(buf = ast_str_thread_get(&verbose_buf, VERBOSE_BUF_INIT_SIZE)))
return;
if (ast_opt_timestamp) {
Tilghman Lesher
committed
struct timeval tv;
struct ast_tm tm;
char date[40];
char *datefmt;
Tilghman Lesher
committed
tv = ast_tvnow();
ast_localtime(&tv, &tm, NULL);
ast_strftime(date, sizeof(date), dateformat, &tm);
datefmt = alloca(strlen(date) + 3 + strlen(fmt) + 1);
sprintf(datefmt, "[%s] %s", date, fmt);
fmt = datefmt;
}
/* Build string */
va_start(ap, fmt);
res = ast_str_set_va(&buf, 0, fmt, ap);
va_end(ap);
/* If the build failed then we can drop this allocated message */
if (res == AST_DYNSTR_BUILD_FAILED)
return;
if (!(logmsg = ast_calloc(1, sizeof(*logmsg) + res + 1)))
return;
strcpy(logmsg->str, buf->str);
Joshua Colp
committed
ast_log(LOG_VERBOSE, logmsg->str);
/* Set type */
logmsg->type = LOGMSG_VERBOSE;
/* Add to the list and poke the thread if possible */
if (logthread != AST_PTHREADT_NULL) {
AST_LIST_LOCK(&logmsgs);
AST_LIST_INSERT_TAIL(&logmsgs, logmsg, list);
ast_cond_signal(&logcond);
AST_LIST_UNLOCK(&logmsgs);
} else {
logger_print_verbose(logmsg);
free(logmsg);
}
int ast_register_verbose(void (*v)(const char *string))
{
struct verb *verb;
if (!(verb = ast_malloc(sizeof(*verb))))
return -1;
AST_RWLIST_WRLOCK(&verbosers);
AST_RWLIST_INSERT_HEAD(&verbosers, verb, list);
AST_RWLIST_UNLOCK(&verbosers);
int ast_unregister_verbose(void (*v)(const char *string))
AST_RWLIST_WRLOCK(&verbosers);
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&verbosers, cur, list) {
if (cur->verboser == v) {
AST_RWLIST_REMOVE_CURRENT(list);
AST_RWLIST_TRAVERSE_SAFE_END;
AST_RWLIST_UNLOCK(&verbosers);
return cur ? 0 : -1;