forked from MaskRay/ccls
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
174 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "log.hh" | ||
|
||
#include <llvm/ADT/SmallString.h> | ||
#include <llvm/Support/Threading.h> | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <time.h> | ||
#include <iomanip> | ||
#include <mutex> | ||
|
||
namespace ccls::log { | ||
static std::mutex mtx; | ||
FILE* file; | ||
Verbosity verbosity; | ||
|
||
Message::Message(Verbosity verbosity, const char* file, int line) | ||
: verbosity_(verbosity) { | ||
using namespace llvm; | ||
time_t tim = time(NULL); | ||
struct tm t; | ||
{ | ||
std::lock_guard<std::mutex> lock(mtx); | ||
t = *localtime(&tim); | ||
} | ||
char buf[16]; | ||
snprintf(buf, sizeof buf, "%02d:%02d:%02d ", t.tm_hour, t.tm_min, t.tm_sec); | ||
stream_ << buf; | ||
{ | ||
SmallString<32> Name; | ||
get_thread_name(Name); | ||
stream_ << std::left << std::setw(13) << Name.c_str(); | ||
} | ||
{ | ||
const char* p = strrchr(file, '/'); | ||
if (p) | ||
file = p + 1; | ||
stream_ << std::right << std::setw(15) << file << ':' << std::left | ||
<< std::setw(3) << line; | ||
} | ||
stream_ << ' '; | ||
// clang-format off | ||
switch (verbosity_) { | ||
case Verbosity_FATAL: stream_ << 'F'; break; | ||
case Verbosity_ERROR: stream_ << 'E'; break; | ||
case Verbosity_WARNING: stream_ << 'W'; break; | ||
case Verbosity_INFO: stream_ << 'I'; break; | ||
default: stream_ << "V(" << int(verbosity_) << ')'; | ||
} | ||
// clang-format on | ||
stream_ << ' '; | ||
} | ||
|
||
Message::~Message() { | ||
if (!file) return; | ||
std::lock_guard<std::mutex> lock(mtx); | ||
stream_ << '\n'; | ||
fputs(stream_.str().c_str(), file); | ||
if (verbosity_ == Verbosity_FATAL) | ||
abort(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#pragma once | ||
|
||
#include <stdio.h> | ||
#include <sstream> | ||
|
||
namespace ccls::log { | ||
extern FILE* file; | ||
|
||
struct Voidify { | ||
void operator&(const std::ostream&) {} | ||
}; | ||
|
||
enum Verbosity { | ||
Verbosity_FATAL = -3, | ||
Verbosity_ERROR = -2, | ||
Verbosity_WARNING = -1, | ||
Verbosity_INFO = 0, | ||
}; | ||
extern Verbosity verbosity; | ||
|
||
struct Message { | ||
std::stringstream stream_; | ||
int verbosity_; | ||
|
||
Message(Verbosity verbosity, const char* file, int line); | ||
~Message(); | ||
}; | ||
} | ||
|
||
#define LOG_IF(v, cond) \ | ||
!(cond) ? void(0) \ | ||
: ccls::log::Voidify() & \ | ||
ccls::log::Message(v, __FILE__, __LINE__).stream_ | ||
#define LOG_S(v) \ | ||
LOG_IF(ccls::log::Verbosity_##v, \ | ||
ccls::log::Verbosity_##v <= ccls::log::verbosity) | ||
#define LOG_IF_S(v, cond) \ | ||
LOG_IF(ccls::log::Verbosity_##v, \ | ||
(cond) && ccls::log::Verbosity_##v <= ccls::log::verbosity) | ||
#define CHECK_S(cond) LOG_IF(FATAL, !(cond)) << "check failed: " #cond " " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.