[asterisk-commits] jrose: branch jrose/call_identifiers r359941 - in /team/jrose/call_identifier...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Mar 19 13:14:50 CDT 2012
Author: jrose
Date: Mon Mar 19 13:14:44 2012
New Revision: 359941
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=359941
Log:
Splitting log function
Modified:
team/jrose/call_identifiers/include/asterisk/logger.h
team/jrose/call_identifiers/main/logger.c
Modified: team/jrose/call_identifiers/include/asterisk/logger.h
URL: http://svnview.digium.com/svn/asterisk/team/jrose/call_identifiers/include/asterisk/logger.h?view=diff&rev=359941&r1=359940&r2=359941
==============================================================================
--- team/jrose/call_identifiers/include/asterisk/logger.h (original)
+++ team/jrose/call_identifiers/include/asterisk/logger.h Mon Mar 19 13:14:44 2012
@@ -59,6 +59,24 @@
void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
__attribute__((format(printf, 5, 6)));
+
+/* XXX needs documentation */
+struct ast_callid;
+
+/*! \brief Used for sending a log message with a known call_id
+ This is a modified logger function which is functionally identical to the above logger function,
+ it just include a call_id argument as well. If NULL is specified here, no attempt will be made to
+ join the log message with a call_id.
+
+ \param level Type of log event
+ \param file Will be provided by the AST_LOG_* macro
+ \param line Will be provided by the AST_LOG_* macro
+ \param function Will be provided by the AST_LOG_* macro
+ \param callid This is the ast_callid that is associated with the log message. May be NULL.
+ \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_callid(int level, const char *file, int line, const char *function, struct ast_callid *callid, const char *fmt, ...)
+ __attribute__((format(printf, 6, 7)));
void ast_backtrace(void);
@@ -214,9 +232,6 @@
* \since 1.8
*/
void ast_logger_unregister_level(const char *name);
-
-/* XXX needs documentation */
-struct ast_callid;
/*!
* \brief factory function to create a new uniquely identifying callid.
Modified: team/jrose/call_identifiers/main/logger.c
URL: http://svnview.digium.com/svn/asterisk/team/jrose/call_identifiers/main/logger.c?view=diff&rev=359941&r1=359940&r2=359941
==============================================================================
--- team/jrose/call_identifiers/main/logger.c (original)
+++ team/jrose/call_identifiers/main/logger.c Mon Mar 19 13:14:44 2012
@@ -1244,7 +1244,7 @@
using = ast_atomic_fetchadd_int(&next_unique_callid, +1);
call->call_identifier = using;
- ast_log(LOG_DEBUG, "CALL_ID [C%d] created by thread.\n", call->call_identifier);
+ ast_log(LOG_DEBUG, "CALL_ID [C%06d] created by thread.\n", call->call_identifier);
return call;
}
@@ -1260,7 +1260,7 @@
if (!(*pointing)) {
ast_callid_ref(callid);
*pointing = callid;
- ast_log(LOG_DEBUG, "CALL_ID [C%d] bound to thread.\n", callid->call_identifier);
+ ast_log(LOG_DEBUG, "CALL_ID [C%06d] bound to thread.\n", callid->call_identifier);
/* callid will be unreffed at thread destruction */
} else {
ast_log(LOG_WARNING, "Attempted to ast_callid_threadassoc_add on thread already associated with a callid.\n");
@@ -1288,15 +1288,13 @@
/*!
* \brief send log messages to syslog and/or the console
*/
-void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
+static void __attribute__((format(printf, 6, 0))) ast_log_full(int level, const char *file, int line, const char *function, struct ast_callid *callid, const char *fmt, va_list ap)
{
struct logmsg *logmsg = NULL;
struct ast_str *buf = NULL;
struct ast_tm tm;
struct timeval now = ast_tvnow();
- struct ast_callid **callid;
int res = 0;
- va_list ap;
char datestring[256];
if (!(buf = ast_str_thread_get(&log_buf, LOG_BUF_INIT_SIZE)))
@@ -1308,9 +1306,7 @@
* so just log to stdout
*/
int result;
- va_start(ap, fmt);
result = ast_str_set_va(&buf, BUFSIZ, fmt, ap); /* XXX BUFSIZ ? */
- va_end(ap);
if (result != AST_DYNSTR_BUILD_FAILED) {
term_filter_escapes(ast_str_buffer(buf));
fputs(ast_str_buffer(buf), stdout);
@@ -1323,9 +1319,7 @@
return;
/* Build string */
- va_start(ap, fmt);
res = ast_str_set_va(&buf, BUFSIZ, fmt, ap);
- va_end(ap);
/* If the build failed, then abort and free this structure */
if (res == AST_DYNSTR_BUILD_FAILED)
@@ -1345,11 +1339,9 @@
logmsg->type = LOGMSG_NORMAL;
}
- callid = ast_threadstorage_get(&unique_callid, sizeof(struct ast_callid **));
-
- if (callid && *callid) {
- ast_callid_ref(*callid);
- logmsg->callid = (*callid);
+ if (callid) {
+ ast_callid_ref(callid);
+ logmsg->callid = (callid);
/* callid will be unreffed at logmsg destruction */
}
@@ -1378,6 +1370,32 @@
}
return;
+}
+
+void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
+{
+ struct ast_callid **callid;
+ va_list ap;
+
+ callid = ast_threadstorage_get(&unique_callid, sizeof(struct ast_callid **));
+
+ if (callid && *callid) {
+ va_start(ap, fmt);
+ ast_log_full(level, file, line, function, *callid, fmt, ap);
+ return;
+ }
+
+ va_start(ap, fmt);
+ ast_log_full(level, file, line, function, NULL, fmt, ap);
+ va_end(ap);
+}
+
+void ast_log_callid(int level, const char *file, int line, const char *function, struct ast_callid *callid, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ ast_log_full(level, file, line, function, callid, fmt, ap);
+ va_end(ap);
}
#ifdef HAVE_BKTR
More information about the asterisk-commits
mailing list