diff options
author | Sam McCall <sam.mccall@gmail.com> | 2018-07-11 10:35:11 +0000 |
---|---|---|
committer | Sam McCall <sam.mccall@gmail.com> | 2018-07-11 10:35:11 +0000 |
commit | 1d169c6229a469de486afee49496f230640612d0 (patch) | |
tree | 09f3f4a66ea3932c72f057cf720a089ad255d51e /clang-tools-extra/clangd/ClangdUnit.cpp | |
parent | 5107256dba82b5adba078896308c02d289557bd9 (diff) |
[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
Diffstat (limited to 'clang-tools-extra/clangd/ClangdUnit.cpp')
-rw-r--r-- | clang-tools-extra/clangd/ClangdUnit.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
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<clang::CompilerInvocation> CI, auto Action = llvm::make_unique<ClangdFrontendAction>(); 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<clang::CompilerInvocation> 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<const PreambleData> 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<const PreambleData> 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<PreambleData>( 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); |