[clang-tools-extra] r344675 - [clangd] Rename and move trivial logger to Logger.cpp. NFC

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 17 00:39:32 PDT 2018


Author: sammccall
Date: Wed Oct 17 00:39:32 2018
New Revision: 344675

URL: http://llvm.org/viewvc/llvm-project?rev=344675&view=rev
Log:
[clangd] Rename and move trivial logger to Logger.cpp. NFC

Modified:
    clang-tools-extra/trunk/clangd/ClangdLSPServer.h
    clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
    clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h
    clang-tools-extra/trunk/clangd/Logger.cpp
    clang-tools-extra/trunk/clangd/Logger.h
    clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=344675&r1=344674&r2=344675&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Wed Oct 17 00:39:32 2018
@@ -24,7 +24,6 @@
 namespace clang {
 namespace clangd {
 
-class JSONOutput;
 class SymbolIndex;
 
 /// This class exposes ClangdServer's capabilities via Language Server Protocol.

Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp?rev=344675&r1=344674&r2=344675&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp (original)
+++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp Wed Oct 17 00:39:32 2018
@@ -15,9 +15,7 @@
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
-#include "llvm/Support/Chrono.h"
 #include "llvm/Support/Errno.h"
-#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/SourceMgr.h"
@@ -59,18 +57,6 @@ public:
 Key<std::unique_ptr<RequestSpan>> RequestSpan::RSKey;
 } // namespace
 
-void JSONOutput::log(Logger::Level Level,
-                     const llvm::formatv_object_base &Message) {
-  if (Level < MinLevel)
-    return;
-  llvm::sys::TimePoint<> Timestamp = std::chrono::system_clock::now();
-  trace::log(Message);
-  std::lock_guard<std::mutex> Guard(StreamMutex);
-  Logs << llvm::formatv("{0}[{1:%H:%M:%S.%L}] {2}\n", indicator(Level),
-                        Timestamp, Message);
-  Logs.flush();
-}
-
 void clangd::reply(json::Value &&Result) {
   auto ID = getRequestId();
   if (!ID) {

Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h?rev=344675&r1=344674&r2=344675&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h (original)
+++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h Wed Oct 17 00:39:32 2018
@@ -25,23 +25,6 @@
 namespace clang {
 namespace clangd {
 
-// Logs to an output stream, such as stderr.
-// FIXME: Rename to StreamLogger or such, and move to Logger.h.
-class JSONOutput : public Logger {
-public:
-  JSONOutput(llvm::raw_ostream &Logs, Logger::Level MinLevel)
-      : MinLevel(MinLevel), Logs(Logs) {}
-
-  /// Write a line to the logging stream.
-  void log(Level, const llvm::formatv_object_base &Message) override;
-
-private:
-  Logger::Level MinLevel;
-  llvm::raw_ostream &Logs;
-
-  std::mutex StreamMutex;
-};
-
 /// Sends a successful reply.
 /// Current context must derive from JSONRPCDispatcher::Handler.
 void reply(llvm::json::Value &&Result);

Modified: clang-tools-extra/trunk/clangd/Logger.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Logger.cpp?rev=344675&r1=344674&r2=344675&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/Logger.cpp (original)
+++ clang-tools-extra/trunk/clangd/Logger.cpp Wed Oct 17 00:39:32 2018
@@ -8,6 +8,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "Logger.h"
+#include "Trace.h"
+#include "llvm/Support/Chrono.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/raw_ostream.h"
 #include <mutex>
 
@@ -44,5 +47,17 @@ const char *detail::debugType(const char
   return Filename;
 }
 
+void StreamLogger::log(Logger::Level Level,
+                       const llvm::formatv_object_base &Message) {
+  if (Level < MinLevel)
+    return;
+  llvm::sys::TimePoint<> Timestamp = std::chrono::system_clock::now();
+  trace::log(Message);
+  std::lock_guard<std::mutex> Guard(StreamMutex);
+  Logs << llvm::formatv("{0}[{1:%H:%M:%S.%L}] {2}\n", indicator(Level),
+                        Timestamp, Message);
+  Logs.flush();
+}
+
 } // namespace clangd
 } // namespace clang

Modified: clang-tools-extra/trunk/clangd/Logger.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Logger.h?rev=344675&r1=344674&r2=344675&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/Logger.h (original)
+++ clang-tools-extra/trunk/clangd/Logger.h Wed Oct 17 00:39:32 2018
@@ -15,6 +15,7 @@
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FormatAdapters.h"
 #include "llvm/Support/FormatVariadic.h"
+#include <mutex>
 
 namespace clang {
 namespace clangd {
@@ -86,6 +87,22 @@ public:
   LoggingSession &operator=(LoggingSession const &) = delete;
 };
 
+// Logs to an output stream, such as stderr.
+class StreamLogger : public Logger {
+public:
+  StreamLogger(llvm::raw_ostream &Logs, Logger::Level MinLevel)
+      : MinLevel(MinLevel), Logs(Logs) {}
+
+  /// Write a line to the logging stream.
+  void log(Level, const llvm::formatv_object_base &Message) override;
+
+private:
+  Logger::Level MinLevel;
+  llvm::raw_ostream &Logs;
+
+  std::mutex StreamMutex;
+};
+
 } // namespace clangd
 } // namespace clang
 

Modified: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp?rev=344675&r1=344674&r2=344675&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp (original)
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Wed Oct 17 00:39:32 2018
@@ -253,7 +253,7 @@ int main(int argc, char *argv[]) {
   // Use buffered stream to stderr (we still flush each log message). Unbuffered
   // stream can cause significant (non-deterministic) latency for the logger.
   llvm::errs().SetBuffered();
-  JSONOutput Logger(llvm::errs(), LogLevel);
+  StreamLogger Logger(llvm::errs(), LogLevel);
   clangd::LoggingSession LoggingSession(Logger);
 
   // If --compile-commands-dir arg was invoked, check value and override default




More information about the cfe-commits mailing list