You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2015/11/04 06:30:54 UTC
trafficserver git commit: diags: clean up duplicated printing code
Repository: trafficserver
Updated Branches:
refs/heads/master 32dafee02 -> 40f572dad
diags: clean up duplicated printing code
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/40f572da
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/40f572da
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/40f572da
Branch: refs/heads/master
Commit: 40f572dad5597c064c6758657f0d32f160d3dd7f
Parents: 32dafee
Author: James Peach <jp...@apache.org>
Authored: Tue Nov 3 21:30:24 2015 -0800
Committer: James Peach <jp...@apache.org>
Committed: Tue Nov 3 21:30:24 2015 -0800
----------------------------------------------------------------------
lib/ts/Diags.cc | 57 +++++++++++++++++++++++-----------------------------
1 file changed, 25 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/40f572da/lib/ts/Diags.cc
----------------------------------------------------------------------
diff --git a/lib/ts/Diags.cc b/lib/ts/Diags.cc
index 61fc1c7..be65572 100644
--- a/lib/ts/Diags.cc
+++ b/lib/ts/Diags.cc
@@ -41,6 +41,7 @@
#include "ts/ink_assert.h"
#include "ts/ink_time.h"
#include "ts/ink_hrtime.h"
+#include "ts/ink_thread.h"
#include "ts/Diags.h"
int diags_on_for_plugins = 0;
@@ -49,6 +50,18 @@ bool DiagsConfigState::enabled[2] = {false, false};
// Global, used for all diagnostics
inkcoreapi Diags *diags = NULL;
+template<unsigned Size> static void
+vprintline(FILE * fp, char (&buffer)[Size], va_list ap)
+{
+ int nbytes;
+
+ nbytes = vfprintf(fp, buffer, ap);
+ if (nbytes > 0 && buffer[nbytes - 1] != '\n') {
+ ink_assert(nbytes < Size);
+ putc('\n', fp);
+ }
+}
+
//////////////////////////////////////////////////////////////////////////////
//
// char *SrcLoc::str(char *buf, int buflen)
@@ -240,8 +253,7 @@ Diags::print_va(const char *debug_tag, DiagsLevel diags_level, const SrcLoc *loc
*end_of_format = NUL;
// add the thread id
- pthread_t id = pthread_self();
- end_of_format += snprintf(end_of_format, sizeof(format_buf), "{0x%" PRIx64 "} ", (uint64_t)id);
+ end_of_format += snprintf(end_of_format, sizeof(format_buf), "{0x%" PRIx64 "} ", (uint64_t)ink_thread_self());
//////////////////////////////////////
// start with the diag level prefix //
@@ -316,46 +328,25 @@ Diags::print_va(const char *debug_tag, DiagsLevel diags_level, const SrcLoc *loc
lock();
if (config.outputs[diags_level].to_diagslog) {
if (diags_log && diags_log->m_fp) {
- va_list ap_scratch;
- va_copy(ap_scratch, ap);
- buffer = format_buf_w_ts;
- vfprintf(diags_log->m_fp, buffer, ap_scratch);
- {
- int len = strlen(buffer);
- if (len > 0 && buffer[len - 1] != '\n') {
- putc('\n', diags_log->m_fp);
- }
- }
+ va_list tmp;
+ va_copy(tmp, ap);
+ vprintline(diags_log->m_fp, format_buf_w_ts, tmp);
}
}
if (config.outputs[diags_level].to_stdout) {
if (stdout_log && stdout_log->m_fp) {
- va_list ap_scratch;
- va_copy(ap_scratch, ap);
- buffer = format_buf_w_ts;
- vfprintf(stdout_log->m_fp, buffer, ap_scratch);
- {
- int len = strlen(buffer);
- if (len > 0 && buffer[len - 1] != '\n') {
- putc('\n', stdout_log->m_fp);
- }
- }
+ va_list tmp;
+ va_copy(tmp, ap);
+ vprintline(stdout_log->m_fp, format_buf_w_ts, tmp);
}
}
if (config.outputs[diags_level].to_stderr) {
if (stderr_log && stderr_log->m_fp) {
- va_list ap_scratch;
- va_copy(ap_scratch, ap);
- buffer = format_buf_w_ts;
- vfprintf(stderr_log->m_fp, buffer, ap_scratch);
- {
- int len = strlen(buffer);
- if (len > 0 && buffer[len - 1] != '\n') {
- putc('\n', stderr_log->m_fp);
- }
- }
+ va_list tmp;
+ va_copy(tmp, ap);
+ vprintline(stderr_log->m_fp, format_buf_w_ts, tmp);
}
}
@@ -401,9 +392,11 @@ Diags::print_va(const char *debug_tag, DiagsLevel diags_level, const SrcLoc *loc
vsnprintf(syslog_buffer, sizeof(syslog_buffer) - 1, format_buf, ap);
syslog(priority, "%s", syslog_buffer);
}
+
#if defined(freebsd)
unlock();
#endif
+
}