13 #include <wpi/SmallString.h>
14 #include <wpi/raw_ostream.h>
16 inline std::string NowTime();
37 static TLogLevel& ReportingLevel();
38 static std::string ToString(TLogLevel level);
39 static TLogLevel FromString(
const std::string& level);
47 Log& operator=(
const Log&);
53 oss <<
"- " << NowTime();
54 oss <<
" " << ToString(level) <<
": ";
55 if (level > logDEBUG) {
56 oss << std::string(level - logDEBUG,
'\t');
66 inline TLogLevel& Log::ReportingLevel() {
67 static TLogLevel reportingLevel = logDEBUG4;
68 return reportingLevel;
71 inline std::string Log::ToString(TLogLevel level) {
72 static const char*
const buffer[] = {
"NONE",
"ERROR",
"WARNING",
73 "INFO",
"DEBUG",
"DEBUG1",
74 "DEBUG2",
"DEBUG3",
"DEBUG4"};
78 inline TLogLevel Log::FromString(
const std::string& level) {
79 if (level ==
"DEBUG4")
return logDEBUG4;
80 if (level ==
"DEBUG3")
return logDEBUG3;
81 if (level ==
"DEBUG2")
return logDEBUG2;
82 if (level ==
"DEBUG1")
return logDEBUG1;
83 if (level ==
"DEBUG")
return logDEBUG;
84 if (level ==
"INFO")
return logINFO;
85 if (level ==
"WARNING")
return logWARNING;
86 if (level ==
"ERROR")
return logERROR;
87 if (level ==
"NONE")
return logNONE;
88 Log().Get(logWARNING) <<
"Unknown logging level '" << level
89 <<
"'. Using INFO level as default.";
95 #define FILE_LOG(level) \
96 if (level > FILELog::ReportingLevel()) \
101 inline std::string NowTime() {
105 using std::chrono::duration_cast;
107 auto now = std::chrono::system_clock::now().time_since_epoch();
110 auto count = duration_cast<std::chrono::hours>(now).
count() % 24;
111 if (count < 10) oss <<
"0";
115 count = duration_cast<std::chrono::minutes>(now).count() % 60;
116 if (count < 10) oss <<
"0";
120 count = duration_cast<std::chrono::seconds>(now).count() % 60;
121 if (count < 10) oss <<
"0";
125 oss << duration_cast<std::chrono::milliseconds>(now).count() % 1000;
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:509
auto count(R &&Range, const E &Element) -> typename std::iterator_traits< decltype(adl_begin(Range))>::difference_type
Wrapper function around std::count to count the number of times an element Element occurs in the give...
Definition: STLExtras.h:941
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.