[clang-tools-extra] fb22678 - [clangd] Use elog instead of llvm::errs, log instead of llvm::outs
Kirill Bobyrev via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 28 16:48:36 PDT 2020
Author: Kirill Bobyrev
Date: 2020-07-29T01:48:24+02:00
New Revision: fb22678cd67801e41af4917acceb4014ab5d007e
URL: https://github.com/llvm/llvm-project/commit/fb22678cd67801e41af4917acceb4014ab5d007e
DIFF: https://github.com/llvm/llvm-project/commit/fb22678cd67801e41af4917acceb4014ab5d007e.diff
LOG: [clangd] Use elog instead of llvm::errs, log instead of llvm::outs
Reviewed By: sammccall
Differential Revision: https://reviews.llvm.org/D84697
Added:
Modified:
clang-tools-extra/clangd/index/remote/server/Server.cpp
clang-tools-extra/clangd/indexer/IndexerMain.cpp
clang-tools-extra/clangd/tool/ClangdMain.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/index/remote/server/Server.cpp b/clang-tools-extra/clangd/index/remote/server/Server.cpp
index 364e4db6503c..c3f9efeb7ec0 100644
--- a/clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ b/clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -39,6 +39,15 @@ llvm::cl::opt<std::string> IndexPath(llvm::cl::desc("<INDEX FILE>"),
llvm::cl::opt<std::string> IndexRoot(llvm::cl::desc("<PROJECT ROOT>"),
llvm::cl::Positional, llvm::cl::Required);
+llvm::cl::opt<Logger::Level> LogLevel{
+ "log",
+ llvm::cl::desc("Verbosity of log messages written to stderr"),
+ values(clEnumValN(Logger::Error, "error", "Error messages only"),
+ clEnumValN(Logger::Info, "info", "High level execution tracing"),
+ clEnumValN(Logger::Debug, "verbose", "Low level details")),
+ llvm::cl::init(Logger::Info),
+};
+
llvm::cl::opt<std::string> TraceFile(
"trace-file",
llvm::cl::desc("Path to the file where tracer logs will be stored"));
@@ -173,7 +182,7 @@ void runServer(std::unique_ptr<clangd::SymbolIndex> Index,
Builder.AddListeningPort(ServerAddress, grpc::InsecureServerCredentials());
Builder.RegisterService(&Service);
std::unique_ptr<grpc::Server> Server(Builder.BuildAndStart());
- llvm::outs() << "Server listening on " << ServerAddress << '\n';
+ log("Server listening on {0}", ServerAddress);
Server->Wait();
}
@@ -191,10 +200,16 @@ int main(int argc, char *argv[]) {
llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
if (!llvm::sys::path::is_absolute(IndexRoot)) {
- elog("Index root should be an absolute path.");
+ llvm::errs() << "Index root should be an absolute path.\n";
return -1;
}
+ llvm::errs().SetBuffered();
+ // Don't flush stdout when logging for thread safety.
+ llvm::errs().tie(nullptr);
+ clang::clangd::StreamLogger Logger(llvm::errs(), LogLevel);
+ clang::clangd::LoggingSession LoggingSession(Logger);
+
llvm::Optional<llvm::raw_fd_ostream> TracerStream;
std::unique_ptr<clang::clangd::trace::EventTracer> Tracer;
if (!TraceFile.empty()) {
@@ -220,7 +235,7 @@ int main(int argc, char *argv[]) {
std::unique_ptr<clang::clangd::SymbolIndex> Index = openIndex(IndexPath);
if (!Index) {
- elog("Failed to open the index.");
+ llvm::errs() << "Failed to open the index.\n";
return -1;
}
diff --git a/clang-tools-extra/clangd/indexer/IndexerMain.cpp b/clang-tools-extra/clangd/indexer/IndexerMain.cpp
index dac038308d9e..46224238c3fc 100644
--- a/clang-tools-extra/clangd/indexer/IndexerMain.cpp
+++ b/clang-tools-extra/clangd/indexer/IndexerMain.cpp
@@ -16,6 +16,7 @@
#include "index/Serialization.h"
#include "index/Symbol.h"
#include "index/SymbolCollector.h"
+#include "support/Logger.h"
#include "clang/Tooling/ArgumentsAdjusters.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Execution.h"
@@ -122,7 +123,7 @@ int main(int argc, const char **argv) {
std::make_unique<clang::clangd::IndexActionFactory>(Data),
clang::tooling::getStripPluginsAdjuster());
if (Err) {
- llvm::errs() << llvm::toString(std::move(Err)) << "\n";
+ clang::clangd::elog("{0}", std::move(Err));
}
// Emit collected data.
diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp
index 0d4267774c92..daf87d11c384 100644
--- a/clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -657,16 +657,16 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
// continuing.
llvm::SmallString<128> Path(CompileCommandsDir);
if (std::error_code EC = llvm::sys::fs::make_absolute(Path)) {
- llvm::errs() << "Error while converting the relative path specified by "
- "--compile-commands-dir to an absolute path: "
- << EC.message() << ". The argument will be ignored.\n";
+ elog("Error while converting the relative path specified by "
+ "--compile-commands-dir to an absolute path: {0}. The argument "
+ "will be ignored.",
+ EC.message());
} else {
CompileCommandsDirPath = std::string(Path.str());
}
} else {
- llvm::errs()
- << "Path specified by --compile-commands-dir does not exist. The "
- "argument will be ignored.\n";
+ elog("Path specified by --compile-commands-dir does not exist. The "
+ "argument will be ignored.");
}
}
@@ -750,7 +750,7 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
elog("Couldn't determine user config file, not loading");
}
std::vector<const config::Provider *> ProviderPointers;
- for (const auto& P : ProviderStack)
+ for (const auto &P : ProviderStack)
ProviderPointers.push_back(P.get());
Config = config::Provider::combine(std::move(ProviderPointers));
Opts.ConfigProvider = Config.get();
More information about the cfe-commits
mailing list