diff options
| -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. |

