clang-tools  7.0.0
Logger.cpp
Go to the documentation of this file.
1 //===--- Logger.cpp - Logger interface for clangd -------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "Logger.h"
11 #include "llvm/Support/raw_ostream.h"
12 #include <mutex>
13 
14 namespace clang {
15 namespace clangd {
16 
17 namespace {
18 Logger *L = nullptr;
19 } // namespace
20 
22  assert(!L);
23  L = &Instance;
24 }
25 
27 
29  const llvm::formatv_object_base &Message) {
30  if (L)
31  L->log(Level, Message);
32  else {
33  static std::mutex Mu;
34  std::lock_guard<std::mutex> Guard(Mu);
35  llvm::errs() << Message << "\n";
36  }
37 }
38 
39 const char *detail::debugType(const char *Filename) {
40  if (const char *Slash = strrchr(Filename, '/'))
41  return Slash + 1;
42  if (const char *Backslash = strrchr(Filename, '\\'))
43  return Backslash + 1;
44  return Filename;
45 }
46 
47 } // namespace clangd
48 } // namespace clang
void log(Logger::Level, const llvm::formatv_object_base &)
Definition: Logger.cpp:28
const char * debugType(const char *Filename)
Definition: Logger.cpp:39
std::string Filename
Filename as a string.
Interface to allow custom logging in clangd.
Definition: Logger.h:23
LoggingSession(clangd::Logger &Instance)
Definition: Logger.cpp:21
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//