2017-09-20 15:24:15 +08:00
|
|
|
//===--- Logger.cpp - Logger interface for clangd -------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "Logger.h"
|
2018-01-18 18:24:01 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <mutex>
|
2017-09-20 15:24:15 +08:00
|
|
|
|
2017-12-13 20:51:22 +08:00
|
|
|
namespace clang {
|
|
|
|
namespace clangd {
|
2017-09-20 15:24:15 +08:00
|
|
|
|
2017-12-13 20:51:22 +08:00
|
|
|
namespace {
|
|
|
|
Logger *L = nullptr;
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
LoggingSession::LoggingSession(clangd::Logger &Instance) {
|
|
|
|
assert(!L);
|
|
|
|
L = &Instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
LoggingSession::~LoggingSession() { L = nullptr; }
|
|
|
|
|
[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
llvm-svn: 336785
2018-07-11 18:35:11 +08:00
|
|
|
void detail::log(Logger::Level Level,
|
|
|
|
const llvm::formatv_object_base &Message) {
|
2018-01-18 18:24:01 +08:00
|
|
|
if (L)
|
[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
llvm-svn: 336785
2018-07-11 18:35:11 +08:00
|
|
|
L->log(Level, Message);
|
2018-01-18 18:24:01 +08:00
|
|
|
else {
|
|
|
|
static std::mutex Mu;
|
|
|
|
std::lock_guard<std::mutex> Guard(Mu);
|
|
|
|
llvm::errs() << Message << "\n";
|
|
|
|
}
|
2017-09-20 15:24:15 +08:00
|
|
|
}
|
|
|
|
|
[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
llvm-svn: 336785
2018-07-11 18:35:11 +08:00
|
|
|
const char *detail::debugType(const char *Filename) {
|
|
|
|
if (const char *Slash = strrchr(Filename, '/'))
|
|
|
|
return Slash + 1;
|
|
|
|
if (const char *Backslash = strrchr(Filename, '\\'))
|
|
|
|
return Backslash + 1;
|
|
|
|
return Filename;
|
|
|
|
}
|
|
|
|
|
2017-12-13 20:51:22 +08:00
|
|
|
} // namespace clangd
|
|
|
|
} // namespace clang
|