diff options
| -rw-r--r-- | clang-tools-extra/clangd/JSONRPCDispatcher.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/clang-tools-extra/clangd/JSONRPCDispatcher.cpp b/clang-tools-extra/clangd/JSONRPCDispatcher.cpp index b15f7d81183..3e40dcc92b5 100644 --- a/clang-tools-extra/clangd/JSONRPCDispatcher.cpp +++ b/clang-tools-extra/clangd/JSONRPCDispatcher.cpp @@ -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::Expr &Message) { 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(); } |

