Skip to content

Commit

Permalink
[clangd] Use elog instead of llvm::errs, log instead of llvm::outs
Browse files Browse the repository at this point in the history
Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D84697
  • Loading branch information
kirillbobyrev committed Jul 28, 2020
1 parent 462b356 commit fb22678
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
21 changes: 18 additions & 3 deletions clang-tools-extra/clangd/index/remote/server/Server.cpp
Expand Up @@ -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"));
Expand Down Expand Up @@ -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();
}
Expand All @@ -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()) {
Expand All @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion clang-tools-extra/clangd/indexer/IndexerMain.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 7 additions & 7 deletions clang-tools-extra/clangd/tool/ClangdMain.cpp
Expand Up @@ -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.");
}
}

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit fb22678

Please sign in to comment.