From 1d169c6229a469de486afee49496f230640612d0 Mon Sep 17 00:00:00 2001 From: Sam McCall Date: Wed, 11 Jul 2018 10:35:11 +0000 Subject: [clangd] Upgrade logging facilities with levels and formatv. Summary: log() is split into four functions: - elog()/log()/vlog() have different severity levels, allowing filtering - dlog() is a lazy macro which uses LLVM_DEBUG - it logs to the logger, but conditionally based on -debug-only flag and is omitted in release builds All logging functions use formatv-style format strings now, e.g: log("Could not resolve URI {0}: {1}", URI, Result.takeError()); Existing log sites have been split between elog/log/vlog by best guess. This includes a workaround for passing Error to formatv that can be simplified when D49170 or similar lands. Subscribers: ilya-biryukov, javed.absar, ioeric, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D49008 --- clang-tools-extra/clangd/ClangdUnit.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'clang-tools-extra/clangd/ClangdUnit.cpp') diff --git a/clang-tools-extra/clangd/ClangdUnit.cpp b/clang-tools-extra/clangd/ClangdUnit.cpp index d91be1ee700..a5ab4839cca 100644 --- a/clang-tools-extra/clangd/ClangdUnit.cpp +++ b/clang-tools-extra/clangd/ClangdUnit.cpp @@ -147,7 +147,7 @@ ParsedAST::Build(std::unique_ptr CI, auto Action = llvm::make_unique(); const FrontendInputFile &MainInput = Clang->getFrontendOpts().Inputs[0]; if (!Action->BeginSourceFile(*Clang, MainInput)) { - log("BeginSourceFile() failed when building AST for " + + log("BeginSourceFile() failed when building AST for {0}", MainInput.getFile()); return llvm::None; } @@ -159,7 +159,7 @@ ParsedAST::Build(std::unique_ptr CI, collectIncludeStructureCallback(Clang->getSourceManager(), &Includes)); if (!Action->Execute()) - log("Execute() failed when building AST for " + MainInput.getFile()); + log("Execute() failed when building AST for {0}", MainInput.getFile()); // UnitDiagsConsumer is local, we can not store it in CompilerInstance that // has a longer lifetime. @@ -307,11 +307,11 @@ std::shared_ptr clangd::buildPreamble( compileCommandsAreEqual(Inputs.CompileCommand, OldCompileCommand) && OldPreamble->Preamble.CanReuse(CI, ContentsBuffer.get(), Bounds, Inputs.FS.get())) { - log("Reusing preamble for file " + Twine(FileName)); + vlog("Reusing preamble for file {0}", Twine(FileName)); return OldPreamble; } - log("Preamble for file " + Twine(FileName) + - " cannot be reused. Attempting to rebuild it."); + vlog("Preamble for file {0} cannot be reused. Attempting to rebuild it.", + FileName); trace::Span Tracer("BuildPreamble"); SPAN_ATTACH(Tracer, "File", FileName); @@ -343,13 +343,13 @@ std::shared_ptr clangd::buildPreamble( CI.getFrontendOpts().SkipFunctionBodies = false; if (BuiltPreamble) { - log("Built preamble of size " + Twine(BuiltPreamble->getSize()) + - " for file " + Twine(FileName)); + vlog("Built preamble of size {0} for file {1}", BuiltPreamble->getSize(), + FileName); return std::make_shared( std::move(*BuiltPreamble), PreambleDiagnostics.take(), SerializedDeclsCollector.takeIncludes()); } else { - log("Could not build a preamble for file " + Twine(FileName)); + elog("Could not build a preamble for file {0}", FileName); return nullptr; } } @@ -379,7 +379,7 @@ SourceLocation clangd::getBeginningOfIdentifier(ParsedAST &Unit, const SourceManager &SourceMgr = AST.getSourceManager(); auto Offset = positionToOffset(SourceMgr.getBufferData(FID), Pos); if (!Offset) { - log("getBeginningOfIdentifier: " + toString(Offset.takeError())); + log("getBeginningOfIdentifier: {0}", Offset.takeError()); return SourceLocation(); } SourceLocation InputLoc = SourceMgr.getComposedLoc(FID, *Offset); -- cgit v1.2.3