[clang-tools-extra] r325357 - [clangd] Include timestamps in log messages.

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 16 08:41:42 PST 2018


Author: sammccall
Date: Fri Feb 16 08:41:42 2018
New Revision: 325357

URL: http://llvm.org/viewvc/llvm-project?rev=325357&view=rev
Log:
[clangd] Include timestamps in log messages.

Modified:
    clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp

Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp?rev=325357&r1=325356&r2=325357&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp (original)
+++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp Fri Feb 16 08:41:42 2018
@@ -13,6 +13,7 @@
 #include "Trace.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Chrono.h"
 #include "llvm/Support/SourceMgr.h"
 #include <istream>
 
@@ -60,20 +61,19 @@ void JSONOutput::writeMessage(const json
     OS << Message;
   OS.flush();
 
-  std::lock_guard<std::mutex> Guard(StreamMutex);
-  // Log without headers.
-  Logs << "--> " << S << '\n';
-  Logs.flush();
-
-  // Emit message with header.
-  Outs << "Content-Length: " << S.size() << "\r\n\r\n" << S;
-  Outs.flush();
+  {
+    std::lock_guard<std::mutex> Guard(StreamMutex);
+    Outs << "Content-Length: " << S.size() << "\r\n\r\n" << S;
+    Outs.flush();
+  }
+  log(llvm::Twine("--> ") + S);
 }
 
 void JSONOutput::log(const Twine &Message) {
+  llvm::sys::TimePoint<> Timestamp = std::chrono::system_clock::now();
   trace::log(Message);
   std::lock_guard<std::mutex> Guard(StreamMutex);
-  Logs << Message << '\n';
+  Logs << llvm::formatv("[{0:%H:%M:%S.%L}] {1}\n", Timestamp, Message);
   Logs.flush();
 }
 




More information about the cfe-commits mailing list