Newer
Older
time(&t);
ast_localtime(&t, &tm, NULL);
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_LIST_LOCK(&verbosers);
AST_LIST_INSERT_HEAD(&verbosers, verb, list);
AST_LIST_UNLOCK(&verbosers);
int ast_unregister_verbose(void (*v)(const char *string))
AST_LIST_LOCK(&verbosers);
AST_LIST_TRAVERSE_SAFE_BEGIN(&verbosers, cur, list) {
if (cur->verboser == v) {
AST_LIST_REMOVE_CURRENT(&verbosers, list);
free(cur);
AST_LIST_TRAVERSE_SAFE_END
AST_LIST_UNLOCK(&verbosers);
return cur ? 0 : -1;