simark updated this revision to Diff 137573.
simark added a comment.

Update

- Change switch to -verbose
- Add vlog function, do the filtering there


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44226

Files:
  clangd/JSONRPCDispatcher.cpp
  clangd/Logger.cpp
  clangd/Logger.h
  clangd/tool/ClangdMain.cpp

Index: clangd/tool/ClangdMain.cpp
===================================================================
--- clangd/tool/ClangdMain.cpp
+++ clangd/tool/ClangdMain.cpp
@@ -76,6 +76,9 @@
                    "messages delimited by --- lines, with # comment support")),
     llvm::cl::init(JSONStreamStyle::Standard));
 
+static llvm::cl::opt<bool> Verbose("verbose", llvm::cl::desc("Be more verbose"),
+                                   llvm::cl::init(false));
+
 static llvm::cl::opt<bool>
     PrettyPrint("pretty", llvm::cl::desc("Pretty-print JSON output"),
                 llvm::cl::init(false));
@@ -192,7 +195,7 @@
                  InputMirrorStream ? InputMirrorStream.getPointer() : nullptr,
                  PrettyPrint);
 
-  clangd::LoggingSession LoggingSession(Out);
+  clangd::LoggingSession LoggingSession(Out, Verbose);
 
   // If --compile-commands-dir arg was invoked, check value and override default
   // path.
Index: clangd/Logger.h
===================================================================
--- clangd/Logger.h
+++ clangd/Logger.h
@@ -15,11 +15,14 @@
 namespace clang {
 namespace clangd {
 
-/// Main logging function.
+/// Main logging functions.
 /// Logs messages to a global logger, which can be set up by LoggingSesssion.
 /// If no logger is registered, writes to llvm::errs().
 void log(const llvm::Twine &Message);
 
+/// Same as the above, but for verbose messages.
+void vlog(const llvm::Twine &Message);
+
 /// Interface to allow custom logging in clangd.
 class Logger {
 public:
@@ -32,7 +35,7 @@
 /// Only one LoggingSession can be active at a time.
 class LoggingSession {
 public:
-  LoggingSession(clangd::Logger &Instance);
+  LoggingSession(clangd::Logger &Instance, bool Verbose);
   ~LoggingSession();
 
   LoggingSession(LoggingSession &&) = delete;
Index: clangd/Logger.cpp
===================================================================
--- clangd/Logger.cpp
+++ clangd/Logger.cpp
@@ -16,11 +16,13 @@
 
 namespace {
 Logger *L = nullptr;
+bool Verbose_ = false;
 } // namespace
 
-LoggingSession::LoggingSession(clangd::Logger &Instance) {
+LoggingSession::LoggingSession(clangd::Logger &Instance, bool Verbose) {
   assert(!L);
   L = &Instance;
+  Verbose_ = Verbose;
 }
 
 LoggingSession::~LoggingSession() { L = nullptr; }
@@ -35,5 +37,10 @@
   }
 }
 
+void vlog(const llvm::Twine &Message) {
+  if (Verbose_)
+    log(Message);
+}
+
 } // namespace clangd
 } // namespace clang
Index: clangd/JSONRPCDispatcher.cpp
===================================================================
--- clangd/JSONRPCDispatcher.cpp
+++ clangd/JSONRPCDispatcher.cpp
@@ -66,7 +66,7 @@
     Outs << "Content-Length: " << S.size() << "\r\n\r\n" << S;
     Outs.flush();
   }
-  log(llvm::Twine("--> ") + S);
+  vlog(llvm::Twine("--> ") + S);
 }
 
 void JSONOutput::log(const Twine &Message) {
@@ -306,7 +306,7 @@
     if (auto JSON = ReadMessage(In, Out)) {
       if (auto Doc = json::parse(*JSON)) {
         // Log the formatted message.
-        log(llvm::formatv(Out.Pretty ? "<-- {0:2}\n" : "<-- {0}\n", *Doc));
+        vlog(llvm::formatv(Out.Pretty ? "<-- {0:2}\n" : "<-- {0}\n", *Doc));
         // Finally, execute the action for this JSON message.
         if (!Dispatcher.call(*Doc, Out))
           log("JSON dispatch failed!\n");
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to