diff options
author | Sam McCall <sam.mccall@gmail.com> | 2018-01-18 10:24:01 +0000 |
---|---|---|
committer | Sam McCall <sam.mccall@gmail.com> | 2018-01-18 10:24:01 +0000 |
commit | 2082fe156d5e4b4f6e1fff182bbee0a183d54c71 (patch) | |
tree | 2227c90c6bae19c1d7eabc5e44676efd6fb7bdaf | |
parent | 9c3be3a4e58a70f9f625ec535d6552fe699d4b29 (diff) | |
download | bcm5719-llvm-2082fe156d5e4b4f6e1fff182bbee0a183d54c71.tar.gz bcm5719-llvm-2082fe156d5e4b4f6e1fff182bbee0a183d54c71.zip |
[clangd] Output log messages to stderr when not configured (e.g. in tests). NFC
llvm-svn: 322827
-rw-r--r-- | clang-tools-extra/clangd/Logger.cpp | 12 | ||||
-rw-r--r-- | clang-tools-extra/clangd/Logger.h | 5 |
2 files changed, 12 insertions, 5 deletions
diff --git a/clang-tools-extra/clangd/Logger.cpp b/clang-tools-extra/clangd/Logger.cpp index 2c0c6f9974a..40a90504de2 100644 --- a/clang-tools-extra/clangd/Logger.cpp +++ b/clang-tools-extra/clangd/Logger.cpp @@ -8,6 +8,8 @@ //===----------------------------------------------------------------------===// #include "Logger.h" +#include "llvm/Support/raw_ostream.h" +#include <mutex> namespace clang { namespace clangd { @@ -24,9 +26,13 @@ LoggingSession::LoggingSession(clangd::Logger &Instance) { LoggingSession::~LoggingSession() { L = nullptr; } void log(const Context &Ctx, const llvm::Twine &Message) { - if (!L) - return; - L->log(Ctx, Message); + if (L) + L->log(Ctx, Message); + else { + static std::mutex Mu; + std::lock_guard<std::mutex> Guard(Mu); + llvm::errs() << Message << "\n"; + } } } // namespace clangd diff --git a/clang-tools-extra/clangd/Logger.h b/clang-tools-extra/clangd/Logger.h index c856162b4b5..b6d7a1b4caf 100644 --- a/clang-tools-extra/clangd/Logger.h +++ b/clang-tools-extra/clangd/Logger.h @@ -16,8 +16,9 @@ namespace clang { namespace clangd { -/// Main logging function. Logs messages to a global logger, which can be set up -/// by LoggingSesssion. +/// Main logging function. +/// 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 Context &Ctx, const llvm::Twine &Message); /// Interface to allow custom logging in clangd. |