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"));
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();
}
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()) {
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;
}
#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"
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.
// 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.");
}
}
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();