trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject [trafficserver] branch master updated: BWF: Change timestamp global name to be consistent with logging time stamps.
Date Thu, 06 Dec 2018 22:25:34 GMT
This is an automated email from the ASF dual-hosted git repository.

amc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new c4619bb  BWF: Change timestamp global name to be consistent with logging time stamps.
c4619bb is described below

commit c4619bba50fa3dd3c48bbbc69f8d3a242e1ba39e
Author: Alan M. Carroll <amc@apache.org>
AuthorDate: Wed Nov 14 16:10:27 2018 -0600

    BWF: Change timestamp global name to be consistent with logging time stamps.
---
 src/tscore/BufferWriterFormat.cc | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/tscore/BufferWriterFormat.cc b/src/tscore/BufferWriterFormat.cc
index e3bf9a7..7efd5e0 100644
--- a/src/tscore/BufferWriterFormat.cc
+++ b/src/tscore/BufferWriterFormat.cc
@@ -965,12 +965,14 @@ namespace
 void
 BWF_Timestamp(ts::BufferWriter &w, ts::BWFSpec const &spec)
 {
-  // Unfortunately need to write to a temporary buffer or the sizing isn't correct if @a
w is clipped
-  // because @c strftime returns 0 if the buffer isn't large enough.
-  char buff[32];
-  std::time_t t = std::time(nullptr);
-  auto n        = strftime(buff, sizeof(buff), "%Y %b %d %H:%M:%S", std::localtime(&t));
-  w.write(buff, n);
+  auto now   = std::chrono::system_clock::now();
+  auto epoch = std::chrono::system_clock::to_time_t(now);
+  ts::LocalBufferWriter<48> lw;
+
+  ctime_r(&epoch, lw.auxBuffer());
+  lw.fill(19); // clip trailing stuff, do not want.
+  lw.print(".{:03}", std::chrono::time_point_cast<std::chrono::milliseconds>(now).time_since_epoch().count()
% 1000);
+  w.write(lw.view().substr(4));
 }
 
 void


Mime
View raw message